Improve inline documentation

This commit is contained in:
Gwendal Roué committed 2022-11-26 16:26:46 +01:00
1 parent 6295f4609e
commit 4e4699ebed
6 files changed
+88 -24

No files matched your search

@@ -498,7 +498,7 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter key: A unique key.
/// - parameter key: A key dictionary.
public func filter(key: [String: (any DatabaseValueConvertible)?]?) -> Self {
guard let key else {
return none()
@@ -526,7 +526,7 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter keys: A collection of unique keys
/// - parameter keys: An array of key dictionaries.
public func filter(keys: [[String: (any DatabaseValueConvertible)?]]) -> Self {
if keys.isEmpty {
return none()
+4 -4
View File
@@ -538,7 +538,7 @@ extension Table {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter key: A unique key.
/// - parameter key: A key dictionary.
public func filter(key: [String: (any DatabaseValueConvertible)?]?) -> QueryInterfaceRequest<RowDecoder> {
all().filter(key: key)
}
@@ -566,7 +566,7 @@ extension Table {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter keys: A collection of unique keys
/// - parameter keys: An array of key dictionaries.
public func filter(keys: [[String: (any DatabaseValueConvertible)?]]) -> QueryInterfaceRequest<RowDecoder> {
all().filter(keys: keys)
}
@@ -1611,7 +1611,7 @@ extension Table {
///
/// - parameters:
/// - db: A database connection.
/// - key: A unique key.
/// - key: A key dictionary.
/// - returns: Whether a row exists for this key.
public func exists(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
try !filter(key: key).isEmpty(db)
@@ -1842,7 +1842,7 @@ extension Table {
/// key columns.
/// - parameters:
/// - db: A database connection.
/// - key: A dictionary of values.
/// - key: A key dictionary.
/// - returns: Whether a row was deleted.
@discardableResult
public func deleteOne(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
@@ -467,14 +467,32 @@ public final class TableDefinition {
///
/// ```swift
/// // CREATE TABLE citizenship (
/// // citizenID INTEGER NOT NULL,
/// // citizenId INTEGER NOT NULL,
/// // countryCode TEXT NOT NULL,
/// // PRIMARY KEY (citizenID, countryCode)
/// // PRIMARY KEY (citizenId, countryCode)
/// // )
/// try db.create(table: "citizenship") { t in
/// t.column("citizenID", .integer).notNull()
/// t.column("citizenId", .integer).notNull()
/// t.column("countryCode", .text).notNull()
/// t.primaryKey(["citizenID", "countryCode"])
/// t.primaryKey(["citizenId", "countryCode"])
/// }
/// ```
///
/// - important: Make sure you add not null constraints on your primary key
/// columns, as in the above example, or SQLite will allow null values.
/// See <https://www.sqlite.org/quirks.html#primary_keys_can_sometimes_contain_nulls>
/// for more information.
///
/// When defining a primary key on a single column, you can use the
/// ``ColumnDefinition/primaryKey(onConflict:autoincrement:)``
/// shortcut:
///
/// ```swift
/// // CREATE TABLE player(
/// // id TEXT NOT NULL PRIMARY KEY
/// // )
/// try db.create(table: "player") { t in
/// t.column("id", .text).notNull().primaryKey()
/// }
/// ```
///
@@ -510,6 +528,18 @@ public final class TableDefinition {
/// }
/// ```
///
/// When defining a unique constraint on a single column, you can use the
/// ``ColumnDefinition/unique(onConflict:)`` shortcut:
///
/// ```swift
/// // CREATE TABLE player(
/// // email TEXT UNIQUE
/// // )
/// try db.create(table: "player") { t in
/// t.column("email", .text).unique()
/// }
/// ```
///
/// Related SQLite documentation: <https://www.sqlite.org/lang_createtable.html#uniqueconst>
///
/// - parameter columns: The unique key columns.
@@ -526,17 +556,27 @@ public final class TableDefinition {
/// ```swift
/// // CREATE TABLE passport (
/// // issueDate DATE NOT NULL,
/// // citizenID INTEGER NOT NULL,
/// // citizenId INTEGER NOT NULL,
/// // countryCode INTEGER NOT NULL,
/// // FOREIGN KEY (citizenID, countryCode)
/// // REFERENCES citizenship(citizenID, countryCode)
/// // FOREIGN KEY (citizenId, countryCode)
/// // REFERENCES citizenship(citizenId, countryCode)
/// // ON DELETE CASCADE
/// // )
/// try db.create(table: "passport") { t in
/// t.column("issueDate", .date).notNull()
/// t.column("citizenID", .integer).notNull()
/// t.column("citizenId", .integer).notNull()
/// t.column("countryCode", .text).notNull()
/// t.foreignKey(["citizenID", "countryCode"], references: "citizenship", onDelete: .cascade)
/// t.foreignKey(["citizenId", "countryCode"], references: "citizenship", onDelete: .cascade)
/// }
/// ```
///
/// When defining a foreign key on a single column, you can use the
/// ``ColumnDefinition/references(_:column:onDelete:onUpdate:deferred:)``
/// shortcut:
///
/// ```swift
/// try db.create(table: "player") { t in
/// t.column("teamId", .integer).references("team", onDelete: .cascade)
/// }
/// ```
///
@@ -588,6 +628,18 @@ public final class TableDefinition {
/// }
/// ```
///
/// When defining a check constraint on a single column, you can use the
/// ``ColumnDefinition/check(_:)`` shortcut:
///
/// ```swift
/// // CREATE TABLE player(
/// // name TEXT CHECK (LENGTH(name) > 0)
/// // )
/// try db.create(table: "player") { t in
/// t.column("name", .text).check { length($0) > 0 }
/// }
/// ```
///
/// Related SQLite documentation: <https://www.sqlite.org/lang_createtable.html#ckconst>
///
/// - parameter condition: The checked condition.
@@ -612,6 +664,18 @@ public final class TableDefinition {
/// }
/// ```
///
/// When defining a check constraint on a single column, you can use the
/// ``ColumnDefinition/check(sql:)`` shortcut:
///
/// ```swift
/// // CREATE TABLE player(
/// // name TEXT CHECK (LENGTH(name) > 0)
/// // )
/// try db.create(table: "player") { t in
/// t.column("name", .text).check(sql: "LENGTH(name) > 0")
/// }
/// ```
///
/// Related SQLite documentation: <https://www.sqlite.org/lang_createtable.html#ckconst>
///
/// - parameter sql: An SQL snippet
@@ -642,8 +706,8 @@ public final class TableDefinition {
/// ``SQL`` literals allow you to safely embed raw values in your SQL,
/// without any risk of syntax errors or SQL injection:
///
/// // CREATE TABLE player (
/// ```swift
/// // CREATE TABLE player (
/// // score INTEGER,
/// // CHECK (score >= 0)
/// // )
@@ -1126,7 +1190,7 @@ public final class ColumnDefinition {
/// }
/// ```
///
/// - warning: Make sure you add a not null constraint on your primary key
/// - important: Make sure you add a not null constraint on your primary key
/// column, as in the above example, or SQLite will allow null values.
/// See <https://www.sqlite.org/quirks.html#primary_keys_can_sometimes_contain_nulls>
/// for more information.
@@ -374,7 +374,7 @@ extension TableRecord {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter key: A unique key.
/// - parameter key: A key dictionary.
public static func filter(key: [String: (any DatabaseValueConvertible)?]?) -> QueryInterfaceRequest<Self> {
all().filter(key: key)
}
@@ -402,7 +402,7 @@ extension TableRecord {
/// When executed, this request raises a fatal error if no unique index
/// exists on a subset of the key columns.
///
/// - parameter keys: A collection of unique keys
/// - parameter keys: An array of key dictionaries.
public static func filter(keys: [[String: (any DatabaseValueConvertible)?]]) -> QueryInterfaceRequest<Self> {
all().filter(keys: keys)
}
@@ -266,7 +266,7 @@ extension FetchableRecord where Self: TableRecord & Identifiable, ID: DatabaseVa
/// ```swift
/// try dbQueue.read { db in
/// let player = try Player.fetchOne(db, id: 123)
/// let country = try Country.fetchOne(db, key: "FR")
/// let country = try Country.fetchOne(db, id: "FR")
/// }
/// ```
///
@@ -421,7 +421,7 @@ extension FetchableRecord where Self: TableRecord {
///
/// - parameters:
/// - db: A database connection.
/// - key: A dictionary of values.
/// - key: A key dictionary.
/// - returns: An optional record.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public static func fetchOne(_ db: Database, key: [String: (any DatabaseValueConvertible)?]?) throws -> Self? {
+3 -3
View File
@@ -362,7 +362,7 @@ extension TableRecord {
///
/// - parameters:
/// - db: A database connection.
/// - key: A unique key.
/// - key: A key dictionary.
/// - returns: Whether a record exists for this key.
public static func exists(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
try !filter(key: key).isEmpty(db)
@@ -552,7 +552,7 @@ extension TableRecord {
return try filter(keys: keys).deleteAll(db)
}
/// Deletes the record identified by its primary or unique keys, and returns
/// Deletes the record identified by its primary or unique key, and returns
/// whether a record was deleted.
///
/// For example:
@@ -580,7 +580,7 @@ extension TableRecord {
/// key columns.
/// - parameters:
/// - db: A database connection.
/// - key: A dictionary of values.
/// - key: A key dictionary.
/// - returns: Whether a record was deleted.
@discardableResult
public static func deleteOne(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {