diff --git a/Sources/SwiftKnex/Knex+Query.swift b/Sources/SwiftKnex/Knex+Query.swift index f9f6eac..7f0770b 100644 --- a/Sources/SwiftKnex/Knex+Query.swift +++ b/Sources/SwiftKnex/Knex+Query.swift @@ -8,6 +8,13 @@ extension Knex { + public func fetch(trx: Connection? = nil) throws -> T? { + guard let rows = try execute(.select, trx).asResultSet() else { + return nil + } + return try T(rows: rows) + } + public func fetch(trx: Connection? = nil) throws -> [T] { let rows = try execute(.select, trx).asResultSet() return try rows?.map { try T(row: $0) } ?? [] diff --git a/Sources/SwiftKnex/Protocols/Collection.swift b/Sources/SwiftKnex/Protocols/Collection.swift new file mode 100644 index 0000000..15d897c --- /dev/null +++ b/Sources/SwiftKnex/Protocols/Collection.swift @@ -0,0 +1,16 @@ +// +// Collection.swift +// SwiftJNChatApp +// +// Created by Yuki Takei on 2017/02/20. +// +// + +public protocol CollectionSerializable { + func serialize() throws -> [[String: Any]] +} + +public protocol CollectionType { + init(rows: ResultSet) throws +} + diff --git a/Sources/SwiftKnex/Entity/Entity.swift b/Sources/SwiftKnex/Protocols/Entity.swift similarity index 100% rename from Sources/SwiftKnex/Entity/Entity.swift rename to Sources/SwiftKnex/Protocols/Entity.swift