From ab53696ce1aca28a292ecb1b20967a1f687cf7a1 Mon Sep 17 00:00:00 2001 From: Huan Lin Date: Mon, 15 Oct 2018 21:52:10 -0700 Subject: [PATCH] add primary key with 4 columns. --- Sources/SQLite/Typed/Schema.swift | 4 ++++ Tests/SQLiteTests/SchemaTests.swift | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Sources/SQLite/Typed/Schema.swift b/Sources/SQLite/Typed/Schema.swift index 62c90702..febfe68c 100644 --- a/Sources/SQLite/Typed/Schema.swift +++ b/Sources/SQLite/Typed/Schema.swift @@ -341,6 +341,10 @@ public final class TableBuilder { primaryKey([compositeA, b, c]) } + public func primaryKey(_ compositeA: Expression, _ b: Expression, _ c: Expression, _ d: Expression) { + primaryKey([compositeA, b, c, d]) + } + fileprivate func primaryKey(_ composite: [Expressible]) { definitions.append("PRIMARY KEY".prefix(composite)) } diff --git a/Tests/SQLiteTests/SchemaTests.swift b/Tests/SQLiteTests/SchemaTests.swift index b9a08881..30646b98 100644 --- a/Tests/SQLiteTests/SchemaTests.swift +++ b/Tests/SQLiteTests/SchemaTests.swift @@ -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() {