Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions SQLite/Typed/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>
"".wrap(builder.definitions) as Expression<Void>,
withoutRowid ? Expression<Void>(literal: "WITHOUT ROWID") : nil
]

return " ".join(clauses.flatMap { $0 }).asSQL()
Expand Down
9 changes: 9 additions & 0 deletions SQLiteTests/SchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down