Skip to content

Commit 302fc69

Browse files
committed
TableDefinition.primaryKey(["a", "b"]) is no longer sunsetted
People need it to define the primary key on non-consecutive columns: #1326
1 parent 0045592 commit 302fc69

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

GRDB/QueryInterface/Schema/TableDefinition.swift

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,29 @@ extension Database {
160160
/// ```swift
161161
/// // a INTEGER NOT NULL,
162162
/// // b TEXT NOT NULL,
163-
/// // PRIMARY KEY (a, b),
163+
/// // PRIMARY KEY (a, b)
164164
/// t.primaryKey {
165165
/// t.column("a", .integer)
166166
/// t.column("b", .text)
167167
/// }
168168
///
169+
/// // a INTEGER NOT NULL,
170+
/// // b TEXT NOT NULL,
171+
/// // PRIMARY KEY (a, b)
172+
/// t.column("a", .integer).notNull()
173+
/// t.column("b", .text).notNull()
174+
/// t.primaryKey(["a", "b"])
175+
///
169176
/// // a INTEGER,
170177
/// // b TEXT,
171-
/// // UNIQUE (a, b) ON CONFLICT REPLACE,
178+
/// // UNIQUE (a, b) ON CONFLICT REPLACE
172179
/// t.column("a", .integer)
173180
/// t.column("b", .text)
174181
/// t.uniqueKey(["a", "b"], onConflict: .replace)
175182
///
176183
/// // a INTEGER,
177184
/// // b TEXT,
178-
/// // FOREIGN KEY (a, b) REFERENCES parents(c, d),
185+
/// // FOREIGN KEY (a, b) REFERENCES parents(c, d)
179186
/// t.column("a", .integer)
180187
/// t.column("b", .text)
181188
/// t.foreignKey(["a", "b"], references: "parents")
@@ -469,8 +476,8 @@ public struct TableOptions: OptionSet {
469476

470477
/// A `TableDefinition` lets you define the components of a database table.
471478
///
472-
/// You don't create instances of this class. Instead, you use the `Database`
473-
/// ``Database/create(table:options:body:)`` method:
479+
/// See the documentation of the `Database`
480+
/// ``Database/create(table:options:body:)`` method for usage information:
474481
///
475482
/// ```swift
476483
/// try db.create(table: "player") { t in // t is TableDefinition
@@ -493,6 +500,7 @@ public struct TableOptions: OptionSet {
493500
/// - ``autoIncrementedPrimaryKey(_:onConflict:)``
494501
/// - ``primaryKey(_:_:onConflict:)``
495502
/// - ``primaryKey(onConflict:body:)``
503+
/// - ``primaryKey(_:onConflict:)``
496504
///
497505
/// ### Define a Foreign Key
498506
///
@@ -508,13 +516,6 @@ public struct TableOptions: OptionSet {
508516
/// - ``check(sql:)``
509517
/// - ``constraint(literal:)``
510518
/// - ``constraint(sql:)``
511-
///
512-
/// ### Sunsetted Methods
513-
///
514-
/// Those are legacy interfaces that are preserved for backwards compatibility.
515-
/// Their use is not recommended.
516-
///
517-
/// - ``primaryKey(_:onConflict:)``
518519
public final class TableDefinition {
519520
struct KeyConstraint {
520521
var columns: [String]
@@ -567,7 +568,7 @@ public final class TableDefinition {
567568
self.options = options
568569
}
569570

570-
/// Defines the auto-incremented primary key.
571+
/// Appends an auto-incremented primary key column.
571572
///
572573
/// For example:
573574
///
@@ -601,7 +602,7 @@ public final class TableDefinition {
601602
column(name, .integer).primaryKey(onConflict: conflictResolution, autoincrement: true)
602603
}
603604

604-
/// Defines the primary key on a single column.
605+
/// Appends a primary key column.
605606
///
606607
/// For example:
607608
///
@@ -636,7 +637,7 @@ public final class TableDefinition {
636637
}
637638
}
638639

639-
/// Defines the primary key on multiple columns.
640+
/// Defines the primary key on wrapped columns.
640641
///
641642
/// For example:
642643
///
@@ -656,7 +657,7 @@ public final class TableDefinition {
656657
/// }
657658
/// ```
658659
///
659-
/// A NOT NULL constraint is always added to the primary key columns.
660+
/// A NOT NULL constraint is always added to the wrapped primary key columns.
660661
public func primaryKey(
661662
onConflict conflictResolution: Database.ConflictResolution? = nil,
662663
body: () throws -> Void)
@@ -744,7 +745,7 @@ public final class TableDefinition {
744745
columns.append(.literal(literal))
745746
}
746747

747-
/// Defines the primary key.
748+
/// Adds a primary key constraint.
748749
///
749750
/// For example:
750751
///
@@ -766,10 +767,6 @@ public final class TableDefinition {
766767
/// See <https://www.sqlite.org/quirks.html#primary_keys_can_sometimes_contain_nulls>
767768
/// for more information.
768769
///
769-
/// - warning: This is a legacy interface that is preserved for backwards
770-
/// compatibility. Use of this interface is not recommended: prefer
771-
/// ``TableDefinition/primaryKey(onConflict:body:)`` instead.
772-
///
773770
/// - parameter columns: The primary key columns.
774771
/// - parameter conflictResolution: An optional conflict resolution
775772
/// (see <https://www.sqlite.org/lang_conflict.html>).

0 commit comments

Comments
 (0)