@@ -6,7 +6,10 @@ struct _FluentSQLiteDatabase {
66}
77
88extension _FluentSQLiteDatabase : Database {
9- func execute( query: DatabaseQuery , onRow: @escaping ( DatabaseRow ) -> ( ) ) -> EventLoopFuture < Void > {
9+ func execute(
10+ query: DatabaseQuery ,
11+ onOutput: @escaping ( DatabaseOutput ) -> ( )
12+ ) -> EventLoopFuture < Void > {
1013 let sql = SQLQueryConverter ( delegate: SQLiteConverterDelegate ( ) ) . convert ( query)
1114 let ( string, binds) = self . serialize ( sql)
1215 let data : [ SQLiteData ]
@@ -19,12 +22,18 @@ extension _FluentSQLiteDatabase: Database {
1922 }
2023 return self . database. withConnection { connection in
2124 connection. logging ( to: self . logger)
22- . query ( string, data, onRow)
25+ . query ( string, data) { row in
26+ onOutput ( row)
27+ }
2328 . flatMap {
2429 switch query. action {
2530 case . create:
2631 return connection. lastAutoincrementID ( ) . map {
27- onRow ( LastInsertRow ( idKey: query. idKey, lastAutoincrementID: $0) )
32+ let row = LastInsertRow (
33+ lastAutoincrementID: $0,
34+ customIDKey: query. customIDKey
35+ )
36+ onOutput ( row)
2837 }
2938 default :
3039 return self . eventLoop. makeSucceededFuture ( ( ) )
@@ -51,6 +60,14 @@ extension _FluentSQLiteDatabase: Database {
5160 }
5261
5362 func execute( schema: DatabaseSchema ) -> EventLoopFuture < Void > {
63+ switch schema. action {
64+ case . update:
65+ if schema. createFields. isEmpty {
66+ return self . eventLoop. makeSucceededFuture ( ( ) )
67+ }
68+ default :
69+ break
70+ }
5471 let sql = SQLSchemaConverter ( delegate: SQLiteConverterDelegate ( ) ) . convert ( schema)
5572 let ( string, binds) = self . serialize ( sql)
5673 let data : [ SQLiteData ]
@@ -65,6 +82,10 @@ extension _FluentSQLiteDatabase: Database {
6582 fatalError ( " Unexpected output: \( $0) " )
6683 }
6784 }
85+
86+ func execute( enum: DatabaseEnum ) -> EventLoopFuture < Void > {
87+ return self . eventLoop. makeSucceededFuture ( ( ) )
88+ }
6889
6990 func withConnection< T> ( _ closure: @escaping ( Database ) -> EventLoopFuture < T > ) -> EventLoopFuture < T > {
7091 self . database. withConnection {
@@ -101,20 +122,24 @@ extension _FluentSQLiteDatabase: SQLiteDatabase {
101122 }
102123}
103124
104- private struct LastInsertRow : DatabaseRow {
125+ private struct LastInsertRow : DatabaseOutput {
105126 var description : String {
106127 [ " id " : self . lastAutoincrementID] . description
107128 }
108129
109- let idKey : String
110130 let lastAutoincrementID : Int
131+ let customIDKey : FieldKey ?
132+
133+ func schema( _ schema: String ) -> DatabaseOutput {
134+ return self
135+ }
111136
112- func contains( field: String ) -> Bool {
113- field == self . idKey
137+ func contains( _ field: FieldKey ) -> Bool {
138+ field == . id || field == self . customIDKey
114139 }
115140
116- func decode< T> ( field: String , as type: T . Type , for database : Database ) throws -> T where T : Decodable {
117- guard field == self . idKey else {
141+ func decode< T> ( _ field: FieldKey , as type: T . Type ) throws -> T where T : Decodable {
142+ guard field == . id || field == self . customIDKey else {
118143 fatalError ( " Cannot decode field from last insert row: \( field) . " )
119144 }
120145 if let autoincrementInitializable = T . self as? AutoincrementIDInitializable . Type {
0 commit comments