Skip to content

Instantly share code, notes, and snippets.

@hartbit
Last active February 10, 2018 16:43
Show Gist options
  • Save hartbit/c177ce4c2265d8ec38a0a74f8d051845 to your computer and use it in GitHub Desktop.
Save hartbit/c177ce4c2265d8ec38a0a74f8d051845 to your computer and use it in GitHub Desktop.
GRDB Sourcery Templates
// Generated using Sourcery 0.10.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import GRDBCipher
extension BookViewModel: RowConvertible {
init(row: Row) {
title = row["title"]
genre = row["genre"]
authorName = row["authorName"]
}
}
import GRDBCipher
{% for type in types.implementing.AutoRowConvertible %}
extension {{ type.name }}: RowConvertible {
init(row: Row) {
{% for variable in type.storedVariables|!annotated:"skipRowConvertible" %}
{{ variable.name }} = row["{{ variable.name }}"]
{% endfor %}
}
}
{% endfor %}
import GRDBCipher
// swiftlint:disable identifier_name
class Book: Record {
let id: Int64
let authorId: Int64
let title: String
let genre: String
var pageCount: Int
// sourcery:skipRecord
var cachedData: Data?
// sourcery:inline:auto:Book.Record
override class var databaseTableName: String {
return "books"
}
required init(row: Row) {
id = row["id"]
authorId = row["authorId"]
title = row["title"]
genre = row["genre"]
pageCount = row["pageCount"]
super.init(row: row)
}
override func encode(to container: inout PersistenceContainer) {
super.encode(to: &container)
container["id"] = id
container["authorId"] = authorId
container["title"] = title
container["genre"] = genre
container["pageCount"] = pageCount
}
// sourcery:end
}
// Generated using Sourcery 0.10.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import GRDBCipher
// swiftlint:disable superfluous_disable_command
// swiftlint:disable identifier_name
extension Book {
static let id = Column("id")
static let authorId = Column("authorId")
static let title = Column("title")
static let genre = Column("genre")
static let pageCount = Column("pageCount")
}
import GRDBCipher
// swiftlint:disable superfluous_disable_command
// swiftlint:disable identifier_name
{% for type in types.based.Record %}
// sourcery:inline:auto:{{ type.name }}.Record
override class var databaseTableName: String {
return "{{ type.name|lowerFirstLetter }}s"
}
required init(row: Row) {
{% for variable in type.storedVariables|!annotated:"skipRecord" %}
{{ variable.name }} = row["{{ variable.name }}"]
{% endfor %}
super.init(row: row)
}
override func encode(to container: inout PersistenceContainer) {
super.encode(to: &container)
{% for variable in type.storedVariables|!annotated:"skipRecord" %}
container["{{ variable.name }}"] = {{ variable.name }}
{% endfor %}
}
// sourcery:end
extension {{ type.name }} {
{% for variable in type.storedVariables|!annotated:"skipRecord" %}
static let {{ variable.name }} = Column("{{ variable.name }}")
{% endfor %}
}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment