File tree 2 files changed +29
-4
lines changed
Sources/FluentSQLiteDriver
Tests/FluentSQLiteDriverTests
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,23 @@ extension _FluentSQLiteDatabase: Database {
32
32
}
33
33
}
34
34
}
35
+
36
+ func transaction< T> ( _ closure: @escaping ( Database ) -> EventLoopFuture < T > ) -> EventLoopFuture < T > {
37
+ self . database. withConnection { conn in
38
+ conn. query ( " BEGIN TRANSACTION " ) . flatMap { _ in
39
+ let db = _FluentSQLiteDatabase ( database: conn, context: self . context)
40
+ return closure ( db) . flatMap { result in
41
+ conn. query ( " COMMIT TRANSACTION " ) . map { _ in
42
+ result
43
+ }
44
+ } . flatMapError { error in
45
+ conn. query ( " ROLLBACK TRANSACTION " ) . flatMapThrowing { _ in
46
+ throw error
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
35
52
36
53
func execute( schema: DatabaseSchema ) -> EventLoopFuture < Void > {
37
54
let sql = SQLSchemaConverter ( delegate: SQLiteConverterDelegate ( ) ) . convert ( schema)
Original file line number Diff line number Diff line change @@ -32,10 +32,6 @@ final class FluentSQLiteDriverTests: XCTestCase {
32
32
try self . benchmarker. testEagerLoadParent ( )
33
33
}
34
34
35
- func testEagerLoadParentJoin( ) throws {
36
- try self . benchmarker. testEagerLoadParentJoin ( )
37
- }
38
-
39
35
func testEagerLoadParentJSON( ) throws {
40
36
try self . benchmarker. testEagerLoadParentJSON ( )
41
37
}
@@ -100,6 +96,10 @@ final class FluentSQLiteDriverTests: XCTestCase {
100
96
try self . benchmarker. testTimestampable ( )
101
97
}
102
98
99
+ func testTransaction( ) throws {
100
+ try self . benchmarker. testTransaction ( )
101
+ }
102
+
103
103
func testModelMiddleware( ) throws {
104
104
try self . benchmarker. testModelMiddleware ( )
105
105
}
@@ -164,10 +164,18 @@ final class FluentSQLiteDriverTests: XCTestCase {
164
164
try self . benchmarker. testRange ( )
165
165
}
166
166
167
+ func testRelationMethods( ) throws {
168
+ try self . benchmarker. testRelationMethods ( )
169
+ }
170
+
167
171
func testNonstandardIDKey( ) throws {
168
172
try self . benchmarker. testNonstandardIDKey ( )
169
173
}
170
174
175
+ func testGroup( ) throws {
176
+ try self . benchmarker. testGroup ( )
177
+ }
178
+
171
179
var benchmarker : FluentBenchmarker {
172
180
return . init( database: self . database)
173
181
}
You can’t perform that action at this time.
0 commit comments