@@ -96,7 +96,15 @@ extension Database {
96
96
97
97
// MARK: - Database Schema
98
98
99
- /// Returns the current schema version.
99
+ /// Returns the current schema version (`PRAGMA schema_version`).
100
+ ///
101
+ /// For example:
102
+ ///
103
+ /// ```swift
104
+ /// let version = try dbQueue.read { db in
105
+ /// try db.schemaVersion()
106
+ /// }
107
+ /// ```
100
108
///
101
109
/// Related SQLite documentation: <https://www.sqlite.org/pragma.html#pragma_schema_version>
102
110
public func schemaVersion( ) throws -> Int32 {
@@ -234,8 +242,19 @@ extension Database {
234
242
235
243
/// Returns whether a table exists
236
244
///
237
- /// When `schemaName` is not specified, known schemas are iterated in
238
- /// SQLite resolution order and the first matching result is returned.
245
+ /// When `schemaName` is not specified, the result is true if any known
246
+ /// schema contains the table.
247
+ ///
248
+ /// For example:
249
+ ///
250
+ /// ```swift
251
+ /// try dbQueue.read { db in
252
+ /// if try db.tableExists("player") { ... }
253
+ /// if try db.tableExists("player", in: "main") { ... }
254
+ /// if try db.tableExists("player", in: "temp") { ... }
255
+ /// if try db.tableExists("player", in: "attached") { ... }
256
+ /// }
257
+ /// ```
239
258
///
240
259
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or
241
260
/// if the specified schema does not exist
@@ -278,8 +297,19 @@ extension Database {
278
297
/// Returns whether a view exists, in the main or temp schema, or in an
279
298
/// attached database.
280
299
///
281
- /// When `schemaName` is not specified, known schemas are iterated in
282
- /// SQLite resolution order and the first matching result is returned.
300
+ /// When `schemaName` is not specified, the result is true if any known
301
+ /// schema contains the table.
302
+ ///
303
+ /// For example:
304
+ ///
305
+ /// ```swift
306
+ /// try dbQueue.read { db in
307
+ /// if try db.viewExists("player") { ... }
308
+ /// if try db.viewExists("player", in: "main") { ... }
309
+ /// if try db.viewExists("player", in: "temp") { ... }
310
+ /// if try db.viewExists("player", in: "attached") { ... }
311
+ /// }
312
+ /// ```
283
313
///
284
314
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or
285
315
/// if the specified schema does not exist
@@ -296,8 +326,19 @@ extension Database {
296
326
/// Returns whether a trigger exists, in the main or temp schema, or in an
297
327
/// attached database.
298
328
///
299
- /// When `schemaName` is not specified, known schemas are iterated in
300
- /// SQLite resolution order and the first matching result is returned.
329
+ /// When `schemaName` is not specified, the result is true if any known
330
+ /// schema contains the table.
331
+ ///
332
+ /// For example:
333
+ ///
334
+ /// ```swift
335
+ /// try dbQueue.read { db in
336
+ /// if try db.triggerExists("on_player_update") { ... }
337
+ /// if try db.triggerExists("on_player_update", in: "main") { ... }
338
+ /// if try db.triggerExists("on_player_update", in: "temp") { ... }
339
+ /// if try db.triggerExists("on_player_update", in: "attached") { ... }
340
+ /// }
341
+ /// ```
301
342
///
302
343
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or
303
344
/// if the specified schema does not exist
@@ -340,6 +381,15 @@ extension Database {
340
381
/// table has no explicit primary key, the result is the hidden
341
382
/// "rowid" column.
342
383
///
384
+ /// For example:
385
+ ///
386
+ /// ```swift
387
+ /// try dbQueue.read { db in
388
+ /// let primaryKey = try db.primaryKey("player")
389
+ /// print(primaryKey.columns)
390
+ /// }
391
+ /// ```
392
+ ///
343
393
/// When `schemaName` is not specified, known schemas are iterated in
344
394
/// SQLite resolution order and the first matching result is returned.
345
395
///
@@ -529,14 +579,26 @@ extension Database {
529
579
530
580
/// The indexes on table named `tableName`.
531
581
///
582
+ /// For example:
583
+ ///
584
+ /// ```swift
585
+ /// try dbQueue.read { db in
586
+ /// let indexes = db.indexes(in: "player")
587
+ /// for index in indexes {
588
+ /// print(index.columns)
589
+ /// }
590
+ /// }
591
+ /// ```
592
+ ///
532
593
/// Only indexes on columns are returned. Indexes on expressions are
533
594
/// not returned.
534
595
///
535
- /// SQLite does not define any index for INTEGER PRIMARY KEY columns: this
536
- /// method does not return any index that represents the primary key.
596
+ /// SQLite does not define any index for INTEGER PRIMARY KEY columns:
597
+ /// this method does not return any index that represents the
598
+ /// primary key.
537
599
///
538
- /// If you want to know if a set of columns uniquely identifies a row, because
539
- /// the columns contain the primary key or a unique index, use
600
+ /// If you want to know if a set of columns uniquely identifies a row,
601
+ /// because the columns contain the primary key or a unique index, use
540
602
/// ``table(_:hasUniqueKey:)``.
541
603
///
542
604
/// When `schemaName` is not specified, known schemas are iterated in
@@ -617,16 +679,19 @@ extension Database {
617
679
/// For example:
618
680
///
619
681
/// ```swift
620
- /// // One table with one primary key (id), and a unique index (a, b):
621
- /// //
622
- /// // > CREATE TABLE t(id INTEGER PRIMARY KEY, a, b, c);
623
- /// // > CREATE UNIQUE INDEX i ON t(a, b);
624
- /// try db.table("t", hasUniqueKey: ["id"]) // true
625
- /// try db.table("t", hasUniqueKey: ["a", "b"]) // true
626
- /// try db.table("t", hasUniqueKey: ["b", "a"]) // true
627
- /// try db.table("t", hasUniqueKey: ["c"]) // false
628
- /// try db.table("t", hasUniqueKey: ["id", "a"]) // true
629
- /// try db.table("t", hasUniqueKey: ["id", "a", "b", "c"]) // true
682
+ /// try dbQueue.read { db in
683
+ /// // One table with one primary key (id)
684
+ /// // and a unique index (a, b):
685
+ /// //
686
+ /// // > CREATE TABLE t(id INTEGER PRIMARY KEY, a, b, c);
687
+ /// // > CREATE UNIQUE INDEX i ON t(a, b);
688
+ /// try db.table("t", hasUniqueKey: ["id"]) // true
689
+ /// try db.table("t", hasUniqueKey: ["a", "b"]) // true
690
+ /// try db.table("t", hasUniqueKey: ["b", "a"]) // true
691
+ /// try db.table("t", hasUniqueKey: ["c"]) // false
692
+ /// try db.table("t", hasUniqueKey: ["id", "a"]) // true
693
+ /// try db.table("t", hasUniqueKey: ["id", "a", "b", "c"]) // true
694
+ /// }
630
695
/// ```
631
696
public func table(
632
697
_ tableName: String ,
@@ -640,6 +705,17 @@ extension Database {
640
705
/// When `schemaName` is not specified, known schemas are iterated in
641
706
/// SQLite resolution order and the first matching result is returned.
642
707
///
708
+ /// For example:
709
+ ///
710
+ /// ```swift
711
+ /// try dbQueue.read { db in
712
+ /// let foreignKeys = try db.foreignKeys(in: "player")
713
+ /// for foreignKey in foreignKeys {
714
+ /// print(foreignKey.destinationTable)
715
+ /// }
716
+ /// }
717
+ /// ```
718
+ ///
643
719
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, if
644
720
/// the specified schema does not exist, or if no such table or view
645
721
/// with this name exists in the main or temp schema, or in an attached
@@ -861,6 +937,17 @@ extension Database {
861
937
/// When `schemaName` is not specified, known schemas are iterated in
862
938
/// SQLite resolution order and the first matching result is returned.
863
939
///
940
+ /// For example:
941
+ ///
942
+ /// ```swift
943
+ /// try dbQueue.read { db in
944
+ /// let columns = try db.columns(in: "player")
945
+ /// for column in columns {
946
+ /// print(column.name)
947
+ /// }
948
+ /// }
949
+ /// ```
950
+ ///
864
951
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, if
865
952
/// the specified schema does not exist,or if no such table or view
866
953
/// with this name exists in the main or temp schema, or in an attached
0 commit comments