Skip to content

Commit 758026a

Browse files
authored
Merge pull request #42 from noppoMan/add-collection-type
Add CollectionType
2 parents 762bd97 + d337f7d commit 758026a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Sources/SwiftKnex/Knex+Query.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
extension Knex {
1010

11+
public func fetch<T: CollectionType>(trx: Connection? = nil) throws -> T? {
12+
guard let rows = try execute(.select, trx).asResultSet() else {
13+
return nil
14+
}
15+
return try T(rows: rows)
16+
}
17+
1118
public func fetch<T: Entity>(trx: Connection? = nil) throws -> [T] {
1219
let rows = try execute(.select, trx).asResultSet()
1320
return try rows?.map { try T(row: $0) } ?? []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Collection.swift
3+
// SwiftJNChatApp
4+
//
5+
// Created by Yuki Takei on 2017/02/20.
6+
//
7+
//
8+
9+
public protocol CollectionSerializable {
10+
func serialize() throws -> [[String: Any]]
11+
}
12+
13+
public protocol CollectionType {
14+
init(rows: ResultSet) throws
15+
}
16+

0 commit comments

Comments
 (0)