Skip to content

Commit 9a9a05a

Browse files
kkoltzaujberkel
authored andcommitted
Add "WITHOUT ROWID" table option.
See: https://www.sqlite.org/withoutrowid.html
1 parent a51a6ba commit 9a9a05a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Sources/SQLite/Typed/Schema.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ extension Table {
3636

3737
// MARK: - CREATE TABLE
3838

39-
public func create(temporary: Bool = false, ifNotExists: Bool = false, block: (TableBuilder) -> Void) -> String {
39+
public func create(temporary: Bool = false, ifNotExists: Bool = false, withoutRowid: Bool = false, block: (TableBuilder) -> Void) -> String {
4040
let builder = TableBuilder()
4141

4242
block(builder)
4343

4444
let clauses: [Expressible?] = [
4545
create(Table.identifier, tableName(), temporary ? .Temporary : nil, ifNotExists),
46-
"".wrap(builder.definitions) as Expression<Void>
46+
"".wrap(builder.definitions) as Expression<Void>,
47+
withoutRowid ? Expression<Void>(literal: "WITHOUT ROWID") : nil
4748
]
4849

4950
return " ".join(clauses.flatMap { $0 }).asSQL()

Tests/SQLiteTests/SchemaTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ class SchemaTests : XCTestCase {
5353
"CREATE TEMPORARY TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL)",
5454
table.create(temporary: true, ifNotExists: true) { $0.column(int64) }
5555
)
56+
57+
XCTAssertEqual(
58+
"CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL) WITHOUT ROWID",
59+
table.create(withoutRowid: true) { $0.column(int64) }
60+
)
61+
XCTAssertEqual(
62+
"CREATE TEMPORARY TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL) WITHOUT ROWID",
63+
table.create(temporary: true, ifNotExists: true, withoutRowid: true) { $0.column(int64) }
64+
)
5665
}
5766

5867
func test_create_withQuery_compilesCreateTableExpression() {

0 commit comments

Comments
 (0)