diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index 915175b92..854498145 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -4,10 +4,10 @@ import SQLite3 #endif -// MARK: - Database Schema - extension Database { - + + // MARK: - Database Schema + /// Clears the database schema cache. /// /// You may need to clear the cache manually if the database schema is diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index 1813d535d..0f8ae6b90 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -1,9 +1,9 @@ import Foundation -// MARK: - Prepared Statements - extension Database { - + + // MARK: - Statements + /// Returns a new prepared statement that can be reused. /// /// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?") diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 47b82402c..3a5c64bc1 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -175,9 +175,10 @@ public final class Database { } } -// MARK: - Database Opening - extension Database { + + // MARK: - Database Opening + /// Registers the public Database.logError function as the global SQLite /// error log, with sqlite3_config(SQLITE_CONFIG_LOG). /// @@ -267,9 +268,10 @@ extension Database { } } -// MARK: - Database Setup - extension Database { + + // MARK: - Database Setup + /// This method must be called after database initialization func setup() throws { // Setup trace first, so that setup queries are traced. @@ -376,9 +378,10 @@ extension Database { } } -// MARK: - Database Closing - extension Database { + + // MARK: - Database Closing + /// This method must be called before database deallocation func close() { SchedulingWatchdog.preconditionValidQueue(self) @@ -462,9 +465,10 @@ extension Database { #endif } -// MARK: - Functions - extension Database { + + // MARK: - Functions + /// Add or redefine an SQL function. /// /// let fn = DatabaseFunction("succ", argumentCount: 1) { dbValues in @@ -487,9 +491,10 @@ extension Database { } } -// MARK: - Collations - extension Database { + + // MARK: - Collations + /// Add or redefine a collation. /// /// let collation = DatabaseCollation("localized_standard") { (string1, string2) in @@ -526,9 +531,10 @@ extension Database { } } -// MARK: - Transactions & Savepoint - extension Database { + + // MARK: - Transactions & Savepoint + /// Executes a block inside a database transaction. /// /// try dbQueue.inDatabase do { @@ -727,9 +733,10 @@ extension Database { } } -// MARK: - Memory Management - extension Database { + + // MARK: - Memory Management + func releaseMemory() { sqlite3_db_release_memory(sqliteConnection) schemaCache.clear() @@ -738,10 +745,11 @@ extension Database { } } -// MARK: - Encryption - #if SQLITE_HAS_CODEC extension Database { + + // MARK: - Encryption + func change(passphrase: String) throws { // FIXME: sqlite3_rekey is discouraged. // @@ -763,8 +771,6 @@ extension Database { } #endif -// MARK: - Public Database Types - extension Database { /// See BusyMode and https://www.sqlite.org/c3ref/busy_handler.html @@ -933,8 +939,6 @@ extension Database { } } -// MARK: - Internal Database Types - extension Database { /// An SQLite threading mode. See https://www.sqlite.org/threadsafe.html. enum ThreadingMode { diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 6c93daa75..764622e62 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -110,10 +110,10 @@ public final class DatabasePool { #endif } -// MARK: - WAL Checkpoints - extension DatabasePool { - + + // MARK: - WAL Checkpoints + /// Runs a WAL checkpoint /// /// See https://www.sqlite.org/wal.html and @@ -134,10 +134,10 @@ extension DatabasePool { } } -// MARK: - Memory management - extension DatabasePool { - + + // MARK: - Memory management + /// Free as much memory as possible. /// /// This method blocks the current thread until all database accesses are completed. @@ -196,10 +196,11 @@ extension DatabasePool { #endif } -// MARK: - Encryption - #if SQLITE_HAS_CODEC extension DatabasePool { + + // MARK: - Encryption + /// Changes the passphrase of an encrypted database public func change(passphrase: String) throws { try readerPool.clear(andThen: { @@ -210,12 +211,10 @@ extension DatabasePool { } #endif -// MARK: - DatabaseReader - extension DatabasePool : DatabaseReader { - // MARK: - Read From Database - + // MARK: - Reading from Database + /// Synchronously executes a read-only block in a protected dispatch queue, /// and returns its result. The block is wrapped in a deferred transaction. /// @@ -351,7 +350,6 @@ extension DatabasePool : DatabaseReader { return readers.first { $0.onValidQueue } } - // MARK: - Functions /// Add or redefine an SQL function. @@ -383,7 +381,6 @@ extension DatabasePool : DatabaseReader { } } - // MARK: - Collations /// Add or redefine a collation. @@ -413,8 +410,6 @@ extension DatabasePool : DatabaseReader { } } -// MARK: - DatabaseWriter - extension DatabasePool : DatabaseWriter { // MARK: - Writing in Database diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index 59c829ea3..cab51b234 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -68,10 +68,10 @@ public final class DatabaseQueue { #endif } -// MARK: - Database Access - extension DatabaseQueue { - + + // MARK: - Database Access + /// Synchronously executes a block in a protected dispatch queue, and /// returns its result. /// @@ -118,10 +118,10 @@ extension DatabaseQueue { } } -// MARK: - Memory management - extension DatabaseQueue { - + + // MARK: - Memory management + /// Free as much memory as possible. /// /// This method blocks the current thread until all database accesses are completed. @@ -174,11 +174,11 @@ extension DatabaseQueue { #endif } -// MARK: - Encryption - #if SQLITE_HAS_CODEC extension DatabaseQueue { + // MARK: - Encryption + /// Changes the passphrase of an encrypted database public func change(passphrase: String) throws { try inDatabase { try $0.change(passphrase: passphrase) } @@ -186,13 +186,10 @@ extension DatabaseQueue { } #endif - -// MARK: - DatabaseReader - extension DatabaseQueue : DatabaseReader { // MARK: - DatabaseReader Protocol Adoption - + /// Synchronously executes a read-only block in a protected dispatch queue, /// and returns its result. /// @@ -240,7 +237,6 @@ extension DatabaseQueue : DatabaseReader { return try serializedDatabase.reentrantSync(block) } - // MARK: - Functions /// Add or redefine an SQL function. @@ -264,7 +260,6 @@ extension DatabaseQueue : DatabaseReader { inDatabase { $0.remove(function: function) } } - // MARK: - Collations /// Add or redefine a collation. @@ -286,12 +281,10 @@ extension DatabaseQueue : DatabaseReader { } } -// MARK: - DatabaseWriter - extension DatabaseQueue : DatabaseWriter { // MARK: - DatabaseWriter Protocol Adoption - + /// Alias for `inDatabase`. See `DatabaseWriter.write`. public func write(_ block: (Database) throws -> T) rethrows -> T { return try inDatabase(block) diff --git a/GRDB/Core/DatabaseReader.swift b/GRDB/Core/DatabaseReader.swift index 84ee9c46e..c632b426b 100644 --- a/GRDB/Core/DatabaseReader.swift +++ b/GRDB/Core/DatabaseReader.swift @@ -221,6 +221,8 @@ public final class AnyDatabaseReader : DatabaseReader { self.base = base } + // MARK: - Reading from Database + public func read(_ block: (Database) throws -> T) throws -> T { return try base.read(block) } @@ -233,6 +235,8 @@ public final class AnyDatabaseReader : DatabaseReader { return try base.unsafeReentrantRead(block) } + // MARK: - Functions + public func add(function: DatabaseFunction) { base.add(function: function) } @@ -241,6 +245,8 @@ public final class AnyDatabaseReader : DatabaseReader { base.remove(function: function) } + // MARK: - Collations + public func add(collation: DatabaseCollation) { base.add(collation: collation) } diff --git a/GRDB/Core/DatabaseWriter.swift b/GRDB/Core/DatabaseWriter.swift index 7c8f5b264..c3f8ef200 100644 --- a/GRDB/Core/DatabaseWriter.swift +++ b/GRDB/Core/DatabaseWriter.swift @@ -136,6 +136,8 @@ public final class AnyDatabaseWriter : DatabaseWriter { self.base = base } + // MARK: - Reading from Database + public func read(_ block: (Database) throws -> T) throws -> T { return try base.read(block) } @@ -148,21 +150,11 @@ public final class AnyDatabaseWriter : DatabaseWriter { return try base.unsafeReentrantRead(block) } - public func add(function: DatabaseFunction) { - base.add(function: function) + public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { + try base.readFromCurrentState(block) } - public func remove(function: DatabaseFunction) { - base.remove(function: function) - } - - public func add(collation: DatabaseCollation) { - base.add(collation: collation) - } - - public func remove(collation: DatabaseCollation) { - base.remove(collation: collation) - } + // MARK: - Writing in Database public func write(_ block: (Database) throws -> T) rethrows -> T { return try base.write(block) @@ -171,8 +163,24 @@ public final class AnyDatabaseWriter : DatabaseWriter { public func unsafeReentrantWrite(_ block: (Database) throws -> T) rethrows -> T { return try base.unsafeReentrantWrite(block) } - - public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { - try base.readFromCurrentState(block) + + // MARK: - Functions + + public func add(function: DatabaseFunction) { + base.add(function: function) + } + + public func remove(function: DatabaseFunction) { + base.remove(function: function) + } + + // MARK: - Collations + + public func add(collation: DatabaseCollation) { + base.add(collation: collation) + } + + public func remove(collation: DatabaseCollation) { + base.remove(collation: collation) } } diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 4623c19bc..3ddf7010f 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -4,9 +4,10 @@ import SQLite3 #endif -// MARK: - Database Observation - extension Database { + + // MARK: - Database Observation + /// Add a transaction observer, so that it gets notified of /// database changes. /// diff --git a/GRDB/FTS/FTS5CustomTokenizer.swift b/GRDB/FTS/FTS5CustomTokenizer.swift index 357d9bccf..883f1fbc0 100644 --- a/GRDB/FTS/FTS5CustomTokenizer.swift +++ b/GRDB/FTS/FTS5CustomTokenizer.swift @@ -38,7 +38,7 @@ extension Database { - // MARK: - Custom FTS5 Tokenizers + // MARK: - FTS5 private class FTS5TokenizerConstructor { let db: Database diff --git a/GRDB/FTS/FTS5Pattern.swift b/GRDB/FTS/FTS5Pattern.swift index fa8e5a058..e10dbf4db 100644 --- a/GRDB/FTS/FTS5Pattern.swift +++ b/GRDB/FTS/FTS5Pattern.swift @@ -77,6 +77,8 @@ extension Database { + // MARK: - FTS5 + /// Creates a pattern from a raw pattern string; throws DatabaseError on /// invalid syntax. /// diff --git a/GRDB/FTS/FTS5Tokenizer.swift b/GRDB/FTS/FTS5Tokenizer.swift index f57eeb811..dcb01d7f7 100644 --- a/GRDB/FTS/FTS5Tokenizer.swift +++ b/GRDB/FTS/FTS5Tokenizer.swift @@ -106,8 +106,9 @@ } extension Database { - /// MARK: - FTS5 Tokenizers + // MARK: - FTS5 + /// Private type that makes a pre-registered FTS5 tokenizer available /// through the FTS5Tokenizer protocol. private final class FTS5RegisteredTokenizer : FTS5Tokenizer { diff --git a/GRDB/QueryInterface/VirtualTableModule.swift b/GRDB/QueryInterface/VirtualTableModule.swift index 296d4b346..c9f06087f 100644 --- a/GRDB/QueryInterface/VirtualTableModule.swift +++ b/GRDB/QueryInterface/VirtualTableModule.swift @@ -39,7 +39,7 @@ public protocol VirtualTableModule { extension Database { - // MARK: - Database Schema: Virtual Table + // MARK: - Database Schema /// Creates a virtual database table. ///