Skip to content

Commit f90bd95

Browse files
authored
Merge pull request #45 from vapor/tn-beta-4
Beta 4
2 parents 65c487e + 501436c commit f90bd95

File tree

4 files changed

+35
-63
lines changed

4 files changed

+35
-63
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ on:
44
jobs:
55
bionic:
66
container:
7-
image: vapor/swift:5.1-bionic
7+
image: vapor/swift:5.2-bionic
88
runs-on: ubuntu-latest
99
steps:
1010
- run: apt update -y; apt install -y libsqlite3-dev
1111
- uses: actions/checkout@v1
1212
- run: swift test --enable-test-discovery --sanitize=thread
1313
xenial:
1414
container:
15-
image: vapor/swift:5.1-xenial
15+
image: vapor/swift:5.2-xenial
1616
runs-on: ubuntu-latest
1717
steps:
1818
- run: apt update -y; apt install -y libsqlite3-dev

Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ extension _FluentSQLiteDatabase: Database {
3232
}
3333
}
3434
}
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+
}
3552

3653
func execute(schema: DatabaseSchema) -> EventLoopFuture<Void> {
3754
let sql = SQLSchemaConverter(delegate: SQLiteConverterDelegate()).convert(schema)

Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ final class FluentSQLiteDriverTests: XCTestCase {
3232
try self.benchmarker.testEagerLoadParent()
3333
}
3434

35-
func testEagerLoadParentJoin() throws {
36-
try self.benchmarker.testEagerLoadParentJoin()
37-
}
38-
3935
func testEagerLoadParentJSON() throws {
4036
try self.benchmarker.testEagerLoadParentJSON()
4137
}
@@ -100,6 +96,10 @@ final class FluentSQLiteDriverTests: XCTestCase {
10096
try self.benchmarker.testTimestampable()
10197
}
10298

99+
func testTransaction() throws {
100+
try self.benchmarker.testTransaction()
101+
}
102+
103103
func testModelMiddleware() throws {
104104
try self.benchmarker.testModelMiddleware()
105105
}
@@ -164,10 +164,22 @@ final class FluentSQLiteDriverTests: XCTestCase {
164164
try self.benchmarker.testRange()
165165
}
166166

167+
func testRelationMethods() throws {
168+
try self.benchmarker.testRelationMethods()
169+
}
170+
167171
func testNonstandardIDKey() throws {
168172
try self.benchmarker.testNonstandardIDKey()
169173
}
170174

175+
func testGroup() throws {
176+
try self.benchmarker.testGroup()
177+
}
178+
179+
func testPagination() throws {
180+
try self.benchmarker.testPagination()
181+
}
182+
171183
var benchmarker: FluentBenchmarker {
172184
return .init(database: self.database)
173185
}

circle.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)