Skip to content

add primary key with 4 columns #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2019
Merged
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
4 changes: 4 additions & 0 deletions Sources/SQLite/Typed/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ public final class TableBuilder {
primaryKey([compositeA, b, c])
}

public func primaryKey<T : Value, U : Value, V : Value, W : Value>(_ compositeA: Expression<T>, _ b: Expression<U>, _ c: Expression<V>, _ d: Expression<W>) {
primaryKey([compositeA, b, c, d])
}

fileprivate func primaryKey(_ composite: [Expressible]) {
definitions.append("PRIMARY KEY".prefix(composite))
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/SQLiteTests/SchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ class SchemaTests : XCTestCase {
"CREATE TABLE \"table\" (PRIMARY KEY (\"int64\", \"string\", \"double\"))",
table.create { t in t.primaryKey(int64, string, double) }
)
XCTAssertEqual(
"CREATE TABLE \"table\" (PRIMARY KEY (\"int64\", \"string\", \"double\", \"date\"))",
table.create { t in t.primaryKey(int64, string, double, date) }
)
}

func test_unique_compilesUniqueExpression() {
Expand Down