import GRDB /// The Line struct. struct Line: Identifiable, Equatable { var id: Int64? var chap: Int var line_id: Int // this is a line_id per book var verse: Int var body: String var book: String } extension Line { private static let books = [ "John", "Matthew", "Imitation of Christ"] } // MARK: - Persistence /// Make Line a Codable Record. /// /// See extension Line: Codable, FetchableRecord, MutablePersistableRecord { // Define database columns from CodingKeys fileprivate enum Columns { static let id = Column(CodingKeys.id) static let chap = Column(CodingKeys.chap) } /// Updates a player id after it has been inserted in the database. mutating func didInsert(_ inserted: InsertionSuccess) { id = inserted.rowID } } // MARK: - Line Database Requests /// Define some player requests used by the application. /// /// See /// See extension DerivableRequest { /// A request of players ordered by name. /// /// For example: /// /// let players: [Line] = try dbWriter.read { db in /// try Line.all().orderedByName().fetchAll(db) /// } //func orderedByName() -> Self { // // Sort by name in a localized case insensitive fashion // // See https://github.com/groue/GRDB.swift/blob/master/README.md#string-comparison // order(Line.Columns.name.collating(.localizedCaseInsensitiveCompare)) //} ///// A request of players ordered by score. ///// ///// For example: ///// ///// let players: [Line] = try dbWriter.read { db in ///// try Line.all().orderedByScore().fetchAll(db) ///// } ///// let bestLine: Line? = try dbWriter.read { db in ///// try Line.all().orderedByScore().fetchOne(db) ///// } //func orderedByScore() -> Self { // // Sort by descending score, and then by name, in a // // localized case insensitive fashion // // See https://github.com/groue/GRDB.swift/blob/master/README.md#string-comparison // order( // Line.Columns.score.desc, // Line.Columns.name.collating(.localizedCaseInsensitiveCompare)) //} }