Update inline documentation with singular table names

This commit is contained in:
Gwendal Roué committed 2018-05-01 20:32:18 +02:00
1 parent 872d6d21ac
commit 1bf7f67008
47 files changed
+312 -312

No files matched your search

+14 -14
View File
@@ -327,11 +327,11 @@ extension Database {
/// This type closely matches the information returned by the
/// `table_info` pragma.
///
/// > CREATE TABLE players (
/// > CREATE TABLE player (
/// id INTEGER PRIMARY KEY,
/// firstName TEXT,
/// lastName TEXT)
/// > PRAGMA table_info("players")
/// > PRAGMA table_info("player")
/// cid name type notnull dflt_value pk
/// ---- ----- ------- -------- ---------- ---
/// 0 id INTEGER 0 NULL 1
@@ -362,14 +362,14 @@ public struct ColumnInfo : FetchableRecord {
/// For example:
///
/// try db.execute("""
/// CREATE TABLE players(
/// CREATE TABLE player(
/// id INTEGER PRIMARY KEY,
/// name TEXT DEFAULT 'Anonymous',
/// score INT DEFAULT 0,
/// creationDate DATE DEFAULT CURRENT_TIMESTAMP
/// )
/// """)
/// let columnInfos = try db.columns(in: "players")
/// let columnInfos = try db.columns(in: "player")
/// columnInfos[0].defaultValueSQL // nil
/// columnInfos[1].defaultValueSQL // "'Anoynymous'"
/// columnInfos[2].defaultValueSQL // "0"
@@ -424,38 +424,38 @@ public struct IndexInfo {
///
/// When the table's primary key is the rowid:
///
/// // CREATE TABLE items (name TEXT)
/// let pk = try db.primaryKey("items")
/// // CREATE TABLE item (name TEXT)
/// let pk = try db.primaryKey("item")
/// pk.columns // ["rowid"]
/// pk.rowIDColumn // nil
/// pk.isRowID // true
///
/// // CREATE TABLE citizens (
/// // CREATE TABLE citizen (
/// // id INTEGER PRIMARY KEY,
/// // name TEXT
/// // )
/// let pk = try db.primaryKey("citizens")!
/// let pk = try db.primaryKey("citizen")!
/// pk.columns // ["id"]
/// pk.rowIDColumn // "id"
/// pk.isRowID // true
///
/// When the table's primary key is not the rowid:
///
/// // CREATE TABLE countries (
/// // CREATE TABLE country (
/// // isoCode TEXT NOT NULL PRIMARY KEY
/// // name TEXT
/// // )
/// let pk = db.primaryKey("countries")!
/// let pk = db.primaryKey("country")!
/// pk.columns // ["isoCode"]
/// pk.rowIDColumn // nil
/// pk.isRowID // false
///
/// // CREATE TABLE citizenships (
/// // citizenID INTEGER NOT NULL REFERENCES citizens(id)
/// // countryIsoCode TEXT NOT NULL REFERENCES countries(isoCode)
/// // CREATE TABLE citizenship (
/// // citizenID INTEGER NOT NULL REFERENCES citizen(id)
/// // countryIsoCode TEXT NOT NULL REFERENCES country(isoCode)
/// // PRIMARY KEY (citizenID, countryIsoCode)
/// // )
/// let pk = db.primaryKey("citizenships")!
/// let pk = db.primaryKey("citizenship")!
/// pk.columns // ["citizenID", "countryIsoCode"]
/// pk.rowIDColumn // nil
/// pk.isRowID // false
+12 -12
View File
@@ -1,12 +1,12 @@
import Foundation
extension Database {
// MARK: - Statements
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -19,7 +19,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?", prepFlags: 0)
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?", prepFlags: 0)
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -34,7 +34,7 @@ extension Database {
/// Returns a prepared statement that can be reused.
///
/// let statement = try db.cachedSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.cachedSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -55,7 +55,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -68,7 +68,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)", prepFlags: 0)
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)", prepFlags: 0)
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -83,7 +83,7 @@ extension Database {
/// Returns a prepared statement that can be reused.
///
/// let statement = try db.cachedUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.cachedUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -105,13 +105,13 @@ extension Database {
/// Executes one or several SQL statements, separated by semi-colons.
///
/// try db.execute(
/// "INSERT INTO players (name) VALUES (:name)",
/// "INSERT INTO player (name) VALUES (:name)",
/// arguments: ["name": "Arthur"])
///
/// try db.execute("""
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// """, arguments; ['Arthur', 'Barbara', 'Craig'])
///
/// This method may throw a DatabaseError.
+1 -1
View File
@@ -879,7 +879,7 @@ extension Database {
/// An SQL column type.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// }
+1 -1
View File
@@ -16,7 +16,7 @@ public final class DatabaseCollation {
/// return (string1 as NSString).localizedStandardCompare(string2)
/// }
/// db.add(collation: collation)
/// try db.execute("CREATE TABLE files (name TEXT COLLATE localized_standard")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE localized_standard")
///
/// - parameters:
/// - name: The function name.
+2 -2
View File
@@ -363,10 +363,10 @@ public protocol DatabaseAggregate {
/// aggregate function.
///
/// -- One value
/// SELECT maxLength(name) FROM players
/// SELECT maxLength(name) FROM player
///
/// -- Two values
/// SELECT maxFullNameLength(firstName, lastName) FROM players
/// SELECT maxFullNameLength(firstName, lastName) FROM player
///
/// This method is never called after the finalize() method has been called.
mutating func step(_ dbValues: [DatabaseValue]) throws
+12 -12
View File
@@ -224,14 +224,14 @@ extension DatabasePool : DatabaseReader {
///
/// try dbPool.read { db in
/// // Those two values are guaranteed to be equal, even if the
/// // `wines` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// // `wine` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// try dbPool.read { db in
/// // Now this value may be different:
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// This method is *not* reentrant.
@@ -266,8 +266,8 @@ extension DatabasePool : DatabaseReader {
/// try dbPool.unsafeRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iteration is safe, though:
@@ -303,8 +303,8 @@ extension DatabasePool : DatabaseReader {
/// try dbPool.unsafeReentrantRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iteration is safe, though:
@@ -346,12 +346,12 @@ extension DatabasePool : DatabaseReader {
/// database updates are *not visible* inside the block.
///
/// try dbPool.write { db in
/// try db.execute("DELETE FROM players")
/// try db.execute("DELETE FROM player")
/// try dbPool.readFromCurrentState { db in
/// // Guaranteed to be zero
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")!
/// }
/// try db.execute("INSERT INTO players ...")
/// try db.execute("INSERT INTO player ...")
/// }
///
/// This method blocks the current thread until the isolation guarantee has
@@ -611,7 +611,7 @@ extension DatabasePool : DatabaseReader {
/// }
/// dbPool.add(collation: collation)
/// try dbPool.write { db in
/// try db.execute("CREATE TABLE files (name TEXT COLLATE LOCALIZED_STANDARD")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
/// }
public func add(collation: DatabaseCollation) {
collations.update(with: collation)
+4 -4
View File
@@ -10,7 +10,7 @@ public final class DatabaseQueue: DatabaseWriter {
#if os(iOS)
private weak var application: UIApplication?
#endif
// MARK: - Configuration
/// The database configuration
@@ -291,7 +291,7 @@ extension DatabaseQueue {
/// Synchronously executes a block in a protected dispatch queue, and
/// returns its result.
///
/// // INSERT INTO players ...
/// // INSERT INTO player ...
/// let players = try dbQueue.inDatabase { db in
/// try Player(...).insert(db)
/// }
@@ -307,7 +307,7 @@ extension DatabaseQueue {
/// Synchronously executes a block in a protected dispatch queue, and
/// returns its result.
///
/// // INSERT INTO players ...
/// // INSERT INTO player ...
/// try dbQueue.unsafeReentrantWrite { db in
/// try Player(...).insert(db)
/// }
@@ -350,7 +350,7 @@ extension DatabaseQueue {
/// }
/// dbQueue.add(collation: collation)
/// try dbQueue.write { db in
/// try db.execute("CREATE TABLE files (name TEXT COLLATE LOCALIZED_STANDARD")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
/// }
public func add(collation: DatabaseCollation) {
writer.sync { $0.add(collation: collation) }
+9 -9
View File
@@ -31,14 +31,14 @@ public protocol DatabaseReader : class {
///
/// try reader.read { db in
/// // Those two values are guaranteed to be equal, even if the
/// // `wines` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// // `wine` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// try reader.read { db in
/// // Now this value may be different:
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds
@@ -61,8 +61,8 @@ public protocol DatabaseReader : class {
/// try reader.unsafeRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iterations are isolated, though:
@@ -92,8 +92,8 @@ public protocol DatabaseReader : class {
/// try reader.unsafeReentrantRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iterations are isolated, though:
@@ -144,7 +144,7 @@ public protocol DatabaseReader : class {
/// return (string1 as NSString).localizedStandardCompare(string2)
/// }
/// reader.add(collation: collation)
/// try reader.execute("SELECT * FROM files ORDER BY name COLLATE localized_standard")
/// try reader.execute("SELECT * FROM file ORDER BY name COLLATE localized_standard")
func add(collation: DatabaseCollation)
/// Remove a collation.
+6 -6
View File
@@ -18,27 +18,27 @@
///
/// - `SelectStatement.fetchedRegion`:
///
/// let statement = db.makeSelectStatement("SELECT name, score FROM players")
/// let statement = db.makeSelectStatement("SELECT name, score FROM player")
/// print(statement.fetchedRegion)
/// // prints "players(name,score)"
/// // prints "player(name,score)"
///
/// - `Request.fetchedRegion(_:)`
///
/// let request = Player.filter(key: 1)
/// try print(request.fetchedRegion(db))
/// // prints "players(*)[1]"
/// // prints "player(*)[1]"
///
/// Database regions returned by requests can be more precise than regions
/// returned by select statements. Especially, regions returned by statements
/// don't know about rowids:
///
/// // A plain statement
/// let statement = db.makeSelectStatement("SELECT * FROM players WHERE id = 1")
/// statement.fetchedRegion // "players(*)"
/// let statement = db.makeSelectStatement("SELECT * FROM player WHERE id = 1")
/// statement.fetchedRegion // "player(*)"
///
/// // A query interface request that executes the same statement:
/// let request = Player.filter(key: 1)
/// try request.fetchedRegion(db) // "players(*)[1]"
/// try request.fetchedRegion(db) // "player(*)[1]"
public struct DatabaseRegion: CustomStringConvertible, Equatable {
private let tableRegions: [String: TableRegion]?
private init(tableRegions: [String: TableRegion]?) {
+1 -1
View File
@@ -110,7 +110,7 @@ extension DatabaseSnapshot {
/// }
/// snapshot.add(collation: collation)
/// let files = try snapshot.read { db in
/// try File.fetchAll(db, "SELECT * FROM files ORDER BY name COLLATE localized_standard")
/// try File.fetchAll(db, "SELECT * FROM file ORDER BY name COLLATE localized_standard")
/// }
public func add(collation: DatabaseCollation) {
serializedDatabase.sync { $0.add(collation: collation) }
+2 -2
View File
@@ -42,7 +42,7 @@ extension DatabaseValueConvertible {
/// For example:
///
/// try dbQueue.read { db in
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, "SELECT url FROM links")
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, "SELECT url FROM link")
/// while let url = urls.next() { // URL
/// print(url)
/// }
@@ -82,7 +82,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
/// For example:
///
/// try dbQueue.read { db in
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, "SELECT url FROM links")
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, "SELECT url FROM link")
/// while let url = urls.next() { // URL?
/// print(url)
/// }
+3 -3
View File
@@ -73,12 +73,12 @@ public protocol DatabaseWriter : DatabaseReader {
/// For example:
///
/// try writer.write { db in
/// try db.execute("DELETE FROM players")
/// try db.execute("DELETE FROM player")
/// try writer.readFromCurrentState { db in
/// // Guaranteed to be zero
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")!
/// }
/// try db.execute("INSERT INTO players ...")
/// try db.execute("INSERT INTO player ...")
/// }
func readFromCurrentState(_ block: @escaping (Database) -> Void) throws
}
+4 -4
View File
@@ -185,8 +185,8 @@ public struct SQLRequest<T> : FetchRequest {
/// Creates a request from an SQL string, optional arguments, and
/// optional row adapter.
///
/// let request = SQLRequest("SELECT * FROM players")
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
/// let request = SQLRequest("SELECT * FROM player")
/// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1])
///
/// - parameters:
/// - sql: An SQL query.
@@ -215,8 +215,8 @@ public struct SQLRequest<T> : FetchRequest {
/// Creates an SQL request from an SQL string, optional arguments, and
/// optional row adapter.
///
/// let request = SQLRequest("SELECT * FROM players")
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
/// let request = SQLRequest("SELECT * FROM player")
/// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1])
///
/// - parameters:
/// - sql: An SQL query.
+2 -2
View File
@@ -583,7 +583,7 @@ extension Row {
/// A cursor of database rows. For example:
///
/// try dbQueue.read { db in
/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM players")
/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM player")
/// }
public final class RowCursor : Cursor {
public let statement: SelectStatement
@@ -690,7 +690,7 @@ extension Row {
/// Returns a cursor over rows fetched from an SQL query.
///
/// let rows = try Row.fetchCursor(db, "SELECT id, name FROM players") // RowCursor
/// let rows = try Row.fetchCursor(db, "SELECT id, name FROM player") // RowCursor
/// while let row = try rows.next() { // Row
/// let id: Int64 = row[0]
/// let name: String = row[1]
+3 -3
View File
@@ -289,7 +289,7 @@ extension AuthorizedStatement {
/// You create SelectStatement with the Database.makeSelectStatement() method:
///
/// try dbQueue.read { db in
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
/// }
@@ -375,7 +375,7 @@ extension SelectStatement: AuthorizedStatement { }
/// For example:
///
/// try dbQueue.read { db in
/// let statement = db.makeSelectStatement("SELECT * FROM players")
/// let statement = db.makeSelectStatement("SELECT * FROM player")
/// let cursor: StatementCursor = statement.cursor()
/// }
public final class StatementCursor: Cursor {
@@ -414,7 +414,7 @@ public final class StatementCursor: Cursor {
/// You create UpdateStatement with the Database.makeUpdateStatement() method:
///
/// try dbQueue.inTransaction { db in
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
/// return .commit
+2 -2
View File
@@ -75,7 +75,7 @@ extension StatementColumnConvertible {
/// For example:
///
/// try dbQueue.read { db in
/// let names: ColumnCursor<String> = try String.fetchCursor(db, "SELECT name FROM players")
/// let names: ColumnCursor<String> = try String.fetchCursor(db, "SELECT name FROM player")
/// while let name = names.next() { // String
/// print(name)
/// }
@@ -121,7 +121,7 @@ public final class ColumnCursor<Value: DatabaseValueConvertible & StatementColum
/// For example:
///
/// try dbQueue.read { db in
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, "SELECT email FROM players")
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, "SELECT email FROM player")
/// while let email = emails.next() { // String?
/// print(email ?? "<NULL>")
/// }
+9 -10
View File
@@ -29,13 +29,12 @@ extension Database {
/// Registers a closure to be executed after the next or current
/// transaction completion.
///
/// dbQueue.inTransaction { db in
/// try dbQueue.write { db in
/// db.afterNextTransactionCommit { _ in
/// print("commit did succeed")
/// print("success")
/// }
/// ...
/// return .commit // prints "commit did succeed"
/// }
/// } // prints "success"
///
/// If the transaction is rollbacked, the closure is not executed.
///
@@ -100,11 +99,11 @@ extension Database {
///
/// Then a statement is executed:
///
/// try db.execute("INSERT INTO documents ...")
/// try db.execute("INSERT INTO document ...")
///
/// The observation process starts when the statement is *compiled*:
/// sqlite3_set_authorizer tells that the statement performs insertion into the
/// `documents` table. Generally speaking, statements may have many effects, by
/// `document` table. Generally speaking, statements may have many effects, by
/// the mean of foreign key actions and SQL triggers. SQLite takes care of
/// exposing all those effects to sqlite3_set_authorizer.
///
@@ -129,7 +128,7 @@ extension Database {
///
/// Then another statement is executed:
///
/// try db.execute("INSERT INTO documents ...")
/// try db.execute("INSERT INTO document ...")
///
/// This time, when the statement is *executed* and SQLite tells that a row has
/// been inserted, the broker buffers the change event instead of immediately
@@ -738,14 +737,14 @@ extension TransactionObserver {
/// For example:
///
/// class PlayerObserver: TransactionObserver {
/// var playersTableWasModified = false
/// var playerTableWasModified = false
///
/// func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
/// return eventKind.tableName == "players"
/// return eventKind.tableName == "player"
/// }
///
/// func databaseDidChange(with event: DatabaseEvent) {
/// playersTableWasModified = true
/// playerTableWasModified = true
///
/// // It is pointless to keep on tracking further changes:
/// stopObservingDatabaseChangesUntilNextTransaction()
+7 -7
View File
@@ -1,15 +1,15 @@
/// FTS3 lets you define "fts3" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts3(content)
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// // CREATE VIRTUAL TABLE document USING fts3(content)
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
public struct FTS3 : VirtualTableModule {
/// Creates a FTS3 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts3(content)
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// // CREATE VIRTUAL TABLE document USING fts3(content)
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
public init() {
@@ -54,7 +54,7 @@ public struct FTS3 : VirtualTableModule {
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in // t is FTS3TableDefinition
/// try db.create(virtualTable: "document", using: FTS3()) { t in // t is FTS3TableDefinition
/// t.column("content")
/// }
public final class FTS3TableDefinition {
@@ -62,7 +62,7 @@ public final class FTS3TableDefinition {
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.tokenizer = .porter
/// }
/// See https://www.sqlite.org/fts3.html#creating_and_destroying_fts_tables
@@ -70,7 +70,7 @@ public final class FTS3TableDefinition {
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
///
+5 -5
View File
@@ -1,6 +1,6 @@
/// An FTS3 tokenizer, suitable for FTS3 and FTS4 table definitions:
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .simple // FTS3TokenizerDescriptor
/// }
///
@@ -16,7 +16,7 @@ public struct FTS3TokenizerDescriptor {
/// The "simple" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .simple
/// }
///
@@ -25,7 +25,7 @@ public struct FTS3TokenizerDescriptor {
/// The "porter" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .porter
/// }
///
@@ -35,7 +35,7 @@ public struct FTS3TokenizerDescriptor {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .unicode61()
/// }
///
@@ -54,7 +54,7 @@ public struct FTS3TokenizerDescriptor {
#else
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .unicode61()
/// }
///
+13 -13
View File
@@ -1,7 +1,7 @@
/// FTS4 lets you define "fts4" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts4(content)
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING fts4(content)
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -11,8 +11,8 @@ public struct FTS4 : VirtualTableModule {
/// Creates a FTS4 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts4(content)
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING fts4(content)
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -137,7 +137,7 @@ public struct FTS4 : VirtualTableModule {
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in // t is FTS4TableDefinition
/// try db.create(virtualTable: "document", using: FTS4()) { t in // t is FTS4TableDefinition
/// t.column("content")
/// }
///
@@ -153,7 +153,7 @@ public final class FTS4TableDefinition {
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.tokenizer = .porter
/// }
///
@@ -201,8 +201,8 @@ public final class FTS4TableDefinition {
/// Support for the FTS5 `prefix` option
///
/// // CREATE VIRTUAL TABLE documents USING FTS4(content, prefix='2 4');
/// db.create(virtualTable: "documents", using:FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING FTS4(content, prefix='2 4');
/// db.create(virtualTable: "document", using:FTS4()) { t in
/// t.prefixes = [2, 4]
/// t.column("content")
/// }
@@ -212,7 +212,7 @@ public final class FTS4TableDefinition {
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -242,7 +242,7 @@ public final class FTS4TableDefinition {
///
/// You get instances of this class when you create an FTS4 table:
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content") // FTS4ColumnDefinition
/// }
///
@@ -261,7 +261,7 @@ public final class FTS4ColumnDefinition {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
@@ -280,7 +280,7 @@ public final class FTS4ColumnDefinition {
#else
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
@@ -300,7 +300,7 @@ public final class FTS4ColumnDefinition {
/// Uses the column as the Int32 language id hidden column.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("lid").asLanguageId()
/// }
+9 -9
View File
@@ -1,8 +1,8 @@
#if SQLITE_ENABLE_FTS5
/// FTS5 lets you define "fts5" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts5(content)
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// // CREATE VIRTUAL TABLE document USING fts5(content)
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -12,8 +12,8 @@
/// Creates a FTS5 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts5(content)
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// // CREATE VIRTUAL TABLE document USING fts5(content)
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -156,7 +156,7 @@
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in // t is FTS5TableDefinition
/// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition
/// t.column("content")
/// }
///
@@ -172,7 +172,7 @@
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.tokenizer = .porter()
/// }
///
@@ -254,7 +254,7 @@
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -284,7 +284,7 @@
///
/// You get instances of this class when you create an FTS5 table:
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content") // FTS5ColumnDefinition
/// }
///
@@ -300,7 +300,7 @@
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
+2 -2
View File
@@ -11,7 +11,7 @@
/// VIRTUAL TABLE statement. In the example below, the arguments will
/// be `["arg1", "arg2"]`.
///
/// CREATE VIRTUAL TABLE documents USING fts5(
/// CREATE VIRTUAL TABLE document USING fts5(
/// tokenize='custom arg1 arg2'
/// )
///
@@ -26,7 +26,7 @@
///
/// class MyTokenizer : FTS5CustomTokenizer { ... }
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// let tokenizer = MyTokenizer.tokenizerDescriptor(arguments: ["unicode61", "remove_diacritics", "0"])
/// t.tokenizer = tokenizer
/// }
+4 -4
View File
@@ -65,7 +65,7 @@
// that pattern.
do {
try DatabaseQueue().inDatabase { db in
try db.create(virtualTable: "documents", using: FTS5()) { t in
try db.create(virtualTable: "document", using: FTS5()) { t in
if allowedColumns.isEmpty {
t.column("__grdb__")
} else {
@@ -74,7 +74,7 @@
}
}
}
try db.makeSelectStatement("SELECT * FROM documents WHERE documents MATCH ?")
try db.makeSelectStatement("SELECT * FROM document WHERE document MATCH ?")
.cursor(arguments: [rawPattern])
.next() // error on next() for invalid patterns
}
@@ -97,8 +97,8 @@
///
/// The pattern syntax is documented at https://www.sqlite.org/fts5.html#full_text_query_syntax
///
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "documents") // OK
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "documents") // malformed MATCH expression: [AND]
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND]
public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern {
return try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map { $0.name })
}
+5 -5
View File
@@ -1,7 +1,7 @@
#if SQLITE_ENABLE_FTS5
/// An FTS5 tokenizer, suitable for FTS5 table definitions:
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor
/// }
///
@@ -33,7 +33,7 @@
/// Creates an FTS5 tokenizer descriptor.
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// let tokenizer = FTS5TokenizerDescriptor(components: ["porter", "unicode61", "remove_diacritics", "0"])
/// t.tokenizer = tokenizer
/// }
@@ -47,7 +47,7 @@
/// The "ascii" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .ascii()
/// }
///
@@ -66,7 +66,7 @@
/// The "porter" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .porter()
/// }
///
@@ -85,7 +85,7 @@
/// An "unicode61" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .unicode61()
/// }
///
+46 -43
View File
@@ -9,34 +9,37 @@
///
/// var migrator = DatabaseMigrator()
///
/// // v1.0 database
/// migrator.registerMigration("createAuthors") { db in
/// try db.execute("""
/// CREATE TABLE authors (
/// id INTEGER PRIMARY KEY,
/// creationDate TEXT,
/// name TEXT NOT NULL
/// )
/// """)
/// // 1st migration
/// migrator.registerMigration("createLibrary") { db in
/// try db.create(table: "author") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("creationDate", .datetime)
/// t.column("name", .text).notNull()
/// }
///
/// try db.create(table: "book") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("authorId", .integer)
/// .notNull()
/// .references("author", onDelete: .cascade)
/// t.column("title", .text).notNull()
/// }
/// }
///
/// migrator.registerMigration("createBooks") { db in
/// try db.execute("""
/// CREATE TABLE books (
/// uuid TEXT PRIMARY KEY,
/// authorID INTEGER NOT NULL
/// REFERENCES authors(id)
/// ON DELETE CASCADE ON UPDATE CASCADE,
/// title TEXT NOT NULL
/// )
/// """)
/// }
///
/// // v2.0 database
/// // 2nd migration
/// migrator.registerMigration("AddBirthYearToAuthors") { db in
/// try db.execute("ALTER TABLE authors ADD COLUMN birthYear INT")
/// try db.alter(table: "author") { t
/// t.add(column: "birthYear", .integer)
/// }
/// }
///
/// // Migrations for future versions will be inserted here:
/// //
/// // // 3rd migration
/// // migrator.registerMigration("...") { db in
/// // ...
/// // }
///
/// try migrator.migrate(dbQueue)
public struct DatabaseMigrator {
@@ -46,14 +49,12 @@ public struct DatabaseMigrator {
/// Registers a migration.
///
/// migrator.registerMigration("createPlayers") { db in
/// try db.execute("""
/// CREATE TABLE players (
/// id INTEGER PRIMARY KEY,
/// creationDate TEXT,
/// name TEXT NOT NULL
/// )
/// """)
/// migrator.registerMigration("createAuthors") { db in
/// try db.create(table: "author") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("creationDate", .datetime)
/// t.column("name", .text).notNull()
/// }
/// }
///
/// - parameters:
@@ -69,12 +70,13 @@ public struct DatabaseMigrator {
///
/// // Add a NOT NULL constraint on players.name:
/// migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { db in
/// try db.execute("""
/// CREATE TABLE new_players (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
/// INSERT INTO new_players SELECT * FROM players;
/// DROP TABLE players;
/// ALTER TABLE new_players RENAME TO players;
/// """)
/// try db.create(table: "new_player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text).notNull()
/// }
/// try db.execute("INSERT INTO new_player SELECT * FROM player")
/// try db.drop(table: "player")
/// try db.rename(table: "new_player", to: "player")
/// }
///
/// While your migration code runs with disabled foreign key checks, those
@@ -96,12 +98,13 @@ public struct DatabaseMigrator {
///
/// // Add a NOT NULL constraint on players.name:
/// migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { db in
/// try db.execute("""
/// CREATE TABLE new_players (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
/// INSERT INTO new_players SELECT * FROM players;
/// DROP TABLE players;
/// ALTER TABLE new_players RENAME TO players;
/// """)
/// try db.create(table: "new_player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text).notNull()
/// }
/// try db.execute("INSERT INTO new_player SELECT * FROM player")
/// try db.drop(table: "player")
/// try db.rename(table: "new_player", to: "player")
/// }
///
/// While your migration code runs with disabled foreign key checks, those
@@ -48,6 +48,7 @@ public protocol Association: SelectionRequest, FilteredRequest, OrderedRequest {
/// }
func forKey(_ key: String) -> Self
// TODO: this one prevents "through" associations like HasOneThrough, HasManyThrough, etc.
/// :nodoc:
var request: AssociationRequest<RightAssociated> { get }
@@ -271,7 +272,7 @@ extension Association where LeftAssociated: MutablePersistableRecord {
/// For example:
///
/// struct Team: {
/// static let players = hasMany(Book.self)
/// static let players = hasMany(Player.self)
/// var players: QueryInterfaceRequest<Player> {
/// return request(for: Team.players)
/// }
@@ -80,7 +80,6 @@ struct ForeignKeyRequest {
}
}
/// The (origin, destination) column pairs that join a left table to a right table.
/// :nodoc:
typealias ForeignKeyMapping = [(origin: String, destination: String)]
@@ -5,7 +5,7 @@ extension QueryInterfaceRequest {
/// Creates a request with a full-text predicate added to the eventual
/// set of already applied predicates.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.all()
/// request = request.matching(pattern)
///
@@ -28,7 +28,7 @@ extension TableRecord {
/// Returns a QueryInterfaceRequest with a matching predicate.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.matching(pattern)
///
/// If the search pattern is nil, the request does not match any
@@ -6,7 +6,7 @@
/// Creates a request with a full-text predicate added to the eventual
/// set of already applied predicates.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.all()
/// request = request.matching(pattern)
///
@@ -33,7 +33,7 @@
/// Returns a QueryInterfaceRequest with a matching predicate.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.matching(pattern)
///
/// If the search pattern is nil, the request does not match any
@@ -216,6 +216,7 @@ extension QueryInterfaceQuery {
}
extension QueryInterfaceQuery {
/// precondition: self is the result of finalizedQuery
func sql(_ db: Database, _ context: inout SQLGenerationContext) throws -> String {
var sql = "SELECT"
@@ -48,7 +48,7 @@ extension MutablePersistableRecord {
/// For example:
///
/// struct Team: {
/// static let players = hasMany(Book.self)
/// static let players = hasMany(Player.self)
/// var players: QueryInterfaceRequest<Player> {
/// return request(for: Team.players)
/// }
+24 -24
View File
@@ -49,13 +49,13 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select([Column("id"), Column("email")])
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select([Column("id")])
/// .select([Column("email")])
@@ -65,11 +65,11 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request which returns distinct rows.
///
/// // SELECT DISTINCT * FROM players
/// // SELECT DISTINCT * FROM player
/// var request = Player.all()
/// request = request.distinct()
///
/// // SELECT DISTINCT name FROM players
/// // SELECT DISTINCT name FROM player
/// var request = Player.select(Column("name"))
/// request = request.distinct()
public func distinct() -> QueryInterfaceRequest<T> {
@@ -79,7 +79,7 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request with the provided *predicate promise* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE 1
/// // SELECT * FROM player WHERE 1
/// var request = Player.all()
/// request = request.filter { db in true }
public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceRequest<T> {
@@ -99,13 +99,13 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order([Column("name")])
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order([Column("email")])
/// .reversed()
@@ -116,13 +116,13 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request that reverses applied orderings.
///
/// // SELECT * FROM players ORDER BY name DESC
/// // SELECT * FROM player ORDER BY name DESC
/// var request = Player.all().order(Column("name"))
/// request = request.reversed()
///
/// If no ordering was applied, the returned request is identical.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// var request = Player.all()
/// request = request.reversed()
public func reversed() -> QueryInterfaceRequest<T> {
@@ -131,7 +131,7 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request which fetches *limit* rows, starting at *offset*.
///
/// // SELECT * FROM players LIMIT 1
/// // SELECT * FROM player LIMIT 1
/// var request = Player.all()
/// request = request.limit(1)
///
@@ -214,7 +214,7 @@ extension TableRecord {
/// Creates a request which fetches all records.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let request = Player.all()
///
/// The selection defaults to all columns. This default can be changed for
@@ -234,7 +234,7 @@ extension TableRecord {
/// Creates a request which selects *selection*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select(Column("id"), Column("email"))
public static func select(_ selection: SQLSelectable...) -> QueryInterfaceRequest<Self> {
return all().select(selection)
@@ -242,7 +242,7 @@ extension TableRecord {
/// Creates a request which selects *selection*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select([Column("id"), Column("email")])
public static func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest<Self> {
return all().select(selection)
@@ -250,7 +250,7 @@ extension TableRecord {
/// Creates a request which selects *sql*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select(sql: "id, email")
public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
return all().select(sql: sql, arguments: arguments)
@@ -258,7 +258,7 @@ extension TableRecord {
/// Creates a request with the provided *predicate*.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// let request = Player.filter(Column("email") == "arthur@example.com")
///
/// The selection defaults to all columns. This default can be changed for
@@ -270,7 +270,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id = 1
/// // SELECT * FROM player WHERE id = 1
/// let request = Player.filter(key: 1)
///
/// The selection defaults to all columns. This default can be changed for
@@ -282,7 +282,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id IN (1, 2, 3)
/// // SELECT * FROM player WHERE id IN (1, 2, 3)
/// let request = Player.filter(keys: [1, 2, 3])
///
/// The selection defaults to all columns. This default can be changed for
@@ -294,7 +294,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE personId = 1 AND countryCode = 'FR'
/// // SELECT * FROM passport WHERE personId = 1 AND countryCode = 'FR'
/// let request = Passport.filter(key: ["personId": 1, "countryCode": "FR"])
///
/// When executed, this request raises a fatal error if there is no unique
@@ -309,7 +309,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE (personId = 1 AND countryCode = 'FR') OR ...
/// // SELECT * FROM passport WHERE (personId = 1 AND countryCode = 'FR') OR ...
/// let request = Passport.filter(keys: [["personId": 1, "countryCode": "FR"], ...])
///
/// When executed, this request raises a fatal error if there is no unique
@@ -324,7 +324,7 @@ extension TableRecord {
/// Creates a request with the provided *predicate*.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// let request = Player.filter(sql: "email = ?", arguments: ["arthur@example.com"])
///
/// The selection defaults to all columns. This default can be changed for
@@ -337,7 +337,7 @@ extension TableRecord {
/// Creates a request sorted according to the
/// provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order(Column("name"))
///
/// The selection defaults to all columns. This default can be changed for
@@ -350,7 +350,7 @@ extension TableRecord {
/// Creates a request sorted according to the
/// provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order([Column("name")])
///
/// The selection defaults to all columns. This default can be changed for
@@ -362,7 +362,7 @@ extension TableRecord {
/// Creates a request sorted according to *sql*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order(sql: "name")
///
/// The selection defaults to all columns. This default can be changed for
@@ -375,7 +375,7 @@ extension TableRecord {
/// Creates a request which fetches *limit* rows, starting at
/// *offset*.
///
/// // SELECT * FROM players LIMIT 1
/// // SELECT * FROM player LIMIT 1
/// let request = Player.limit(1)
///
/// The selection defaults to all columns. This default can be changed for
+18 -18
View File
@@ -4,13 +4,13 @@
public protocol SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select([Column("id"), Column("email")])
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select([Column("id")])
/// .select([Column("email")])
@@ -20,13 +20,13 @@ public protocol SelectionRequest {
extension SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select(Column("id"), Column("email"))
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select(Column("id"))
/// .select(Column("email"))
@@ -36,13 +36,13 @@ extension SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select(sql: "id, email")
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select(sql: "id")
/// .select(sql: "email")
@@ -58,7 +58,7 @@ public protocol FilteredRequest {
/// Creates a request with the provided *predicate promise* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE 1
/// // SELECT * FROM player WHERE 1
/// var request = Player.all()
/// request = request.filter { db in true }
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self
@@ -68,7 +68,7 @@ extension FilteredRequest {
/// Creates a request with the provided *predicate* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// var request = Player.all()
/// request = request.filter(Column("email") == "arthur@example.com")
public func filter(_ predicate: SQLExpressible) -> Self {
@@ -78,7 +78,7 @@ extension FilteredRequest {
/// Creates a request with the provided *predicate* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// var request = Player.all()
/// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"])
public func filter(sql: String, arguments: StatementArguments? = nil) -> Self {
@@ -87,7 +87,7 @@ extension FilteredRequest {
/// Creates a request that matches nothing.
///
/// // SELECT * FROM players WHERE 0
/// // SELECT * FROM player WHERE 0
/// var request = Player.all()
/// request = request.none()
public func none() -> Self {
@@ -248,13 +248,13 @@ extension AggregatingRequest {
public protocol OrderedRequest {
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order([Column("name")])
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order([Column("email")])
/// .reversed()
@@ -263,13 +263,13 @@ public protocol OrderedRequest {
/// Creates a request that reverses applied orderings.
///
/// // SELECT * FROM players ORDER BY name DESC
/// // SELECT * FROM player ORDER BY name DESC
/// var request = Player.all().order(Column("name"))
/// request = request.reversed()
///
/// If no ordering was applied, the returned request is identical.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// var request = Player.all()
/// request = request.reversed()
func reversed() -> Self
@@ -278,13 +278,13 @@ public protocol OrderedRequest {
extension OrderedRequest {
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order(Column("name"))
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order(Column("email"))
/// .reversed()
@@ -295,13 +295,13 @@ extension OrderedRequest {
/// Creates a request with the provided *sql* used for sorting.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order(sql: "name")
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order(sql: "email")
/// .order(sql: "name")
@@ -5,8 +5,8 @@
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com' COLLATE NOCASE
/// Players.filter(email == "arthur@example.com")
/// // SELECT * FROM player WHERE email = 'arthur@example.com' COLLATE NOCASE
/// Player.filter(email == "arthur@example.com")
public struct SQLCollatedExpression {
/// The tainted expression
public let expression: SQLExpression
@@ -18,8 +18,8 @@ public struct SQLCollatedExpression {
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players ORDER BY email COLLATE NOCASE ASC
/// Players.order(email.asc)
/// // SELECT * FROM player ORDER BY email COLLATE NOCASE ASC
/// Player.order(email.asc)
///
/// See https://github.com/groue/GRDB.swift/#the-query-interface
public var asc: SQLOrderingTerm {
@@ -30,8 +30,8 @@ public struct SQLCollatedExpression {
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players ORDER BY email COLLATE NOCASE DESC
/// Players.order(email.desc)
/// // SELECT * FROM player ORDER BY email COLLATE NOCASE DESC
/// Player.order(email.desc)
///
/// See https://github.com/groue/GRDB.swift/#the-query-interface
public var desc: SQLOrderingTerm {
@@ -142,8 +142,6 @@ public struct SQLUnaryOperator : Hashable {
/// SQLExpressionUnary is an expression made of an unary operator and
/// an operand expression.
///
/// SQLExpressionUnary(.not, Column("favorite"))
///
/// :nodoc:
public struct SQLExpressionUnary : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -8,11 +8,11 @@
/// For example:
///
/// struct Player : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// let request = Player.all()
public struct AllColumns {
public init() { }
@@ -754,7 +754,7 @@ extension Sequence where Element == SQLExpression {
///
/// For example:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// // WHERE (registered
/// // AND (score >= 1000)
/// // AND (name IS NOT NULL))
@@ -767,10 +767,10 @@ extension Sequence where Element == SQLExpression {
/// When the sequence is empty, `joined(operator: .and)` returns true,
/// and `joined(operator: .or)` returns false:
///
/// // SELECT * FROM players WHERE 1
/// // SELECT * FROM player WHERE 1
/// Player.filter([].joined(operator: .and))
///
/// // SELECT * FROM players WHERE 0
/// // SELECT * FROM player WHERE 0
/// Player.filter([].joined(operator: .or))
public func joined(operator: SQLLogicalBinaryOperator) -> SQLExpression {
let expressions = Array(self)
+28 -28
View File
@@ -5,7 +5,7 @@ extension Database {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -34,7 +34,7 @@ extension Database {
#else
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -66,7 +66,7 @@ extension Database {
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -103,7 +103,7 @@ extension Database {
/// Modifies a database table.
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: "url", .text)
/// }
///
@@ -223,7 +223,7 @@ extension Database {
/// You don't create instances of this class. Instead, you use the Database
/// `create(table:)` method:
///
/// try db.create(table: "players") { t in // t is TableDefinition
/// try db.create(table: "player") { t in // t is TableDefinition
/// t.column(...)
/// }
///
@@ -250,7 +250,7 @@ public final class TableDefinition {
/// Defines the auto-incremented primary key.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// }
///
@@ -282,7 +282,7 @@ public final class TableDefinition {
/// Appends a table column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text)
/// }
///
@@ -301,7 +301,7 @@ public final class TableDefinition {
/// Defines the table primary key.
///
/// try db.create(table: "citizenships") { t in
/// try db.create(table: "citizenship") { t in
/// t.column("citizenID", .integer)
/// t.column("countryCode", .text)
/// t.primaryKey(["citizenID", "countryCode"])
@@ -323,7 +323,7 @@ public final class TableDefinition {
/// Adds a unique key.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.column("latitude", .double)
/// t.column("longitude", .double)
/// t.uniqueKey(["latitude", "longitude"])
@@ -344,7 +344,7 @@ public final class TableDefinition {
/// t.column("issueDate", .date)
/// t.column("citizenID", .integer)
/// t.column("countryCode", .text)
/// t.foreignKey(["citizenID", "countryCode"], references: "citizenships", onDelete: .cascade)
/// t.foreignKey(["citizenID", "countryCode"], references: "citizenship", onDelete: .cascade)
/// }
///
/// See https://www.sqlite.org/foreignkeys.html
@@ -365,7 +365,7 @@ public final class TableDefinition {
/// Adds a CHECK constraint.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("personalPhone", .text)
/// t.column("workPhone", .text)
/// let personalPhone = Column("personalPhone")
@@ -382,7 +382,7 @@ public final class TableDefinition {
/// Adds a CHECK constraint.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("personalPhone", .text)
/// t.column("workPhone", .text)
/// t.check(sql: "personalPhone IS NOT NULL OR workPhone IS NOT NULL")
@@ -509,7 +509,7 @@ public final class TableDefinition {
/// You don't create instances of this class. Instead, you use the Database
/// `alter(table:)` method:
///
/// try db.alter(table: "players") { t in // t is TableAlteration
/// try db.alter(table: "player") { t in // t is TableAlteration
/// t.add(column: ...)
/// }
///
@@ -524,7 +524,7 @@ public final class TableAlteration {
/// Appends a column to the table.
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: "url", .text)
/// }
///
@@ -566,11 +566,11 @@ public final class TableAlteration {
///
/// You get instances of this class when you create or alter a database table:
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column(...) // ColumnDefinition
/// }
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: ...) // ColumnDefinition
/// }
///
@@ -599,7 +599,7 @@ public final class ColumnDefinition {
/// Adds a primary key constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("id", .integer).primaryKey()
/// }
///
@@ -619,7 +619,7 @@ public final class ColumnDefinition {
/// Adds a NOT NULL constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).notNull()
/// }
///
@@ -636,7 +636,7 @@ public final class ColumnDefinition {
/// Adds a UNIQUE constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).unique()
/// }
///
@@ -653,7 +653,7 @@ public final class ColumnDefinition {
/// Adds an index of the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).indexed()
/// }
///
@@ -670,7 +670,7 @@ public final class ColumnDefinition {
/// Adds a CHECK constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).check { length($0) > 0 }
/// }
///
@@ -687,7 +687,7 @@ public final class ColumnDefinition {
/// Adds a CHECK constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).check(sql: "LENGTH(name) > 0")
/// }
///
@@ -705,7 +705,7 @@ public final class ColumnDefinition {
/// Defines the default column value.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).defaults(to: "Anonymous")
/// }
///
@@ -721,7 +721,7 @@ public final class ColumnDefinition {
/// Defines the default column value.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("creationDate", .DateTime).defaults(sql: "CURRENT_TIMESTAMP")
/// }
///
@@ -739,7 +739,7 @@ public final class ColumnDefinition {
// Defines the default column collation.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).collate(.nocase)
/// }
///
@@ -755,7 +755,7 @@ public final class ColumnDefinition {
// Defines the default column collation.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).collate(.localizedCaseInsensitiveCompare)
/// }
///
@@ -771,8 +771,8 @@ public final class ColumnDefinition {
/// Defines a foreign key.
///
/// try db.create(table: "books") { t in
/// t.column("authorId", .integer).references("authors", onDelete: .cascade)
/// try db.create(table: "book") { t in
/// t.column("authorId", .integer).references("author", onDelete: .cascade)
/// }
///
/// See https://www.sqlite.org/foreignkeys.html
+5 -5
View File
@@ -2,7 +2,7 @@
/// the `Database.create(virtualTable:using:)` method:
///
/// let module = ...
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// ...
/// }
///
@@ -13,7 +13,7 @@ public protocol VirtualTableModule {
/// The type of the closure argument in the
/// `Database.create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// // t is TableDefinition
/// }
associatedtype TableDefinition
@@ -24,7 +24,7 @@ public protocol VirtualTableModule {
/// Returns a table definition that is passed as the closure argument in the
/// `Database.create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// // t is the result of makeTableDefinition()
/// }
func makeTableDefinition() -> TableDefinition
@@ -70,7 +70,7 @@ extension Database {
/// Creates a virtual database table.
///
/// let module = ...
/// try db.create(virtualTable: "pointOfInterests", using: module) { t in
/// try db.create(virtualTable: "book", using: module) { t in
/// ...
/// }
///
@@ -80,7 +80,7 @@ extension Database {
/// Use this method to create full-text tables using the FTS3, FTS4, or
/// FTS5 modules:
///
/// try db.create(virtualTable: "books", using: FTS4()) { t in
/// try db.create(virtualTable: "book", using: FTS4()) { t in
/// t.column("title")
/// t.column("author")
/// t.column("body")
@@ -273,4 +273,3 @@ extension FetchableRecord where Self: Decodable {
try! self.init(from: RowDecoder(row: row, codingPath: []))
}
}
@@ -4,7 +4,7 @@ extension FetchableRecord where Self: TableRecord {
/// A cursor over all records fetched from the database.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let players = try Player.fetchCursor(db) // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
@@ -30,7 +30,7 @@ extension FetchableRecord where Self: TableRecord {
/// An array of all records fetched from the database.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let players = try Player.fetchAll(db) // [Player]
///
/// The selection defaults to all columns. This default can be changed for
@@ -45,7 +45,7 @@ extension FetchableRecord where Self: TableRecord {
/// The first found record.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let player = try Player.fetchOne(db) // Player?
///
/// The selection defaults to all columns. This default can be changed for
+7 -7
View File
@@ -36,7 +36,7 @@ public protocol FetchableRecord {
///
/// struct Player : FetchableRecord { ... }
/// try dbQueue.read { db in
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, "SELECT * FROM players")
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, "SELECT * FROM player")
/// }
public final class RecordCursor<Record: FetchableRecord> : Cursor {
private let statement: SelectStatement
@@ -73,7 +73,7 @@ extension FetchableRecord {
/// A cursor over records fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let players = try Player.fetchCursor(statement) // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
@@ -96,7 +96,7 @@ extension FetchableRecord {
/// Returns an array of records fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let players = try Player.fetchAll(statement) // [Player]
///
/// - parameters:
@@ -111,7 +111,7 @@ extension FetchableRecord {
/// Returns a single record fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let player = try Player.fetchOne(statement) // Player?
///
/// - parameters:
@@ -131,7 +131,7 @@ extension FetchableRecord {
/// Returns a cursor over records fetched from an SQL query.
///
/// let players = try Player.fetchCursor(db, "SELECT * FROM players") // Cursor of Player
/// let players = try Player.fetchCursor(db, "SELECT * FROM player") // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
/// }
@@ -154,7 +154,7 @@ extension FetchableRecord {
/// Returns an array of records fetched from an SQL query.
///
/// let players = try Player.fetchAll(db, "SELECT * FROM players") // [Player]
/// let players = try Player.fetchAll(db, "SELECT * FROM player") // [Player]
///
/// - parameters:
/// - db: A database connection.
@@ -169,7 +169,7 @@ extension FetchableRecord {
/// Returns a single record fetched from an SQL query.
///
/// let player = try Player.fetchOne(db, "SELECT * FROM players") // Player?
/// let player = try Player.fetchOne(db, "SELECT * FROM player") // Player?
///
/// - parameters:
/// - db: A database connection.
+5 -6
View File
@@ -18,7 +18,7 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
///
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red],
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
///
@@ -402,17 +402,17 @@ extension FetchedRecordsController where Record: TableRecord {
///
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red])
///
/// The records are compared by primary key (single-column primary key,
/// compound primary key, or implicit rowid). For a database table which
/// has an `id` primary key, this initializer is equivalent to:
///
/// // Assuming the wines table has an `id` primary key:
/// // Assuming the wine table has an `id` primary key:
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red],
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
///
@@ -451,7 +451,7 @@ extension FetchedRecordsController where Record: TableRecord {
/// compound primary key, or implicit rowid). For a database table which
/// has an `id` primary key, this initializer is equivalent to:
///
/// // Assuming the wines table has an `id` primary key:
/// // Assuming the wine table has an `id` primary key:
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// request: request,
@@ -1049,4 +1049,3 @@ private final class Item<T: FetchableRecord> : FetchableRecord, Equatable {
return lhs.row == rhs.row
}
}
+6 -6
View File
@@ -623,16 +623,16 @@ extension MutablePersistableRecord {
/// Delete records identified by their primary keys; returns the number of
/// deleted rows.
///
/// // DELETE FROM players WHERE id IN (1, 2, 3)
/// // DELETE FROM player WHERE id IN (1, 2, 3)
/// try Player.deleteAll(db, keys: [1, 2, 3])
///
/// // DELETE FROM countries WHERE code IN ('FR', 'US', 'DE')
/// // DELETE FROM country WHERE code IN ('FR', 'US', 'DE')
/// try Country.deleteAll(db, keys: ["FR", "US", "DE"])
///
/// When the table has no explicit primary key, GRDB uses the hidden
/// "rowid" column:
///
/// // DELETE FROM documents WHERE rowid IN (1, 2, 3)
/// // DELETE FROM document WHERE rowid IN (1, 2, 3)
/// try Document.deleteAll(db, keys: [1, 2, 3])
///
/// - parameters:
@@ -652,16 +652,16 @@ extension MutablePersistableRecord {
/// Delete a record, identified by its primary key; returns whether a
/// database row was deleted.
///
/// // DELETE FROM players WHERE id = 123
/// // DELETE FROM player WHERE id = 123
/// try Player.deleteOne(db, key: 123)
///
/// // DELETE FROM countries WHERE code = 'FR'
/// // DELETE FROM country WHERE code = 'FR'
/// try Country.deleteOne(db, key: "FR")
///
/// When the table has no explicit primary key, GRDB uses the hidden
/// "rowid" column:
///
/// // DELETE FROM documents WHERE rowid = 1
/// // DELETE FROM document WHERE rowid = 1
/// try Document.deleteOne(db, key: 1)
///
/// - parameters:
+4 -4
View File
@@ -32,7 +32,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
///
/// class Player : Record {
/// override class var databaseTableName: String {
/// return "players"
/// return "player"
/// }
/// }
///
@@ -64,7 +64,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
///
/// Unless this method is overriden, requests select all columns:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
///
/// You can override this property and provide an explicit list
@@ -76,7 +76,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
/// }
/// }
///
/// // SELECT id, name FROM players
/// // SELECT id, name FROM player
/// try RestrictedPlayer.fetchAll(db)
///
/// You can also add extra columns such as the `rowid` column:
@@ -87,7 +87,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
/// }
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// try ExtendedPlayer.fetchAll(db)
open class var databaseSelection: [SQLSelectable] {
return [AllColumns()]
+14 -14
View File
@@ -12,10 +12,10 @@ public protocol TableRecord {
/// The name of the database table used to build requests.
///
/// struct Player : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// }
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
static var databaseTableName: String { get }
@@ -23,28 +23,28 @@ public protocol TableRecord {
///
/// Unless said otherwise, requests select all columns:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
///
/// You can provide a custom implementation and provide an explicit list
/// of columns:
///
/// struct RestrictedPlayer : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static var databaseSelection = [Column("id"), Column("name")]
/// }
///
/// // SELECT id, name FROM players
/// // SELECT id, name FROM player
/// try RestrictedPlayer.fetchAll(db)
///
/// You can also add extra columns such as the `rowid` column:
///
/// struct ExtendedPlayer : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// try ExtendedPlayer.fetchAll(db)
static var databaseSelection: [SQLSelectable] { get }
}
@@ -77,14 +77,14 @@ extension TableRecord {
/// For example:
///
/// struct Player: TableRecord {
/// static let databaseTableName = "players"
/// static let databaseTableName = "player"
/// }
///
/// // SELECT "players".* FROM players
/// let sql = "SELECT \(Player.selectionSQL()) FROM players"
/// // SELECT "player".* FROM player
/// let sql = "SELECT \(Player.selectionSQL()) FROM player"
///
/// // SELECT "p".* FROM players AS p
/// let sql = "SELECT \(Player.selectionSQL(alias: "p")) FROM players AS p"
/// // SELECT "p".* FROM player AS p
/// let sql = "SELECT \(Player.selectionSQL(alias: "p")) FROM player p"
public static func selectionSQL(alias: String? = nil) -> String {
let alias = TableAlias(tableName: databaseTableName, userName: alias)
let selection = databaseSelection.map { $0.qualifiedSelectable(with: alias) }
@@ -99,11 +99,11 @@ extension TableRecord {
/// For example:
///
/// struct Player: TableRecord {
/// static let databaseTableName = "players"
/// static let databaseTableName = "player"
/// }
///
/// try dbQueue.write { db in
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text)
/// t.column("score", .integer)
+1
View File
@@ -30,6 +30,7 @@ GRDB 3.0
- [ ] If required by associations, make reversed() make nothing when there is no alraedy applied ordering
- [ ] Fix matchingRowIds
- [ ] Simplify Range extensions for Swift 4.1
- [ ] https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/6
Not sure