diff --git a/SQLite/Typed/Schema.swift b/SQLite/Typed/Schema.swift index 1388170e..65509292 100644 --- a/SQLite/Typed/Schema.swift +++ b/SQLite/Typed/Schema.swift @@ -36,14 +36,15 @@ extension Table { // MARK: - CREATE TABLE - public func create(temporary: Bool = false, ifNotExists: Bool = false, block: (TableBuilder) -> Void) -> String { + public func create(temporary: Bool = false, ifNotExists: Bool = false, withoutRowid: Bool = false, block: (TableBuilder) -> Void) -> String { let builder = TableBuilder() block(builder) let clauses: [Expressible?] = [ create(Table.identifier, tableName(), temporary ? .Temporary : nil, ifNotExists), - "".wrap(builder.definitions) as Expression + "".wrap(builder.definitions) as Expression, + withoutRowid ? Expression(literal: "WITHOUT ROWID") : nil ] return " ".join(clauses.flatMap { $0 }).asSQL() diff --git a/SQLiteTests/SchemaTests.swift b/SQLiteTests/SchemaTests.swift index 371459c7..e59b569b 100644 --- a/SQLiteTests/SchemaTests.swift +++ b/SQLiteTests/SchemaTests.swift @@ -53,6 +53,15 @@ class SchemaTests : XCTestCase { "CREATE TEMPORARY TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL)", table.create(temporary: true, ifNotExists: true) { $0.column(int64) } ) + + XCTAssertEqual( + "CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL) WITHOUT ROWID", + table.create(withoutRowid: true) { $0.column(int64) } + ) + XCTAssertEqual( + "CREATE TEMPORARY TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL) WITHOUT ROWID", + table.create(temporary: true, ifNotExists: true, withoutRowid: true) { $0.column(int64) } + ) } func test_create_withQuery_compilesCreateTableExpression() {