Add unit tests

This commit is contained in:
2025-10-25 18:56:55 +03:00
parent ddc47abdde
commit bbb7f14650
38 changed files with 1051 additions and 526 deletions

View File

@@ -2,11 +2,9 @@ import Foundation
/// A delegate that observes connection-level database events.
///
/// Conforming types can monitor row-level updates and transaction lifecycle events. All methods are
/// optional default implementations do nothing.
///
/// This protocol is typically used for debugging, logging, or synchronizing application state with
/// database changes.
/// Conforming types can monitor row-level updates and transaction lifecycle events. This protocol
/// is typically used for debugging, logging, or synchronizing application state with database
/// changes.
///
/// - Important: Delegate methods are invoked synchronously on SQLites internal execution thread.
/// Implementations must be lightweight and non-blocking to avoid slowing down SQL operations.
@@ -43,9 +41,3 @@ public protocol ConnectionDelegate: AnyObject {
/// - Parameter connection: The connection that rolled back.
func connectionDidRollback(_ connection: ConnectionProtocol)
}
public extension ConnectionDelegate {
func connection(_ connection: ConnectionProtocol, didUpdate action: SQLiteAction) {}
func connectionWillCommit(_ connection: ConnectionProtocol) throws {}
func connectionDidRollback(_ connection: ConnectionProtocol) {}
}

View File

@@ -12,10 +12,10 @@ import Foundation
///
/// - ``isAutocommit``
/// - ``isReadonly``
/// - ``busyTimeout``
///
/// ### Accessing PRAGMA Values
///
/// - ``busyTimeout``
/// - ``applicationID``
/// - ``foreignKeys``
/// - ``journalMode``
@@ -84,6 +84,8 @@ public protocol ConnectionProtocol: AnyObject {
/// - SeeAlso: [Determine if a database is read-only](https://sqlite.org/c3ref/db_readonly.html)
var isReadonly: Bool { get }
// MARK: - PRAGMA Accessors
/// The busy timeout of the connection, in milliseconds.
///
/// Defines how long SQLite waits for a locked database to become available before returning
@@ -93,8 +95,6 @@ public protocol ConnectionProtocol: AnyObject {
/// - SeeAlso: [Set A Busy Timeout](https://sqlite.org/c3ref/busy_timeout.html)
var busyTimeout: Int32 { get set }
// MARK: - PRAGMA Accessors
/// The application identifier stored in the database header.
///
/// Used to distinguish database files created by different applications or file formats. This

View File

@@ -8,6 +8,11 @@ import Foundation
///
/// ## Topics
///
/// ### Retrieving Statement SQL
///
/// - ``sql``
/// - ``expandedSQL``
///
/// ### Binding Parameters
///
/// - ``parameterCount()``
@@ -34,6 +39,20 @@ import Foundation
/// - ``columnValue(at:)->T?``
/// - ``currentRow()``
public protocol StatementProtocol {
// MARK: - Retrieving Statement SQL
/// The original SQL text used to create this prepared statement.
///
/// Returns the statement text as it was supplied when the statement was prepared. Useful for
/// diagnostics or query introspection.
var sql: String? { get }
/// The SQL text with all parameter values expanded into their literal forms.
///
/// Shows the actual SQL string that would be executed after parameter binding. Useful for
/// debugging and logging queries.
var expandedSQL: String? { get }
// MARK: - Binding Parameters
/// Returns the number of parameters in the prepared SQLite statement.
@@ -101,7 +120,7 @@ public protocol StatementProtocol {
///
/// - Parameters:
/// - value: The ``SQLiteValue`` to bind.
/// - name: The parameter name as written in SQL, including its prefix.
/// - name: The parameter name exactly as written in SQL, including its prefix.
/// - Throws: ``SQLiteError`` if binding fails.
///
/// - SeeAlso: [Binding Values To Prepared Statements](
@@ -130,7 +149,7 @@ public protocol StatementProtocol {
///
/// - Parameters:
/// - value: The value to bind. If `nil`, `NULL` is bound.
/// - name: The parameter name as written in SQL, including its prefix.
/// - name: The parameter name exactly as written in SQL, including its prefix.
/// - Throws: ``SQLiteError`` if binding fails.
///
/// - SeeAlso: [Binding Values To Prepared Statements](