mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-22 04:00:39 +00:00
Generic connection WIP
This commit is contained in:
1 parent
b31be05ee3
commit
3777ba0df2
189 files changed
+2145
-1993
No files matched your search
+113
-113
@@ -1731,7 +1731,7 @@ The [Advanced DatabasePool](README.md#advanced-databasepool) chapter has been ex
|
||||
|
||||
```diff
|
||||
class DatabasePool {
|
||||
+ func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T
|
||||
+ func barrierWriteWithoutTransaction<T>(_ updates: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T
|
||||
+ func invalidateReadOnlyConnections()
|
||||
}
|
||||
|
||||
@@ -1851,7 +1851,7 @@ The [ValueObservation](README.md#valueobservation) chapter has been updated so t
|
||||
}
|
||||
|
||||
extension ValueObservation where Reducer == Void {
|
||||
+ static func tracking<Value>(fetch: @escaping (Database) throws -> Value) -> ValueObservation<ValueReducers.Fetch<Value>>
|
||||
+ static func tracking<Value>(fetch: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Value) -> ValueObservation<ValueReducers.Fetch<Value>>
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1896,7 +1896,7 @@ The [ValueObservation Error Handling](README.md#valueobservation-error-handling)
|
||||
+ var configuration: Configuration { get }
|
||||
+
|
||||
+ #if compiler(>=5.0)
|
||||
+ func asyncRead(_ block: @escaping (Result<Database, Error>) -> Void)
|
||||
+ func asyncRead(_ block: @escaping (Result<DatabaseBase<some SQLiteAPI>, Error>) -> Void)
|
||||
+ #endif
|
||||
}
|
||||
|
||||
@@ -1904,7 +1904,7 @@ The [ValueObservation Error Handling](README.md#valueobservation-error-handling)
|
||||
+ func asyncWriteWithoutTransaction(_ updates: @escaping (Database) -> Void)
|
||||
+
|
||||
+ #if compiler(>=5.0)
|
||||
+ func asyncWrite<T>(_ updates: @escaping (Database) throws -> T, completion: @escaping (Database, Result<T, Error>) -> Void)
|
||||
+ func asyncWrite<T>(_ updates: @escaping (DatabaseBase<some SQLiteAPI>) throws -> T, completion: @escaping (Database, Result<T, Error>) -> Void)
|
||||
+ #endif
|
||||
}
|
||||
```
|
||||
@@ -1984,8 +1984,8 @@ The [ValueObservation Error Handling](README.md#valueobservation-error-handling)
|
||||
|
||||
protocol FetchRequest {
|
||||
+ // deprecated
|
||||
func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
func prepare(_ db: DatabaseBase<some SQLiteAPI>, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func makePreparedRequest(_ db: DatabaseBase<some SQLiteAPI>, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2189,37 +2189,37 @@ It comes with new features, but also a few breaking changes. The [GRDB 4 Migrati
|
||||
}
|
||||
|
||||
class Row {
|
||||
- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor
|
||||
- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row]
|
||||
- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row?
|
||||
+ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor
|
||||
+ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row]
|
||||
+ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row?
|
||||
- static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor
|
||||
- static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row]
|
||||
- static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row?
|
||||
+ static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor
|
||||
+ static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row]
|
||||
+ static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row?
|
||||
}
|
||||
|
||||
extension FetchableRecord {
|
||||
- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor<Self>
|
||||
- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]
|
||||
- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?
|
||||
+ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor<Self>
|
||||
+ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]
|
||||
+ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?
|
||||
- static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor<Self>
|
||||
- static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]
|
||||
- static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?
|
||||
+ static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor<Self>
|
||||
+ static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]
|
||||
+ static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible {
|
||||
- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>
|
||||
- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]
|
||||
- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?
|
||||
+ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>
|
||||
+ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]
|
||||
+ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?
|
||||
- static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>
|
||||
- static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]
|
||||
- static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?
|
||||
+ static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>
|
||||
+ static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]
|
||||
+ static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped>
|
||||
- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?]
|
||||
+ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped>
|
||||
+ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?]
|
||||
- static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped>
|
||||
- static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?]
|
||||
+ static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped>
|
||||
+ static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?]
|
||||
}
|
||||
|
||||
extension TableRecord {
|
||||
@@ -2324,7 +2324,7 @@ It comes with new features, but also a few breaking changes. The [GRDB 4 Migrati
|
||||
struct ValueObservation<Reducer> {
|
||||
- var extent: Database.TransactionObservationExtent
|
||||
- static func tracking(_ regions: DatabaseRegionConvertible..., reducer: Reducer) -> ValueObservation
|
||||
- static func tracking<Value>(_ regions: DatabaseRegionConvertible..., fetchDistinct fetch: @escaping (Database) throws -> Value) -> ValueObservation<DistinctUntilChangedValueReducer<RawValueReducer<Value>>> where Value: Equatable
|
||||
- static func tracking<Value>(_ regions: DatabaseRegionConvertible..., fetchDistinct fetch: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Value) -> ValueObservation<DistinctUntilChangedValueReducer<RawValueReducer<Value>>> where Value: Equatable
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2467,12 +2467,12 @@ It comes with new features, but also a few breaking changes. The [GRDB 4 Migrati
|
||||
+ class DatabaseFuture<Value> { }
|
||||
|
||||
protocol FetchRequest {
|
||||
- func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
- func prepare(_ db: DatabaseBase<some SQLiteAPI>) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func prepare(_ db: DatabaseBase<some SQLiteAPI>, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
}
|
||||
|
||||
struct AnyFetchRequest<T> : FetchRequest {
|
||||
- init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?))
|
||||
- init(_ prepare: @escaping (DatabaseBase<some SQLiteAPI>) throws -> (SelectStatement, RowAdapter?))
|
||||
+ init(_ prepare: @escaping (Database, _ singleResult: Bool) throws -> (SelectStatement, RowAdapter?))
|
||||
}
|
||||
|
||||
@@ -2595,24 +2595,24 @@ This release comes with:
|
||||
}
|
||||
|
||||
extension MutablePersistableRecord {
|
||||
+ mutating func updateChanges(_ db: Database, with change: (inout Self) throws -> Void) throws -> Bool
|
||||
+ mutating func updateChanges(_ db: DatabaseBase<some SQLiteAPI>, with change: (inout Self) throws -> Void) throws -> Bool
|
||||
}
|
||||
|
||||
extension PersistableRecord {
|
||||
+ func updateChanges(_ db: Database, with change: (Self) throws -> Void) throws -> Bool
|
||||
+ func updateChanges(_ db: DatabaseBase<some SQLiteAPI>, with change: (Self) throws -> Void) throws -> Bool
|
||||
}
|
||||
|
||||
struct ValueObservation<Reducer> {
|
||||
+ static func tracking(
|
||||
+ _ regions: [DatabaseRegionConvertible],
|
||||
+ reducer: @escaping (Database) throws -> Reducer)
|
||||
+ reducer: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Reducer)
|
||||
+ -> ValueObservation
|
||||
}
|
||||
|
||||
+extension ValueObservation where Reducer == Void {
|
||||
+ static func tracking<Value>(
|
||||
+ _ regions: [DatabaseRegionConvertible],
|
||||
+ fetch: @escaping (Database) throws -> Value)
|
||||
+ fetch: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Value)
|
||||
+ -> ValueObservation<ValueReducers.Raw<Value>>
|
||||
+ static func combine<R1: ValueReducer, ...>(_ o1: ValueObservation<R1>, ...)
|
||||
+ -> ValueObservation<...>
|
||||
@@ -2697,13 +2697,13 @@ It used to be possible to define custom types that adopt the [DatabaseReader and
|
||||
}
|
||||
|
||||
+protocol DatabaseRegionConvertible {
|
||||
+ func databaseRegion(_ db: Database) throws -> DatabaseRegion
|
||||
+ func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
+}
|
||||
+
|
||||
+extension DatabaseRegion: DatabaseRegionConvertible { }
|
||||
+
|
||||
+struct AnyDatabaseRegionConvertible: DatabaseRegionConvertible {
|
||||
+ init(_ region: @escaping (Database) throws -> DatabaseRegion)
|
||||
+ init(_ region: @escaping (DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion)
|
||||
+ init(_ region: DatabaseRegionConvertible)
|
||||
+}
|
||||
|
||||
@@ -2719,7 +2719,7 @@ It used to be possible to define custom types that adopt the [DatabaseReader and
|
||||
+protocol ValueReducer {
|
||||
+ associatedtype Fetched
|
||||
+ associatedtype Value
|
||||
+ func fetch(_ db: Database) throws -> Fetched
|
||||
+ func fetch(_ db: DatabaseBase<some SQLiteAPI>) throws -> Fetched
|
||||
+ mutating func value(_ fetched: Fetched) -> Value?
|
||||
+}
|
||||
+
|
||||
@@ -2728,7 +2728,7 @@ It used to be possible to define custom types that adopt the [DatabaseReader and
|
||||
+}
|
||||
+
|
||||
+struct AnyValueReducer<Fetched, Value>: ValueReducer {
|
||||
+ init(fetch: @escaping (Database) throws -> Fetched, value: @escaping (Fetched) -> Value?)
|
||||
+ init(fetch: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Fetched, value: @escaping (Fetched) -> Value?)
|
||||
+ init<Reducer: ValueReducer>(_ reducer: Reducer) where Reducer.Fetched == Fetched, Reducer.Value == Value
|
||||
+}
|
||||
|
||||
@@ -2751,12 +2751,12 @@ It used to be possible to define custom types that adopt the [DatabaseReader and
|
||||
+extension ValueObservation where Reducer == Void {
|
||||
+ static func tracking<Value>(
|
||||
+ _ regions: DatabaseRegionConvertible...,
|
||||
+ fetch: @escaping (Database) throws -> Value)
|
||||
+ fetch: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Value)
|
||||
+ -> ValueObservation<ValueReducers.Raw<Value>>
|
||||
+
|
||||
+ static func tracking<Value>(
|
||||
+ _ regions: DatabaseRegionConvertible...,
|
||||
+ fetchDistinct: @escaping (Database) throws -> Value)
|
||||
+ fetchDistinct: @escaping (DatabaseBase<some SQLiteAPI>) throws -> Value)
|
||||
+ -> ValueObservation<ValueReducers.Distinct<Value>>
|
||||
+ where Value: Equatable
|
||||
+
|
||||
@@ -2801,7 +2801,7 @@ This release comes with **Association Aggregates**. They let you compute values
|
||||
```diff
|
||||
protocol AggregatingRequest {
|
||||
- func group(_ expressions: [SQLExpressible]) -> Self
|
||||
+ func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> Self
|
||||
+ func group(_ expressions: @escaping (DatabaseBase<some SQLiteAPI>) throws -> [SQLExpressible]) -> Self
|
||||
}
|
||||
|
||||
+extension AggregatingRequest {
|
||||
@@ -2879,7 +2879,7 @@ Released September 16, 2018 • [diff](https://github.com/groue/GRDB.swift/co
|
||||
|
||||
```diff
|
||||
protocol DatabaseWriter : DatabaseReader {
|
||||
+ func concurrentRead<T>(_ block: @escaping (Database) throws -> T) -> Future<T>
|
||||
+ func concurrentRead<T>(_ block: @escaping (DatabaseBase<some SQLiteAPI>) throws -> T) -> Future<T>
|
||||
+ @available(*, deprecated)
|
||||
func readFromCurrentState(_ block: @escaping (Database) -> Void) throws
|
||||
}
|
||||
@@ -2938,10 +2938,10 @@ Fixes:
|
||||
|
||||
```diff
|
||||
class DatabaseQueue {
|
||||
- func write<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
+ func write<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
- func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
+ func unsafeReentrantRead<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
- func write<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T {
|
||||
+ func write<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T {
|
||||
- func unsafeReentrantRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T {
|
||||
+ func unsafeReentrantRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T {
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3189,14 +3189,14 @@ Released February 25, 2018 • [diff](https://github.com/groue/GRDB.swift/com
|
||||
|
||||
extension MutablePersistable {
|
||||
+ @discardableResult
|
||||
+ func updateChanges(_ db: Database, from record: MutablePersistable) throws -> Bool
|
||||
+ func updateChanges(_ db: DatabaseBase<some SQLiteAPI>, from record: MutablePersistable) throws -> Bool
|
||||
+ func databaseEqual(_ record: Self) -> Bool
|
||||
+ func databaseChanges(from record: MutablePersistable) -> [String: DatabaseValue]
|
||||
}
|
||||
class Record {
|
||||
- final func updateChanges(_ db: Database) throws
|
||||
- final func updateChanges(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ @discardableResult
|
||||
+ final func updateChanges(_ db: Database) throws -> Bool
|
||||
+ final func updateChanges(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
}
|
||||
|
||||
+@available(*, deprecated, message: "Prefer changes methods defined on the MutablePersistable protocol: databaseEqual(_:), databaseChanges(from:), updateChanges(from:)")
|
||||
@@ -3212,7 +3212,7 @@ Released February 25, 2018 • [diff](https://github.com/groue/GRDB.swift/com
|
||||
|
||||
extension TableMapping {
|
||||
+ static func selectionSQL(alias: String? = nil) -> String
|
||||
+ static func numberOfSelectedColumns(_ db: Database) throws -> Int
|
||||
+ static func numberOfSelectedColumns(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
}
|
||||
|
||||
+struct EmptyRowAdapter: RowAdapter { }
|
||||
@@ -3335,7 +3335,7 @@ Released January 18, 2018 • [diff](https://github.com/groue/GRDB.swift/comp
|
||||
|
||||
protocol Request {
|
||||
+ // Default implementation
|
||||
+ func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
+ func fetchedRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
}
|
||||
|
||||
+extension Row: RandomAccessCollection {
|
||||
@@ -3402,8 +3402,8 @@ Released January 11, 2018 • [diff](https://github.com/groue/GRDB.swift/comp
|
||||
}
|
||||
|
||||
extension RowConvertible where Self: TableMapping {
|
||||
- static func fetchOne(_ db: Database, key: [String: DatabaseValueConvertible?]) throws -> Self?
|
||||
+ static func fetchOne(_ db: Database, key: [String: DatabaseValueConvertible?]?) throws -> Self?
|
||||
- static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, key: [String: DatabaseValueConvertible?]) throws -> Self?
|
||||
+ static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, key: [String: DatabaseValueConvertible?]?) throws -> Self?
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3533,7 +3533,7 @@ Released October 24, 2017 • [diff](https://github.com/groue/GRDB.swift/comp
|
||||
|
||||
```diff
|
||||
extension Request {
|
||||
+ func asSQLRequest(_ db: Database, cached: Bool = false) throws -> SQLRequest
|
||||
+ func asSQLRequest(_ db: DatabaseBase<some SQLiteAPI>, cached: Bool = false) throws -> SQLRequest
|
||||
}
|
||||
struct SQLRequest {
|
||||
+ let sql: String
|
||||
@@ -3784,15 +3784,15 @@ New features have been added in order to plug a few holes and support the [RxGRD
|
||||
|
||||
-extension TableMapping {
|
||||
+extension MutablePersistable {
|
||||
@discardableResult static func deleteAll(_ db: Database) throws -> Int
|
||||
@discardableResult static func deleteAll<Sequence: Swift.Sequence>(_ db: Database, keys: Sequence) throws -> Int where Sequence.Element: DatabaseValueConvertible
|
||||
@discardableResult static func deleteOne<PrimaryKeyType: DatabaseValueConvertible>(_ db: Database, key: PrimaryKeyType?) throws -> Bool
|
||||
@discardableResult static func deleteAll(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) throws -> Int
|
||||
@discardableResult static func deleteOne(_ db: Database, key: [String: DatabaseValueConvertible?]) throws -> Bool
|
||||
@discardableResult static func deleteAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
@discardableResult static func deleteAll<Sequence: Swift.Sequence>(_ db: DatabaseBase<some SQLiteAPI>, keys: Sequence) throws -> Int where Sequence.Element: DatabaseValueConvertible
|
||||
@discardableResult static func deleteOne<PrimaryKeyType: DatabaseValueConvertible>(_ db: DatabaseBase<some SQLiteAPI>, key: PrimaryKeyType?) throws -> Bool
|
||||
@discardableResult static func deleteAll(_ db: DatabaseBase<some SQLiteAPI>, keys: [[String: DatabaseValueConvertible?]]) throws -> Int
|
||||
@discardableResult static func deleteOne(_ db: DatabaseBase<some SQLiteAPI>, key: [String: DatabaseValueConvertible?]) throws -> Bool
|
||||
}
|
||||
-extension QueryInterfaceRequest {
|
||||
+extension QueryInterfaceRequest where RowDecoder: MutablePersistable {
|
||||
@discardableResult func deleteAll(_ db: Database) throws -> Int
|
||||
@discardableResult func deleteAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
}
|
||||
|
||||
protocol TableMapping {
|
||||
@@ -3862,30 +3862,30 @@ New features have been added in order to plug a few holes and support the [RxGRD
|
||||
+ static func fetchCursor(...) throws -> RecordCursor<Self>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: RowConvertible {
|
||||
- func fetchCursor(_ db: Database) throws -> DatabaseCursor<RowDecoder>
|
||||
+ func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder>
|
||||
- func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseCursor<RowDecoder>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> RecordCursor<RowDecoder>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: DatabaseValueConvertible {
|
||||
- func fetchCursor(_ db: Database) throws -> DatabaseCursor<RowDecoder>
|
||||
+ func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder>
|
||||
- func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseCursor<RowDecoder>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseValueCursor<RowDecoder>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
+ func fetchCursor(_ db: Database) throws -> ColumnCursor<RowDecoder>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> ColumnCursor<RowDecoder>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible {
|
||||
- func fetchCursor(_ db: Database) throws -> DatabaseCursor<RowDecoder._Wrapped?>
|
||||
+ func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped>
|
||||
- func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseCursor<RowDecoder._Wrapped?>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
+ func fetchCursor(_ db: Database) throws -> NullableColumnCursor<RowDecoder._Wrapped>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> NullableColumnCursor<RowDecoder._Wrapped>
|
||||
}
|
||||
extension TypedRequest where RowDecoder: Row {
|
||||
- func fetchCursor(_ db: Database) throws -> DatabaseCursor<Row>
|
||||
+ func fetchCursor(_ db: Database) throws -> RowCursor
|
||||
- func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseCursor<Row>
|
||||
+ func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowCursor
|
||||
}
|
||||
|
||||
extension TableMapping {
|
||||
- @available(*, deprecated) static func primaryKeyRowComparator(_ db: Database) throws -> (Row, Row) -> Bool
|
||||
- @available(*, deprecated) static func primaryKeyRowComparator(_ db: DatabaseBase<some SQLiteAPI>) throws -> (Row, Row) -> Bool
|
||||
}
|
||||
|
||||
+final class AnyDatabaseReader : DatabaseReader {
|
||||
@@ -4048,7 +4048,7 @@ Released July 13, 2017 • [diff](https://github.com/groue/GRDB.swift/compare
|
||||
}
|
||||
|
||||
protocol DatabaseReader {
|
||||
+ func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T
|
||||
+ func unsafeReentrantRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4110,7 +4110,7 @@ Released July 1, 2017 • [diff](https://github.com/groue/GRDB.swift/compare/
|
||||
|
||||
extension TableMapping {
|
||||
+ @available(*, deprecated)
|
||||
static func primaryKeyRowComparator(_ db: Database) throws -> (Row, Row) -> Bool
|
||||
static func primaryKeyRowComparator(_ db: DatabaseBase<some SQLiteAPI>) throws -> (Row, Row) -> Bool
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4235,8 +4235,8 @@ It comes with breaking changes, but the good news is that they are the last (unt
|
||||
}
|
||||
|
||||
extension Request {
|
||||
- func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AnyRequest
|
||||
+ func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedRequest<Self>
|
||||
- func adapted(_ adapter: @escaping (DatabaseBase<some SQLiteAPI>) throws -> RowAdapter) -> AnyRequest
|
||||
+ func adapted(_ adapter: @escaping (DatabaseBase<some SQLiteAPI>) throws -> RowAdapter) -> AdaptedRequest<Self>
|
||||
}
|
||||
|
||||
protocol TypedRequest : Request {
|
||||
@@ -4245,8 +4245,8 @@ protocol TypedRequest : Request {
|
||||
}
|
||||
|
||||
extension TypedRequest {
|
||||
- func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AnyTypedRequest<Fetched>
|
||||
+ func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedTypedRequest<Self>
|
||||
- func adapted(_ adapter: @escaping (DatabaseBase<some SQLiteAPI>) throws -> RowAdapter) -> AnyTypedRequest<Fetched>
|
||||
+ func adapted(_ adapter: @escaping (DatabaseBase<some SQLiteAPI>) throws -> RowAdapter) -> AdaptedTypedRequest<Self>
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4366,7 +4366,7 @@ Released April 3, 2017
|
||||
- Support for [reactive](https://reactivex.io) extensions:
|
||||
- `SelectStatement.SelectionInfo` is an opaque value that knows which database tables and columns are read by a [select statement](https://github.com/groue/GRDB.swift#prepared-statements).
|
||||
- `DatabaseEventKind.impacts(_ selectionInfo:SelectStatement.SelectionInfo)` tells whether a database change has any impact on the results of a select statement. See [Database Changes Observation](https://github.com/groue/GRDB.swift#database-changes-observation)
|
||||
- `TableMapping.primaryKeyRowComparator(_ db: Database)` returns a function that compares two database rows and return true if and only if they have the same non-null primary key.
|
||||
- `TableMapping.primaryKeyRowComparator(_ db: DatabaseBase<some SQLiteAPI>)` returns a function that compares two database rows and return true if and only if they have the same non-null primary key.
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
@@ -4684,19 +4684,19 @@ Many APIs were changed:
|
||||
}
|
||||
|
||||
final class DatabasePool {
|
||||
- func read<T>(_ block: (Database) throws -> T) rethrows -> T
|
||||
- func nonIsolatedRead<T>(_ block: (Database) throws -> T) rethrows -> T
|
||||
- func read<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T
|
||||
- func nonIsolatedRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T
|
||||
- func readFromWrite(_ block: @escaping (Database) -> Void)
|
||||
+ func read<T>(_ block: (Database) throws -> T) throws -> T
|
||||
+ func nonIsolatedRead<T>(_ block: (Database) throws -> T) throws -> T
|
||||
+ func read<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T
|
||||
+ func nonIsolatedRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T
|
||||
+ func readFromWrite(_ block: @escaping (Database) -> Void) throws
|
||||
}
|
||||
|
||||
protocol DatabaseReader {
|
||||
- func read<T>(_ block: (Database) throws -> T) rethrows -> T
|
||||
- func nonIsolatedRead<T>(_ block: (Database) throws -> T) rethrows -> T
|
||||
+ func read<T>(_ block: (Database) throws -> T) throws -> T
|
||||
+ func nonIsolatedRead<T>(_ block: (Database) throws -> T) throws -> T
|
||||
- func read<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T
|
||||
- func nonIsolatedRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T
|
||||
+ func read<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T
|
||||
+ func nonIsolatedRead<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T
|
||||
}
|
||||
|
||||
protocol DatabaseWriter {
|
||||
@@ -4747,13 +4747,13 @@ Many APIs were changed:
|
||||
}
|
||||
|
||||
protocol MutablePersistable : TableMapping {
|
||||
- func exists(_ db: Database) -> Bool
|
||||
+ func exists(_ db: Database) throws -> Bool
|
||||
- func exists(_ db: DatabaseBase<some SQLiteAPI>) -> Bool
|
||||
+ func exists(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
}
|
||||
|
||||
extension MutablePersistable {
|
||||
- func performExists(_ db: Database) -> Bool
|
||||
+ func performExists(_ db: Database) throws -> Bool
|
||||
- func performExists(_ db: DatabaseBase<some SQLiteAPI>) -> Bool
|
||||
+ func performExists(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest {
|
||||
@@ -4780,8 +4780,8 @@ Many APIs were changed:
|
||||
}
|
||||
|
||||
extension TableMapping {
|
||||
- static func fetchCount(_ db: Database) -> Int
|
||||
+ static func fetchCount(_ db: Database) throws -> Int
|
||||
- static func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) -> Int
|
||||
+ static func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4959,7 +4959,7 @@ Released October 16, 2016
|
||||
protocol VirtualTableModule {
|
||||
- func moduleArguments(_ definition: TableDefinition) -> [String]
|
||||
+ func moduleArguments(for definition: TableDefinition, in db: Database) throws -> [String]
|
||||
+ func database(_ db: Database, didCreate tableName: String, using definition: TableDefinition) throws
|
||||
+ func database(_ db: DatabaseBase<some SQLiteAPI>, didCreate tableName: String, using definition: TableDefinition) throws
|
||||
}
|
||||
```
|
||||
|
||||
@@ -5032,7 +5032,7 @@ Released September 28, 2016
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- The SQLForeignKeyAction, SQLColumnType, SQLConflictResolution, and SQLCollation types have been renamed Database.ForeignKeyAction, Database.ColumnType, Database.ConflictResolution, and Database.CollationName.
|
||||
- The SQLForeignKeyAction, SQLColumnType, SQLConflictResolution, and SQLCollation types have been renamed Database.ForeignKeyAction, Database.ColumnType, DatabaseConflictResolution, and Database.CollationName.
|
||||
|
||||
|
||||
## 0.84.0
|
||||
@@ -5295,8 +5295,8 @@ Released September 11, 2016
|
||||
- func databaseDidRollback(db: Database)
|
||||
+ func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool
|
||||
+ func databaseDidChange(with event: DatabaseEvent)
|
||||
+ func databaseDidCommit(_ db: Database)
|
||||
+ func databaseDidRollback(_ db: Database)
|
||||
+ func databaseDidCommit(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
+ func databaseDidRollback(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
- func databaseWillChangeWithEvent(event: DatabasePreUpdateEvent)
|
||||
+ func databaseWillChange(with event: DatabasePreUpdateEvent)
|
||||
@@ -5319,19 +5319,19 @@ Released September 11, 2016
|
||||
- func delete(db: Database) throws -> Bool
|
||||
- func exists(db: Database) -> Bool
|
||||
+ mutating func didInsert(with rowID: Int64, for column: String?)
|
||||
+ mutating func insert(_ db: Database) throws
|
||||
+ func update(_ db: Database, columns: Set<String>) throws
|
||||
+ mutating func save(_ db: Database) throws
|
||||
+ @discardableResult func delete(_ db: Database) throws -> Bool
|
||||
+ func exists(_ db: Database) -> Bool
|
||||
+ mutating func insert(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ func update(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws
|
||||
+ mutating func save(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ @discardableResult func delete(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
+ func exists(_ db: DatabaseBase<some SQLiteAPI>) -> Bool
|
||||
}
|
||||
protocol Persistable : MutablePersistable {
|
||||
- func didInsertWithRowID(rowID: Int64, forColumn column: String?)
|
||||
- func insert(db: Database) throws
|
||||
- func save(db: Database) throws
|
||||
+ func didInsert(with rowID: Int64, for column: String?)
|
||||
+ func insert(_ db: Database) throws
|
||||
+ func save(_ db: Database) throws
|
||||
+ func insert(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ func save(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
}
|
||||
protocol TableMapping {
|
||||
- static func databaseTableName() -> String
|
||||
@@ -5351,10 +5351,10 @@ Released September 11, 2016
|
||||
+ class var databaseTableName: String
|
||||
+ func awakeFromFetch(row: Row)
|
||||
+ func didInsert(with rowID: Int64, for column: String?)
|
||||
+ func update(_ db: Database, columns: Set<String>) throws
|
||||
+ func insert(_ db: Database) throws
|
||||
+ func save(_ db: Database) throws
|
||||
+ @discardableResult func delete(_ db: Database) throws -> Bool
|
||||
+ func update(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws
|
||||
+ func insert(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ func save(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
+ @discardableResult func delete(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
}
|
||||
```
|
||||
|
||||
@@ -5363,7 +5363,7 @@ Released September 11, 2016
|
||||
```diff
|
||||
protocol FetchRequest {
|
||||
- func prepare(db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func prepare(_ db: DatabaseBase<some SQLiteAPI>) throws -> (SelectStatement, RowAdapter?)
|
||||
}
|
||||
-struct SQLColumn {}
|
||||
+struct Column {}
|
||||
@@ -5943,10 +5943,10 @@ Released May 17, 2016
|
||||
|
||||
```diff
|
||||
struct DatabaseMigrator {
|
||||
- mutating func registerMigration(identifier: String, withDisabledForeignKeyChecks disabledForeignKeyChecks: Bool = false, migrate: (Database) throws -> Void)
|
||||
+ mutating func registerMigration(identifier: String, migrate: (Database) throws -> Void)
|
||||
- mutating func registerMigration(identifier: String, withDisabledForeignKeyChecks disabledForeignKeyChecks: Bool = false, migrate: (DatabaseBase<some SQLiteAPI>) throws -> Void)
|
||||
+ mutating func registerMigration(identifier: String, migrate: (DatabaseBase<some SQLiteAPI>) throws -> Void)
|
||||
+ @available(iOS 8.2, OSX 10.10, *)
|
||||
+ mutating func registerMigrationWithDisabledForeignKeyChecks(identifier: String, migrate: (Database) throws -> Void)
|
||||
+ mutating func registerMigrationWithDisabledForeignKeyChecks(identifier: String, migrate: (DatabaseBase<some SQLiteAPI>) throws -> Void)
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ extension AppDatabase {
|
||||
}
|
||||
|
||||
/// Support for `createRandomPlayersIfEmpty()` and `refreshPlayers()`.
|
||||
private func createRandomPlayers(_ db: Database) throws {
|
||||
private func createRandomPlayers(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
for _ in 0..<8 {
|
||||
_ = try Player.makeRandom().inserted(db) // insert but ignore inserted id
|
||||
}
|
||||
|
||||
@@ -178,12 +178,12 @@ The record protocols have been refactored. We tried to keep the amount of modifi
|
||||
|
||||
```swift
|
||||
// GRDB 6: remove those methods from your code
|
||||
func insert(_ db: Database) throws
|
||||
func insert(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
func didInsert(with rowID: Int64, for column: String?)
|
||||
func update(_ db: Database, columns: Set<String>) throws
|
||||
func save(_ db: Database) throws
|
||||
func delete(_ db: Database) throws -> Bool
|
||||
func exists(_ db: Database) throws -> Bool
|
||||
func update(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws
|
||||
func save(_ db: DatabaseBase<some SQLiteAPI>) throws
|
||||
func delete(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
func exists(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool
|
||||
```
|
||||
|
||||
- `insert(_:)`: customization is now made with [persistence callbacks].
|
||||
@@ -204,12 +204,12 @@ The record protocols have been refactored. We tried to keep the amount of modifi
|
||||
struct Link: PersistableRecord {
|
||||
var url: URL
|
||||
|
||||
func insert(_ db: Database) throws {
|
||||
func insert(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try validate()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(_ db: Database, columns: Set<String>) throws {
|
||||
func update(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws {
|
||||
try validate()
|
||||
try performUpdate(db, columns: columns)
|
||||
}
|
||||
@@ -229,7 +229,7 @@ The record protocols have been refactored. We tried to keep the amount of modifi
|
||||
struct Link: PersistableRecord {
|
||||
var url: URL
|
||||
|
||||
func willSave(_ db: Database) throws {
|
||||
func willSave(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
if url.host == nil {
|
||||
throw ValidationError("url must be absolute.")
|
||||
}
|
||||
@@ -249,7 +249,7 @@ The record protocols have been refactored. We tried to keep the amount of modifi
|
||||
class Link: Record {
|
||||
var url: URL
|
||||
|
||||
override func willSave(_ db: Database) throws {
|
||||
override func willSave(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try super.willSave(db)
|
||||
if url.host == nil {
|
||||
throw ValidationError("url must be absolute.")
|
||||
|
||||
@@ -40,12 +40,12 @@ class TableChangeObserver : NSObject, TransactionObserver {
|
||||
changedTableNames.insert(event.tableName)
|
||||
}
|
||||
|
||||
func databaseDidCommit(_ db: Database) {
|
||||
func databaseDidCommit(_ db: DatabaseBase<some SQLiteAPI>) {
|
||||
print("Changed table(s): \(changedTableNames.joined(separator: ", "))")
|
||||
changedTableNames = []
|
||||
}
|
||||
|
||||
func databaseDidRollback(_ db: Database) {
|
||||
func databaseDidRollback(_ db: DatabaseBase<some SQLiteAPI>) {
|
||||
changedTableNames = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ Columns are special expressions that allow some optimizations and niceties:
|
||||
|
||||
```swift
|
||||
protocol DatabaseRegionConvertible {
|
||||
func databaseRegion(_ db: Database) throws -> DatabaseRegion
|
||||
func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
}
|
||||
```
|
||||
|
||||
@@ -207,10 +207,10 @@ protocol FetchRequest<RowDecoder>: SQLSubqueryable, DatabaseRegionConvertible {
|
||||
associatedtype RowDecoder
|
||||
|
||||
/// Returns a PreparedRequest that is ready to be executed.
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
func makePreparedRequest(_ db: DatabaseBase<some SQLiteAPI>, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
|
||||
/// Returns the number of rows fetched by the request.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ Let's extend Player with database methods.
|
||||
```swift
|
||||
extension Player {
|
||||
/// Deletes all player with no score
|
||||
static func deleteAllWithoutScore(_ db: Database) throws {
|
||||
static func deleteAllWithoutScore(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try db.execute(literal: "DELETE FROM \(self) WHERE \(CodingKeys.score) IS NULL")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
#if !canImport(Darwin)
|
||||
@preconcurrency
|
||||
@@ -201,7 +201,7 @@ public struct Configuration: Sendable {
|
||||
|
||||
// MARK: - Managing SQLite Connections
|
||||
|
||||
private var setups: [@Sendable (Database) throws -> Void] = []
|
||||
private var setups: [@Sendable (DatabaseBase<some SQLiteAPI>) throws -> Void] = []
|
||||
|
||||
/// Defines a function to run whenever an SQLite connection is opened.
|
||||
///
|
||||
@@ -238,7 +238,7 @@ public struct Configuration: Sendable {
|
||||
///
|
||||
/// On newly created databases files, ``DatabasePool`` activates the WAL
|
||||
/// mode after the preparation functions have run.
|
||||
public mutating func prepareDatabase(_ setup: @escaping @Sendable (Database) throws -> Void) {
|
||||
public mutating func prepareDatabase(_ setup: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> Void) {
|
||||
setups.append(setup)
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ public struct Configuration: Sendable {
|
||||
return threadingMode.SQLiteOpenFlags | flags
|
||||
}
|
||||
|
||||
func setUp(_ db: Database) throws {
|
||||
func setUp(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
for f in setups {
|
||||
try f(db)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// A cache for the available database schemas.
|
||||
struct SchemaCache {
|
||||
/// The available schema identifiers, in the order of SQLite resolution:
|
||||
@@ -966,7 +966,7 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
/// Returns the columns in a table or a view.
|
||||
///
|
||||
@@ -1485,7 +1485,7 @@ public struct ForeignKeyViolation: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// See also ``description``.
|
||||
public func failureDescription(_ db: Database) throws -> String {
|
||||
public func failureDescription(_ db: DatabaseBase<some SQLiteAPI>) throws -> String {
|
||||
// Grab detailed information, if possible, for better error message
|
||||
let originRow = try originRowID.flatMap { rowid in
|
||||
try Row.fetchOne(db, sql: "SELECT * FROM \(originTable.quotedDatabaseIdentifier) WHERE rowid = \(rowid)")
|
||||
@@ -1517,7 +1517,7 @@ public struct ForeignKeyViolation: Sendable {
|
||||
/// Converts the violation into a ``DatabaseError``.
|
||||
///
|
||||
/// The returned error has the extended code `SQLITE_CONSTRAINT_FOREIGNKEY`.
|
||||
public func databaseError(_ db: Database) -> DatabaseError {
|
||||
public func databaseError(_ db: DatabaseBase<some SQLiteAPI>) -> DatabaseError {
|
||||
// Grab detailed information, if possible, for better error message.
|
||||
// If detailed information is not available, fallback to plain description.
|
||||
let message = (try? failureDescription(db)) ?? String(describing: self)
|
||||
@@ -1840,7 +1840,7 @@ struct SchemaInfo: Equatable {
|
||||
|
||||
extension SchemaInfo {
|
||||
/// - parameter schemaTableName: "sqlite_master" or "sqlite_temp_master"
|
||||
init(_ db: Database, schemaTableName: String) throws {
|
||||
init(_ db: DatabaseBase<some SQLiteAPI>, schemaTableName: String) throws {
|
||||
objects = try SchemaObject.fetchSet(db, sql: """
|
||||
SELECT type, name, tbl_name, sql FROM \(schemaTableName)
|
||||
""")
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Statements
|
||||
|
||||
@@ -434,10 +434,10 @@ extension SQLStatementCursor: Cursor {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Makes sure statement can be executed, and prepares database observation.
|
||||
@usableFromInline
|
||||
func statementWillExecute(_ statement: Statement) throws {
|
||||
func statementWillExecute(_ statement: StatementBase<API>) throws {
|
||||
// Aborted transactions prevent statement execution (see the
|
||||
// documentation of this method for more information).
|
||||
try checkForAbortedTransaction(sql: statement.sql, arguments: statement.arguments)
|
||||
@@ -458,7 +458,7 @@ extension Database {
|
||||
/// May throw a cancelled commit error, if a transaction observer cancels
|
||||
/// an empty transaction.
|
||||
@usableFromInline
|
||||
func statementDidExecute(_ statement: Statement) throws {
|
||||
func statementDidExecute(_ statement: StatementBase<API>) throws {
|
||||
if statement.invalidatesDatabaseSchemaCache {
|
||||
clearSchemaCache()
|
||||
}
|
||||
@@ -471,7 +471,7 @@ extension Database {
|
||||
|
||||
/// Always throws an error
|
||||
@usableFromInline
|
||||
func statementDidFail(_ statement: Statement, withResultCode resultCode: CInt) throws -> Never {
|
||||
func statementDidFail(_ statement: StatementBase<API>, withResultCode resultCode: CInt) throws -> Never {
|
||||
// Failed statements can not be reused, because `sqlite3_reset` won't
|
||||
// be able to restore the statement to its initial state:
|
||||
// https://www.sqlite.org/c3ref/reset.html
|
||||
@@ -534,15 +534,15 @@ extension Database {
|
||||
}
|
||||
|
||||
/// A thread-unsafe statement cache
|
||||
struct StatementCache {
|
||||
unowned let db: Database
|
||||
private var statements: [String: Statement] = [:]
|
||||
struct StatementCache<API: SQLiteAPI> {
|
||||
unowned let db: DatabaseBase<API>
|
||||
private var statements: [String: StatementBase<API>] = [:]
|
||||
|
||||
init(database: Database) {
|
||||
init(database: DatabaseBase<API>) {
|
||||
self.db = database
|
||||
}
|
||||
|
||||
mutating func statement(_ sql: String) throws -> Statement {
|
||||
mutating func statement(_ sql: String) throws -> StatementBase<API> {
|
||||
if let statement = statements[sql] {
|
||||
return statement
|
||||
}
|
||||
@@ -562,11 +562,11 @@ struct StatementCache {
|
||||
statements = [:]
|
||||
}
|
||||
|
||||
mutating func remove(_ statement: Statement) {
|
||||
mutating func remove(_ statement: StatementBase<API>) {
|
||||
statements.removeFirst { $0.value === statement }
|
||||
}
|
||||
|
||||
mutating func removeAll(where shouldBeRemoved: (Statement) -> Bool) {
|
||||
mutating func removeAll(where shouldBeRemoved: (StatementBase<API>) -> Bool) {
|
||||
statements = statements.filter { (_, statement) in !shouldBeRemoved(statement) }
|
||||
}
|
||||
}
|
||||
+92
-62
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -142,7 +142,7 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
|
||||
/// - ``StorageClass``
|
||||
/// - ``TraceEvent``
|
||||
/// - ``TracingOptions``
|
||||
public final class Database: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
public final class DatabaseBase<API: SQLiteAPI>: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
// The Database class is not thread-safe. An instance should always be
|
||||
// used through a SerializedDatabase.
|
||||
|
||||
@@ -315,7 +315,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
///
|
||||
/// It is nil in read-only connections, because we do not report read-only
|
||||
/// transactions to transaction observers.
|
||||
private(set) var observationBroker: DatabaseObservationBroker?
|
||||
private(set) var observationBroker: DatabaseObservationBroker<API>?
|
||||
|
||||
/// The list of compile options used when building SQLite
|
||||
static func sqliteCompileOptions() throws -> Set<String> {
|
||||
@@ -1491,7 +1491,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
/// either ``TransactionCompletion/commit`` or ``TransactionCompletion/rollback``.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or the
|
||||
/// error thrown by `operations`.
|
||||
public func inTransaction(_ kind: TransactionKind? = nil, _ operations: () throws -> TransactionCompletion) throws {
|
||||
public func inTransaction(_ kind: DatabaseTransactionKind? = nil, _ operations: () throws -> DatabaseTransactionCompletion) throws {
|
||||
// Begin transaction
|
||||
try beginTransaction(kind)
|
||||
|
||||
@@ -1703,7 +1703,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
/// If nil, the transaction kind is DEFERRED when the current
|
||||
/// database access is read-only, and IMMEDIATE otherwise.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func beginTransaction(_ kind: TransactionKind? = nil) throws {
|
||||
public func beginTransaction(_ kind: DatabaseTransactionKind? = nil) throws {
|
||||
// SQLite throws an error for non-deferred transactions when read-only.
|
||||
// We prefer immediate transactions for writes, so that write
|
||||
// transactions can not overlap. This reduces the opportunity for
|
||||
@@ -1945,10 +1945,10 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
// Explicit non-conformance to Sendable: `Database` must be used from a
|
||||
// serialized database access dispatch queue (see `SerializedDatabase`).
|
||||
@available(*, unavailable)
|
||||
extension Database: Sendable { }
|
||||
extension DatabaseBase: Sendable { }
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Encryption
|
||||
|
||||
@@ -2021,7 +2021,7 @@ extension Database {
|
||||
}
|
||||
#endif
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Returns the count of changes executed by one statement execution.
|
||||
func countChanges<T>(_ count: inout Int, forTable tableName: String, updates: () throws -> T) throws -> T {
|
||||
// Database.changesCount calls sqlite3_changes(), whose documentation says:
|
||||
@@ -2049,7 +2049,7 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Database-Related Types
|
||||
|
||||
@@ -2207,26 +2207,6 @@ extension Database {
|
||||
public static let any = ColumnType(rawValue: "ANY")
|
||||
}
|
||||
|
||||
/// An SQLite conflict resolution.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_conflict.html>
|
||||
public enum ConflictResolution: String, Sendable {
|
||||
/// The `ROLLBACK` conflict resolution.
|
||||
case rollback = "ROLLBACK"
|
||||
|
||||
/// The `ABORT` conflict resolution.
|
||||
case abort = "ABORT"
|
||||
|
||||
/// The `FAIL` conflict resolution.
|
||||
case fail = "FAIL"
|
||||
|
||||
/// The `IGNORE` conflict resolution.
|
||||
case ignore = "IGNORE"
|
||||
|
||||
/// The `REPLACE` conflict resolution.
|
||||
case replace = "REPLACE"
|
||||
}
|
||||
|
||||
/// A foreign key action.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/foreignkeys.html>
|
||||
@@ -2413,29 +2393,6 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
/// A transaction commit, or rollback.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_transaction.html>.
|
||||
@frozen
|
||||
public enum TransactionCompletion: Sendable {
|
||||
case commit
|
||||
case rollback
|
||||
}
|
||||
|
||||
/// A transaction kind.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_transaction.html>.
|
||||
public enum TransactionKind: String, Sendable {
|
||||
/// The `DEFERRED` transaction kind.
|
||||
case deferred = "DEFERRED"
|
||||
|
||||
/// The `IMMEDIATE` transaction kind.
|
||||
case immediate = "IMMEDIATE"
|
||||
|
||||
/// The `EXCLUSIVE` transaction kind.
|
||||
case exclusive = "EXCLUSIVE"
|
||||
}
|
||||
|
||||
/// An SQLite threading mode. See <https://www.sqlite.org/threadsafe.html>.
|
||||
///
|
||||
/// - Note: Only the multi-thread mode (`SQLITE_OPEN_NOMUTEX`) is currently
|
||||
@@ -2459,6 +2416,79 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
#warning("TODO: export as DatabaseConflictResolution")
|
||||
/// An SQLite conflict resolution.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_conflict.html>
|
||||
public enum DatabaseConflictResolution: String, Sendable {
|
||||
/// The `ROLLBACK` conflict resolution.
|
||||
case rollback = "ROLLBACK"
|
||||
|
||||
/// The `ABORT` conflict resolution.
|
||||
case abort = "ABORT"
|
||||
|
||||
/// The `FAIL` conflict resolution.
|
||||
case fail = "FAIL"
|
||||
|
||||
/// The `IGNORE` conflict resolution.
|
||||
case ignore = "IGNORE"
|
||||
|
||||
/// The `REPLACE` conflict resolution.
|
||||
case replace = "REPLACE"
|
||||
}
|
||||
|
||||
#warning("TODO: export as Database.StorageClass")
|
||||
/// An SQLite storage class.
|
||||
///
|
||||
/// For more information, see
|
||||
/// [Datatypes In SQLite](https://www.sqlite.org/datatype3.html).
|
||||
public struct DatabaseStorageClass: RawRepresentable, Hashable, Sendable {
|
||||
/// The SQL for the storage class (`"INTEGER"`, `"REAL"`, etc.)
|
||||
public let rawValue: String
|
||||
|
||||
/// Creates an SQL storage class.
|
||||
public init(rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
/// The `INTEGER` storage class.
|
||||
public static let integer = StorageClass(rawValue: "INTEGER")
|
||||
|
||||
/// The `REAL` storage class.
|
||||
public static let real = StorageClass(rawValue: "REAL")
|
||||
|
||||
/// The `TEXT` storage class.
|
||||
public static let text = StorageClass(rawValue: "TEXT")
|
||||
|
||||
/// The `BLOB` storage class.
|
||||
public static let blob = StorageClass(rawValue: "BLOB")
|
||||
}
|
||||
|
||||
#warning("TODO: export as Database.TransactionCompletion")
|
||||
/// A transaction commit, or rollback.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_transaction.html>.
|
||||
@frozen
|
||||
public enum DatabaseTransactionCompletion: Sendable {
|
||||
case commit
|
||||
case rollback
|
||||
}
|
||||
|
||||
#warning("TODO: export as Database.TransactionKind")
|
||||
/// A transaction kind.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_transaction.html>.
|
||||
public enum DatabaseTransactionKind: String, Sendable {
|
||||
/// The `DEFERRED` transaction kind.
|
||||
case deferred = "DEFERRED"
|
||||
|
||||
/// The `IMMEDIATE` transaction kind.
|
||||
case immediate = "IMMEDIATE"
|
||||
|
||||
/// The `EXCLUSIVE` transaction kind.
|
||||
case exclusive = "EXCLUSIVE"
|
||||
}
|
||||
|
||||
// Explicit non-conformance to Sendable: a trace event contains transient
|
||||
// information.
|
||||
@available(*, unavailable)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A custom SQL function or aggregate.
|
||||
///
|
||||
@@ -237,7 +237,7 @@ public final class DatabaseFunction: Identifiable, Sendable {
|
||||
|
||||
/// Calls sqlite3_create_function_v2
|
||||
/// See <https://sqlite.org/c3ref/create_function.html>
|
||||
func install(in db: Database) {
|
||||
func install(in db: DatabaseBase<some SQLiteAPI>) {
|
||||
// Retain the function definition
|
||||
let definition = kind.definition
|
||||
let definitionP = Unmanaged.passRetained(definition).toOpaque()
|
||||
@@ -264,7 +264,7 @@ public final class DatabaseFunction: Identifiable, Sendable {
|
||||
|
||||
/// Calls sqlite3_create_function_v2
|
||||
/// See <https://sqlite.org/c3ref/create_function.html>
|
||||
func uninstall(in db: Database) {
|
||||
func uninstall(in db: DatabaseBase<some SQLiteAPI>) {
|
||||
let code = sqlite3_create_function_v2(
|
||||
db.sqliteConnection,
|
||||
id.name,
|
||||
|
||||
@@ -4,8 +4,8 @@ import Foundation
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
public final class DatabasePool {
|
||||
private let writer: SerializedDatabase
|
||||
public final class DatabasePoolBase<API: SQLiteAPI> {
|
||||
private let writer: SerializedDatabase<API>
|
||||
|
||||
/// The pool of reader connections.
|
||||
/// It is constant, until close() sets it to nil.
|
||||
@@ -143,9 +143,9 @@ public final class DatabasePool {
|
||||
}
|
||||
|
||||
// @unchecked because of readerPool and suspensionObservers
|
||||
extension DatabasePool: @unchecked Sendable { }
|
||||
extension DatabasePoolBase: @unchecked Sendable { }
|
||||
|
||||
extension DatabasePool {
|
||||
extension DatabasePoolBase {
|
||||
|
||||
// MARK: - Memory management
|
||||
|
||||
@@ -263,7 +263,7 @@ extension DatabasePool {
|
||||
#endif
|
||||
}
|
||||
|
||||
extension DatabasePool: DatabaseReader {
|
||||
extension DatabasePoolBase: DatabaseReaderBase {
|
||||
|
||||
public func close() throws {
|
||||
try readerPool?.barrier {
|
||||
@@ -336,7 +336,7 @@ extension DatabasePool: DatabaseReader {
|
||||
// MARK: - Reading from Database
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
GRDBPrecondition(currentReader == nil, "Database methods are not reentrant.")
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -352,7 +352,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -379,7 +379,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
guard let readerPool else {
|
||||
value(.failure(DatabaseError.connectionIsClosed()))
|
||||
@@ -418,7 +418,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
GRDBPrecondition(currentReader == nil, "Database methods are not reentrant.")
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -432,7 +432,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -447,7 +447,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
guard let readerPool else {
|
||||
value(.failure(DatabaseError.connectionIsClosed()))
|
||||
@@ -475,7 +475,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
if let reader = currentReader {
|
||||
return try reader.reentrantSync(value)
|
||||
} else if writer.onValidQueue {
|
||||
@@ -494,7 +494,7 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func spawnConcurrentRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
asyncConcurrentRead(value)
|
||||
}
|
||||
@@ -537,7 +537,7 @@ extension DatabasePool: DatabaseReader {
|
||||
///
|
||||
/// - parameter value: A function that accesses the database.
|
||||
public func asyncConcurrentRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
// Check that we're on the writer queue...
|
||||
writer.execute { db in
|
||||
@@ -686,13 +686,13 @@ extension DatabasePool: DatabaseReader {
|
||||
|
||||
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
|
||||
/// Returns a long-lived WAL snapshot transaction on a reader connection.
|
||||
func walSnapshotTransaction() throws -> WALSnapshotTransaction {
|
||||
func walSnapshotTransaction() throws -> WALSnapshotTransactionBase<API> {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
|
||||
let (reader, releaseReader) = try readerPool.get()
|
||||
return try WALSnapshotTransaction(onReader: reader, release: { isInsideTransaction in
|
||||
return try WALSnapshotTransactionBase(onReader: reader, release: { isInsideTransaction in
|
||||
// Discard the connection if the transaction could not be
|
||||
// properly ended. If we'd reuse it, the next read would
|
||||
// fail because we'd fail starting a read transaction.
|
||||
@@ -705,7 +705,7 @@ extension DatabasePool: DatabaseReader {
|
||||
/// - important: The `completion` argument is executed in a serial
|
||||
/// dispatch queue, so make sure you use the transaction asynchronously.
|
||||
func asyncWALSnapshotTransaction(
|
||||
_ completion: @escaping @Sendable (Result<WALSnapshotTransaction, Error>) -> Void
|
||||
_ completion: @escaping @Sendable (Result<WALSnapshotTransactionBase<API>, Error>) -> Void
|
||||
) {
|
||||
guard let readerPool else {
|
||||
completion(.failure(DatabaseError.connectionIsClosed()))
|
||||
@@ -777,22 +777,22 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabasePool: DatabaseWriter {
|
||||
extension DatabasePoolBase: DatabaseWriterBase {
|
||||
// MARK: - Writing in Database
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func writeWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
@@ -802,7 +802,7 @@ extension DatabasePool: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -832,7 +832,7 @@ extension DatabasePool: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func asyncBarrierWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ updates: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
guard let readerPool else {
|
||||
updates(.failure(DatabaseError.connectionIsClosed()))
|
||||
@@ -873,7 +873,7 @@ extension DatabasePool: DatabaseWriter {
|
||||
/// - throws: The error thrown by `updates`, or by the wrapping transaction.
|
||||
public func writeInTransaction(
|
||||
_ kind: Database.TransactionKind? = nil,
|
||||
_ updates: (Database) throws -> Database.TransactionCompletion)
|
||||
_ updates: (DatabaseBase<API>) throws -> Database.TransactionCompletion)
|
||||
throws
|
||||
{
|
||||
try writer.sync { db in
|
||||
@@ -883,18 +883,18 @@ extension DatabasePool: DatabaseWriter {
|
||||
}
|
||||
}
|
||||
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeReentrantWrite<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.reentrantSync(updates)
|
||||
}
|
||||
|
||||
public func asyncWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Database) -> Void
|
||||
_ updates: @escaping @Sendable (DatabaseBase<API>) -> Void
|
||||
) {
|
||||
writer.async(updates)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabasePool {
|
||||
extension DatabasePoolBase {
|
||||
|
||||
// MARK: - Snapshots
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import Foundation
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
public final class DatabaseQueue {
|
||||
private let writer: SerializedDatabase
|
||||
public final class DatabaseQueueBase<API: SQLiteAPI> {
|
||||
private let writer: SerializedDatabase<API>
|
||||
|
||||
/// If Database Suspension is enabled, this array contains the necessary `NotificationCenter` observers.
|
||||
private var suspensionObservers: [NSObjectProtocol] = []
|
||||
@@ -124,9 +124,9 @@ public final class DatabaseQueue {
|
||||
}
|
||||
|
||||
// @unchecked because of suspensionObservers
|
||||
extension DatabaseQueue: @unchecked Sendable { }
|
||||
extension DatabaseQueueBase: @unchecked Sendable { }
|
||||
|
||||
extension DatabaseQueue {
|
||||
extension DatabaseQueueBase {
|
||||
|
||||
// MARK: - Memory management
|
||||
|
||||
@@ -183,7 +183,7 @@ extension DatabaseQueue {
|
||||
#endif
|
||||
}
|
||||
|
||||
extension DatabaseQueue: DatabaseReader {
|
||||
extension DatabaseQueueBase: DatabaseReaderBase {
|
||||
public func close() throws {
|
||||
try writer.sync { try $0.close() }
|
||||
}
|
||||
@@ -225,7 +225,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
// MARK: - Reading from Database
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try writer.sync { db in
|
||||
try db.isolated(readOnly: true) {
|
||||
try value(db)
|
||||
@@ -234,7 +234,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute { db in
|
||||
try db.isolated(readOnly: true) {
|
||||
@@ -244,7 +244,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
writer.async { db in
|
||||
defer {
|
||||
@@ -273,28 +273,28 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.sync(value)
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(value)
|
||||
}
|
||||
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
writer.async { value(.success($0)) }
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.reentrantSync(value)
|
||||
}
|
||||
|
||||
public func spawnConcurrentRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
// Check that we're on the writer queue...
|
||||
writer.execute { db in
|
||||
@@ -349,7 +349,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseQueue: DatabaseWriter {
|
||||
extension DatabaseQueueBase: DatabaseWriterBase {
|
||||
// MARK: - Writing in Database
|
||||
|
||||
/// Wraps database operations inside a database transaction.
|
||||
@@ -381,7 +381,7 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
/// - throws: The error thrown by `updates`, or by the wrapping transaction.
|
||||
public func inTransaction(
|
||||
_ kind: Database.TransactionKind? = nil,
|
||||
_ updates: (Database) throws -> Database.TransactionCompletion)
|
||||
_ updates: (DatabaseBase<API>) throws -> Database.TransactionCompletion)
|
||||
throws
|
||||
{
|
||||
try writer.sync { db in
|
||||
@@ -392,29 +392,29 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func writeWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
|
||||
public func asyncBarrierWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ updates: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
writer.async { updates(.success($0)) }
|
||||
}
|
||||
@@ -453,16 +453,16 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
///
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
public func inDatabase<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func inDatabase<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeReentrantWrite<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try writer.reentrantSync(updates)
|
||||
}
|
||||
|
||||
public func asyncWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Database) -> Void
|
||||
_ updates: @escaping @Sendable (DatabaseBase<API>) -> Void
|
||||
) {
|
||||
writer.async(updates)
|
||||
}
|
||||
@@ -470,7 +470,7 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
|
||||
// MARK: - Temp Copy
|
||||
|
||||
extension DatabaseQueue {
|
||||
extension DatabaseQueueBase {
|
||||
/// Returns a connection to an in-memory copy of the database at `path`.
|
||||
///
|
||||
/// Changes performed on the returned connection do not impact the
|
||||
|
||||
@@ -52,7 +52,8 @@ import Dispatch
|
||||
/// ### Supporting Types
|
||||
///
|
||||
/// - ``AnyDatabaseReader``
|
||||
public protocol DatabaseReader: AnyObject, Sendable {
|
||||
public protocol DatabaseReaderBase<API>: AnyObject, Sendable {
|
||||
associatedtype API: SQLiteAPI
|
||||
|
||||
/// The database configuration.
|
||||
var configuration: Configuration { get }
|
||||
@@ -186,7 +187,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// - throws: The error thrown by `value`, or any ``DatabaseError`` that
|
||||
/// would happen while establishing the database access.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
func read<T>(_ value: (Database) throws -> T) throws -> T
|
||||
func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T
|
||||
|
||||
/// Executes read-only database operations, and returns their result after
|
||||
/// they have finished executing.
|
||||
@@ -215,7 +216,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// database access, or the error thrown by `value`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules read-only database operations for execution, and
|
||||
@@ -245,7 +246,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// is a `Result` that provides the database connection, or the failure
|
||||
/// that would prevent establishing the read access to the database.
|
||||
func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
)
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
@@ -284,7 +285,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// - throws: The error thrown by `value`, or any ``DatabaseError`` that
|
||||
/// would happen while establishing the database access.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
func unsafeRead<T>(_ value: (Database) throws -> T) throws -> T
|
||||
func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
/// finished executing.
|
||||
@@ -319,7 +320,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// database access, or the error thrown by `value`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
@@ -354,7 +355,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// is a `Result` that provides the database connection, or the failure
|
||||
/// that would prevent establishing the read access to the database.
|
||||
func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
)
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
@@ -398,7 +399,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// - parameter value: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `value`, or any ``DatabaseError`` that
|
||||
/// would happen while establishing the database access.
|
||||
func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T
|
||||
func unsafeReentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T
|
||||
|
||||
|
||||
// MARK: - Value Observation
|
||||
@@ -417,7 +418,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
) -> AnyDatabaseCancellable
|
||||
}
|
||||
|
||||
extension DatabaseReader {
|
||||
extension DatabaseReaderBase {
|
||||
|
||||
// MARK: - Backup
|
||||
|
||||
@@ -499,7 +500,7 @@ extension DatabaseReader {
|
||||
}
|
||||
|
||||
#if canImport(Combine)
|
||||
extension DatabaseReader {
|
||||
extension DatabaseReaderBase {
|
||||
// MARK: - Publishing Database Values
|
||||
|
||||
/// Returns a publisher that publishes one value and completes.
|
||||
@@ -531,7 +532,7 @@ extension DatabaseReader {
|
||||
/// - parameter value: A closure which accesses the database.
|
||||
public func readPublisher<Output>(
|
||||
receiveOn scheduler: some Combine.Scheduler = DispatchQueue.main,
|
||||
value: @escaping @Sendable (Database) throws -> Output
|
||||
value: @escaping @Sendable (DatabaseBase<API>) throws -> Output
|
||||
) -> DatabasePublishers.Read<Output> {
|
||||
OnDemandFuture { fulfill in
|
||||
self.asyncRead { dbResult in
|
||||
@@ -568,7 +569,7 @@ extension Publisher where Failure == Error {
|
||||
}
|
||||
#endif
|
||||
|
||||
extension DatabaseReader {
|
||||
extension DatabaseReaderBase {
|
||||
// MARK: - Value Observation Support
|
||||
|
||||
/// Adding an observation in a read-only database emits only the
|
||||
@@ -619,17 +620,17 @@ extension DatabaseReader {
|
||||
///
|
||||
/// An instance of `AnyDatabaseReader` forwards its operations to an underlying
|
||||
/// base database reader.
|
||||
public final class AnyDatabaseReader {
|
||||
private let base: any DatabaseReader
|
||||
public final class AnyDatabaseReaderBase<API: SQLiteAPI> {
|
||||
private let base: any DatabaseReader<API>
|
||||
|
||||
/// Creates a new database reader that wraps and forwards operations
|
||||
/// to `base`.
|
||||
public init(_ base: any DatabaseReader) {
|
||||
public init(_ base: any DatabaseReader<API>) {
|
||||
self.base = base
|
||||
}
|
||||
}
|
||||
|
||||
extension AnyDatabaseReader: DatabaseReader {
|
||||
extension AnyDatabaseReaderBase: DatabaseReaderBase {
|
||||
public var configuration: Configuration {
|
||||
base.configuration
|
||||
}
|
||||
@@ -647,40 +648,40 @@ extension AnyDatabaseReader: DatabaseReader {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.read(value)
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.read(value)
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.asyncRead(value)
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.unsafeRead(value)
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.unsafeRead(value)
|
||||
}
|
||||
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.asyncUnsafeRead(value)
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.unsafeReentrantRead(value)
|
||||
}
|
||||
|
||||
@@ -735,20 +736,20 @@ extension DatabaseSnapshotReader {
|
||||
/// - parameter value: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `value`, or any ``DatabaseError`` that
|
||||
/// would happen while establishing the database access.
|
||||
public func reentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func reentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
// Reentrant reads are safe in a snapshot
|
||||
try unsafeReentrantRead(value)
|
||||
}
|
||||
|
||||
// There is no such thing as an unsafe access to a snapshot.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try read(value)
|
||||
}
|
||||
|
||||
// There is no such thing as an unsafe access to a snapshot.
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
asyncRead(value)
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public struct DatabaseRegion: Sendable {
|
||||
}
|
||||
|
||||
/// Returns a region suitable for database observation
|
||||
func observableRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
func observableRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
// SQLite does not expose schema changes to the
|
||||
// TransactionObserver protocol. By removing internal SQLite tables from
|
||||
// the observed region, we optimize database observation.
|
||||
@@ -178,7 +178,7 @@ public struct DatabaseRegion: Sendable {
|
||||
/// Returns a region only made of actual tables with their canonical names.
|
||||
///
|
||||
/// This method removes views.
|
||||
func canonicalTables(_ db: Database) throws -> DatabaseRegion {
|
||||
func canonicalTables(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
guard let tableRegions else { return .fullDatabase }
|
||||
var region = DatabaseRegion()
|
||||
for (table, tableRegion) in tableRegions {
|
||||
@@ -237,7 +237,7 @@ extension DatabaseRegion {
|
||||
/// Returns an array of all event kinds that can impact this region.
|
||||
///
|
||||
/// - precondition: the region is canonical.
|
||||
func impactfulEventKinds(_ db: Database) throws -> [DatabaseEventKind] {
|
||||
func impactfulEventKinds(_ db: DatabaseBase<some SQLiteAPI>) throws -> [DatabaseEventKind] {
|
||||
if let tableRegions {
|
||||
return try tableRegions.flatMap { (table, tableRegion) -> [DatabaseEventKind] in
|
||||
let tableName = table.rawValue // canonical table name
|
||||
@@ -420,7 +420,7 @@ public protocol DatabaseRegionConvertible: Sendable {
|
||||
/// Returns a database region.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
func databaseRegion(_ db: Database) throws -> DatabaseRegion
|
||||
func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
}
|
||||
|
||||
extension DatabaseRegionConvertible where Self == DatabaseRegion {
|
||||
@@ -430,16 +430,16 @@ extension DatabaseRegionConvertible where Self == DatabaseRegion {
|
||||
}
|
||||
|
||||
extension DatabaseRegion: DatabaseRegionConvertible {
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
public func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A type-erased DatabaseRegionConvertible
|
||||
public struct AnyDatabaseRegionConvertible: DatabaseRegionConvertible {
|
||||
let _region: @Sendable (Database) throws -> DatabaseRegion
|
||||
let _region: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
|
||||
public init(_ region: @escaping @Sendable (Database) throws -> DatabaseRegion) {
|
||||
public init(_ region: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion) {
|
||||
_region = region
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ public struct AnyDatabaseRegionConvertible: DatabaseRegionConvertible {
|
||||
_region = { try region.databaseRegion($0) }
|
||||
}
|
||||
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
public func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
try _region(db)
|
||||
}
|
||||
}
|
||||
@@ -461,7 +461,7 @@ extension DatabaseRegion {
|
||||
}
|
||||
}
|
||||
|
||||
static func union(_ regions: [any DatabaseRegionConvertible]) -> @Sendable (Database) throws -> DatabaseRegion {
|
||||
static func union<API: SQLiteAPI>(_ regions: [any DatabaseRegionConvertible]) -> @Sendable (DatabaseBase<API>) throws -> DatabaseRegion {
|
||||
return { db in
|
||||
try regions.reduce(into: DatabaseRegion()) { union, region in
|
||||
try union.formUnion(region.databaseRegion(db))
|
||||
|
||||
@@ -6,7 +6,7 @@ import Foundation
|
||||
public struct DatabaseRegionObservation: Sendable {
|
||||
/// A closure that is evaluated when the observation starts, and returns
|
||||
/// the observed database region.
|
||||
var observedRegion: @Sendable (Database) throws -> DatabaseRegion
|
||||
var observedRegion: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion
|
||||
}
|
||||
|
||||
extension DatabaseRegionObservation {
|
||||
@@ -87,7 +87,7 @@ extension DatabaseRegionObservation {
|
||||
public func start(
|
||||
in writer: any DatabaseWriter,
|
||||
onError: @escaping @Sendable (Error) -> Void,
|
||||
onChange: @escaping @Sendable (Database) -> Void)
|
||||
onChange: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) -> Void)
|
||||
-> AnyDatabaseCancellable
|
||||
{
|
||||
let stateMutex = Mutex(ObservationState.pending)
|
||||
@@ -146,12 +146,12 @@ extension DatabaseRegionObservation {
|
||||
}
|
||||
#endif
|
||||
|
||||
private class DatabaseRegionObserver: TransactionObserver {
|
||||
private class DatabaseRegionObserver: TransactionObserverBase {
|
||||
let region: DatabaseRegion
|
||||
let onChange: @Sendable (Database) -> Void
|
||||
let onChange: @Sendable (DatabaseBase<some SQLiteAPI>) -> Void
|
||||
var isChanged = false
|
||||
|
||||
init(region: DatabaseRegion, onChange: @escaping @Sendable (Database) -> Void) {
|
||||
init(region: DatabaseRegion, onChange: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) -> Void) {
|
||||
self.region = region
|
||||
self.onChange = onChange
|
||||
}
|
||||
@@ -172,14 +172,14 @@ private class DatabaseRegionObserver: TransactionObserver {
|
||||
}
|
||||
}
|
||||
|
||||
func databaseDidCommit(_ db: Database) {
|
||||
func databaseDidCommit(_ db: DatabaseBase<some SQLiteAPI>) {
|
||||
guard isChanged else { return }
|
||||
isChanged = false
|
||||
|
||||
onChange(db)
|
||||
}
|
||||
|
||||
func databaseDidRollback(_ db: Database) {
|
||||
func databaseDidRollback(_ db: DatabaseBase<some SQLiteAPI>) {
|
||||
isChanged = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public protocol DatabaseSchemaSource: Sendable {
|
||||
/// // A schema source that specifies that all views are identified by
|
||||
/// // their "id" column:
|
||||
/// struct MySchemaSource: DatabaseSchemaSource {
|
||||
/// func columnsForPrimaryKey(_ db: Database, inView view: DatabaseObjectID) {
|
||||
/// func columnsForPrimaryKey(_ db: DatabaseBase<some SQLiteAPI>, inView view: DatabaseObjectID) {
|
||||
/// ["id"]
|
||||
/// }
|
||||
/// }
|
||||
@@ -123,7 +123,7 @@ public protocol DatabaseSchemaSource: Sendable {
|
||||
/// // A well-behaved schema source defined by a library is public
|
||||
/// // and returns nil for unknown views.
|
||||
/// public struct MyLibrarySchemaSource: DatabaseSchemaSource {
|
||||
/// public func columnsForPrimaryKey(_ db: Database, inView view: DatabaseObjectID) {
|
||||
/// public func columnsForPrimaryKey(_ db: DatabaseBase<some SQLiteAPI>, inView view: DatabaseObjectID) {
|
||||
/// if view.name == "playerView" {
|
||||
/// // This is a view managed by my library:
|
||||
/// return ["id"]
|
||||
@@ -161,14 +161,14 @@ public protocol DatabaseSchemaSource: Sendable {
|
||||
/// - db: A database connection.
|
||||
/// - view: The identifier of a database view.
|
||||
func columnsForPrimaryKey(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
inView view: DatabaseObjectID
|
||||
) throws -> [String]?
|
||||
}
|
||||
|
||||
extension DatabaseSchemaSource {
|
||||
public func columnsForPrimaryKey(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
inView view: DatabaseObjectID
|
||||
) throws -> [String]? {
|
||||
nil
|
||||
@@ -210,7 +210,7 @@ where Source1: DatabaseSchemaSource,
|
||||
var first: Source1
|
||||
var second: Source2
|
||||
|
||||
func columnsForPrimaryKey(_ db: Database, inView view: DatabaseObjectID) throws -> [String]? {
|
||||
func columnsForPrimaryKey(_ db: DatabaseBase<some SQLiteAPI>, inView view: DatabaseObjectID) throws -> [String]? {
|
||||
if let result = try first.columnsForPrimaryKey(db, inView: view) { return result }
|
||||
if let result = try second.columnsForPrimaryKey(db, inView: view) { return result }
|
||||
return nil
|
||||
|
||||
@@ -154,24 +154,24 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
|
||||
// MARK: - Reading from Database
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
public func read<T>(_ block: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T {
|
||||
try reader.sync(block)
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T
|
||||
) async throws -> T {
|
||||
try await reader.execute(value)
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<some SQLiteAPI>, Error>) -> Void
|
||||
) {
|
||||
reader.async { value(.success($0)) }
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<some SQLiteAPI>) throws -> T) rethrows -> T {
|
||||
try reader.sync(value)
|
||||
}
|
||||
|
||||
@@ -180,18 +180,18 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
|
||||
// `DatabaseSnapshotReader`, because of
|
||||
// <https://github.com/apple/swift/issues/74469>.
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T
|
||||
) async throws -> T {
|
||||
try await read(value)
|
||||
}
|
||||
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<some SQLiteAPI>, Error>) -> Void
|
||||
) {
|
||||
reader.async { value(.success($0)) }
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T {
|
||||
try reader.reentrantSync(value)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A database connection that allows concurrent accesses to an unchanging
|
||||
/// database content, as it existed at the moment the snapshot was created.
|
||||
@@ -132,7 +132,7 @@ public final class DatabaseSnapshotPool {
|
||||
/// - parameter configuration: A configuration. If nil, the configuration of
|
||||
/// `db` is used.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public init(_ db: Database, configuration: Configuration? = nil) throws {
|
||||
public init(_ db: DatabaseBase<some SQLiteAPI>, configuration: Configuration? = nil) throws {
|
||||
let path = db.path
|
||||
var configuration = Self.configure(configuration ?? db.configuration)
|
||||
|
||||
@@ -273,7 +273,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func read<T>(_ value: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T {
|
||||
GRDBPrecondition(currentReader == nil, "Database methods are not reentrant.")
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -297,7 +297,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -319,7 +319,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<some SQLiteAPI>, Error>) -> Void
|
||||
) {
|
||||
guard let readerPool else {
|
||||
value(.failure(DatabaseError.connectionIsClosed()))
|
||||
@@ -345,12 +345,12 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
// `DatabaseSnapshotReader`, because of
|
||||
// <https://github.com/apple/swift/issues/74469>.
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T
|
||||
) async throws -> T {
|
||||
try await read(value)
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<some SQLiteAPI>) throws -> T) throws -> T {
|
||||
if let reader = currentReader {
|
||||
return try reader.reentrantSync { db in
|
||||
let result = try value(db)
|
||||
@@ -399,11 +399,11 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
return readers.first { $0.onValidQueue }
|
||||
}
|
||||
|
||||
private func poolCompletion(_ db: Database) -> PoolCompletion {
|
||||
private func poolCompletion(_ db: DatabaseBase<some SQLiteAPI>) -> PoolCompletion {
|
||||
snapshotIsLost(db) ? .discard : .reuse
|
||||
}
|
||||
|
||||
private func snapshotIsLost(_ db: Database) -> Bool {
|
||||
private func snapshotIsLost(_ db: DatabaseBase<some SQLiteAPI>) -> Bool {
|
||||
do {
|
||||
let currentSnapshot = try WALSnapshot(db)
|
||||
if currentSnapshot.compare(walSnapshot) == 0 {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -162,7 +162,7 @@ public struct DatabaseValue: Hashable {
|
||||
}
|
||||
|
||||
/// Creates a `DatabaseValue` initialized from a raw SQLite statement pointer.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_NULL:
|
||||
storage = .null
|
||||
@@ -187,7 +187,7 @@ public struct DatabaseValue: Hashable {
|
||||
}
|
||||
|
||||
extension DatabaseValue: StatementBinding {
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
switch storage {
|
||||
case .null:
|
||||
return sqlite3_bind_null(sqliteStatement, index)
|
||||
|
||||
@@ -80,7 +80,7 @@ extension DatabaseValueConvertible {
|
||||
.databaseValue(databaseValue)
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
public func bind(to sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, at index: CInt) -> CInt {
|
||||
databaseValue.bind(to: sqliteStatement, at: index)
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: A ``DatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> DatabaseValueCursor<Self>
|
||||
@@ -307,7 +307,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An array.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> [Self]
|
||||
@@ -341,7 +341,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Self?
|
||||
@@ -376,7 +376,7 @@ extension DatabaseValueConvertible where Self: Hashable {
|
||||
/// - returns: A set.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Set<Self>
|
||||
@@ -421,7 +421,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: A ``DatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -453,7 +453,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An array.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -488,7 +488,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -522,7 +522,7 @@ extension DatabaseValueConvertible where Self: Hashable {
|
||||
/// - returns: A set.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -581,7 +581,7 @@ extension DatabaseValueConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A ``DatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: some FetchRequest) throws -> DatabaseValueCursor<Self> {
|
||||
public static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> DatabaseValueCursor<Self> {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -622,7 +622,7 @@ extension DatabaseValueConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An array.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: some FetchRequest) throws -> [Self] {
|
||||
public static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> [Self] {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -666,7 +666,7 @@ extension DatabaseValueConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: some FetchRequest) throws -> Self? {
|
||||
public static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Self? {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
return try fetchOne(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -709,7 +709,7 @@ extension DatabaseValueConvertible where Self: Hashable {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A set.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(_ db: Database, _ request: some FetchRequest) throws -> Set<Self> {
|
||||
public static func fetchSet(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Set<Self> {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchSet(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -762,7 +762,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``DatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
@@ -800,7 +800,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [RowDecoder] {
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
@@ -841,7 +841,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowDecoder? {
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
@@ -874,7 +874,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & Hashable {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<RowDecoder> {
|
||||
try RowDecoder.fetchSet(db, self)
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ import Dispatch
|
||||
/// ### Supporting Types
|
||||
///
|
||||
/// - ``AnyDatabaseWriter``
|
||||
public protocol DatabaseWriter: DatabaseReader {
|
||||
public protocol DatabaseWriterBase: DatabaseReaderBase {
|
||||
|
||||
// MARK: - Writing in Database
|
||||
|
||||
@@ -98,7 +98,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T
|
||||
func writeWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
/// finished executing.
|
||||
@@ -130,7 +130,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
@@ -171,7 +171,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) throws -> T
|
||||
func barrierWriteWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) throws -> T
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
/// finished executing.
|
||||
@@ -213,7 +213,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
@@ -256,7 +256,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// is a `Result` that provides the database connection, or the failure
|
||||
/// that would prevent establishing the barrier access to the database.
|
||||
func asyncBarrierWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ updates: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
)
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
@@ -290,7 +290,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
///
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
func asyncWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Database) -> Void
|
||||
_ updates: @escaping @Sendable (DatabaseBase<API>) -> Void
|
||||
)
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
@@ -325,7 +325,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
///
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T
|
||||
func unsafeReentrantWrite<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T
|
||||
|
||||
// MARK: - Reading from Database
|
||||
|
||||
@@ -374,7 +374,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// is a `Result` that provides the database connection, or the failure
|
||||
/// that would prevent establishing the read access to the database.
|
||||
func spawnConcurrentRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
)
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ extension DatabaseWriter {
|
||||
/// would happen while establishing the database access or committing
|
||||
/// the transaction.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func write<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
public func write<T>(_ updates: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try writeWithoutTransaction { db in
|
||||
var result: T?
|
||||
try db.inTransaction {
|
||||
@@ -461,7 +461,7 @@ extension DatabaseWriter {
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - parameter completion: A closure called with the transaction result.
|
||||
public func asyncWrite<T>(
|
||||
_ updates: @escaping @Sendable (Database) throws -> T,
|
||||
_ updates: @escaping @Sendable (DatabaseBase<API>) throws -> T,
|
||||
completion: @escaping @Sendable (Database, Result<T, Error>) -> Void
|
||||
) {
|
||||
asyncWriteWithoutTransaction { db in
|
||||
@@ -502,7 +502,7 @@ extension DatabaseWriter {
|
||||
/// is deallocated).
|
||||
public func add(
|
||||
transactionObserver: some TransactionObserver,
|
||||
extent: Database.TransactionObservationExtent = .observerLifetime)
|
||||
extent: DatabaseTransactionObservationExtent = .observerLifetime)
|
||||
{
|
||||
writeWithoutTransaction { $0.add(transactionObserver: transactionObserver, extent: extent) }
|
||||
}
|
||||
@@ -640,7 +640,7 @@ extension DatabaseWriter {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
public func write<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await writeWithoutTransaction { db in
|
||||
var result: T?
|
||||
@@ -733,7 +733,7 @@ extension DatabaseWriter {
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
public func writePublisher<Output>(
|
||||
receiveOn scheduler: some Combine.Scheduler = DispatchQueue.main,
|
||||
updates: @escaping @Sendable (Database) throws -> Output
|
||||
updates: @escaping @Sendable (DatabaseBase<API>) throws -> Output
|
||||
) -> DatabasePublishers.Write<Output> {
|
||||
OnDemandFuture { fulfill in
|
||||
self.asyncWrite(updates, completion: { _, result in
|
||||
@@ -796,7 +796,7 @@ extension DatabaseWriter {
|
||||
/// - parameter value: A closure which reads from the database.
|
||||
public func writePublisher<T: Sendable, Output>(
|
||||
receiveOn scheduler: some Combine.Scheduler = DispatchQueue.main,
|
||||
updates: @escaping @Sendable (Database) throws -> T,
|
||||
updates: @escaping @Sendable (DatabaseBase<API>) throws -> T,
|
||||
thenRead value: @escaping @Sendable (Database, T) throws -> Output
|
||||
) -> DatabasePublishers.Write<Output> {
|
||||
OnDemandFuture { fulfill in
|
||||
@@ -880,40 +880,40 @@ extension AnyDatabaseWriter: DatabaseReader {
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.read(value)
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.read(value)
|
||||
}
|
||||
|
||||
public func asyncRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.asyncRead(value)
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func unsafeRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.unsafeRead(value)
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.unsafeRead(value)
|
||||
}
|
||||
|
||||
public func asyncUnsafeRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.asyncUnsafeRead(value)
|
||||
}
|
||||
|
||||
public func unsafeReentrantRead<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
public func unsafeReentrantRead<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.unsafeReentrantRead(value)
|
||||
}
|
||||
|
||||
@@ -931,45 +931,45 @@ extension AnyDatabaseWriter: DatabaseReader {
|
||||
|
||||
extension AnyDatabaseWriter: DatabaseWriter {
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func writeWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try base.writeWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.writeWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try base.barrierWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.barrierWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
public func asyncBarrierWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ updates: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.asyncBarrierWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
public func asyncWriteWithoutTransaction(
|
||||
_ updates: @escaping @Sendable (Database) -> Void
|
||||
_ updates: @escaping @Sendable (DatabaseBase<API>) -> Void
|
||||
) {
|
||||
base.asyncWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
public func unsafeReentrantWrite<T>(_ updates: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try base.unsafeReentrantWrite(updates)
|
||||
}
|
||||
|
||||
public func spawnConcurrentRead(
|
||||
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
|
||||
_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void
|
||||
) {
|
||||
base.spawnConcurrentRead(value)
|
||||
}
|
||||
|
||||
@@ -87,20 +87,20 @@ public protocol FetchRequest<RowDecoder>: SQLSubqueryable, DatabaseRegionConvert
|
||||
/// - parameter db: A database connection.
|
||||
/// - parameter singleResult: A hint that a single result row will be
|
||||
/// consumed.
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
func makePreparedRequest<API>(_ db: DatabaseBase<API>, forSingleResult singleResult: Bool) throws -> PreparedRequestBase<API>
|
||||
|
||||
/// Returns the number of rows fetched by the request.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int
|
||||
}
|
||||
|
||||
extension FetchRequest {
|
||||
/// Returns the database region that the request feeds from.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
public func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
try makePreparedRequest(db, forSingleResult: false).statement.databaseRegion
|
||||
}
|
||||
}
|
||||
@@ -123,28 +123,28 @@ typealias WillExecuteSupplementaryRequest = (_ request: AnyFetchRequest<Row>, _
|
||||
/// - parameter rows: The rows that are modified by the supplementary fetch.
|
||||
/// - parameter willExecuteSupplementaryRequest: A closure to execute before
|
||||
/// performing supplementary fetches.
|
||||
typealias SupplementaryFetch = (
|
||||
_ db: Database,
|
||||
typealias SupplementaryFetch<API: SQLiteAPI> = (
|
||||
_ db: DatabaseBase<API>,
|
||||
_ rows: [Row],
|
||||
_ willExecuteSupplementaryRequest: WillExecuteSupplementaryRequest?)
|
||||
throws -> Void
|
||||
|
||||
/// A `PreparedRequest` is a request that is ready to be executed.
|
||||
public struct PreparedRequest {
|
||||
public struct PreparedRequestBase<API: SQLiteAPI> {
|
||||
/// A prepared statement with bound parameters.
|
||||
public var statement: Statement
|
||||
public var statement: StatementBase<API>
|
||||
|
||||
/// An eventual adapter for rows fetched by the select statement.
|
||||
public var adapter: (any RowAdapter)?
|
||||
|
||||
/// A closure that performs supplementary fetches.
|
||||
/// Support for eager loading of hasMany associations.
|
||||
var supplementaryFetch: SupplementaryFetch?
|
||||
var supplementaryFetch: SupplementaryFetch<API>?
|
||||
|
||||
init(
|
||||
statement: Statement,
|
||||
statement: StatementBase<API>,
|
||||
adapter: (any RowAdapter)?,
|
||||
supplementaryFetch: SupplementaryFetch? = nil)
|
||||
supplementaryFetch: SupplementaryFetch<API>? = nil)
|
||||
{
|
||||
self.statement = statement
|
||||
self.adapter = adapter
|
||||
@@ -172,7 +172,7 @@ extension FetchRequest {
|
||||
/// - parameter adapter: A closure that accepts a database connection and
|
||||
/// returns a row adapter.
|
||||
public func adapted(
|
||||
_ adapter: @escaping @Sendable (Database) throws -> any RowAdapter
|
||||
_ adapter: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> any RowAdapter
|
||||
) -> AdaptedFetchRequest<Self> {
|
||||
AdaptedFetchRequest(self, adapter)
|
||||
}
|
||||
@@ -183,11 +183,11 @@ extension FetchRequest {
|
||||
/// See ``FetchRequest/adapted(_:)``.
|
||||
public struct AdaptedFetchRequest<Base: FetchRequest> {
|
||||
let base: Base
|
||||
let adapter: @Sendable (Database) throws -> any RowAdapter
|
||||
let adapter: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> any RowAdapter
|
||||
|
||||
/// Creates an adapted request from a base request and a closure that builds
|
||||
/// a row adapter from a database connection.
|
||||
init(_ base: Base, _ adapter: @escaping @Sendable (Database) throws -> any RowAdapter) {
|
||||
init(_ base: Base, _ adapter: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> any RowAdapter) {
|
||||
self.base = base
|
||||
self.adapter = adapter
|
||||
}
|
||||
@@ -202,14 +202,14 @@ extension AdaptedFetchRequest: SQLSubqueryable {
|
||||
extension AdaptedFetchRequest: FetchRequest {
|
||||
public typealias RowDecoder = Base.RowDecoder
|
||||
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
public func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try base.fetchCount(db)
|
||||
}
|
||||
|
||||
public func makePreparedRequest(
|
||||
_ db: Database,
|
||||
public func makePreparedRequest<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
forSingleResult singleResult: Bool = false)
|
||||
throws -> PreparedRequest
|
||||
throws -> PreparedRequestBase<API>
|
||||
{
|
||||
var preparedRequest = try base.makePreparedRequest(db, forSingleResult: singleResult)
|
||||
|
||||
@@ -262,14 +262,14 @@ extension AnyFetchRequest: SQLSubqueryable {
|
||||
}
|
||||
|
||||
extension AnyFetchRequest: FetchRequest {
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
public func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try request.fetchCount(db)
|
||||
}
|
||||
|
||||
public func makePreparedRequest(
|
||||
_ db: Database,
|
||||
public func makePreparedRequest<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
forSingleResult singleResult: Bool = false)
|
||||
throws -> PreparedRequest
|
||||
throws -> PreparedRequestBase<API>
|
||||
{
|
||||
try request.makePreparedRequest(db, forSingleResult: singleResult)
|
||||
}
|
||||
@@ -283,11 +283,11 @@ private class FetchRequestEraser: FetchRequest, @unchecked Sendable {
|
||||
fatalError("subclass must override")
|
||||
}
|
||||
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest<API>(_ db: DatabaseBase<API>, forSingleResult singleResult: Bool) throws -> PreparedRequestBase<API> {
|
||||
fatalError("subclass must override")
|
||||
}
|
||||
|
||||
func fetchCount(_ db: Database) throws -> Int {
|
||||
func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
fatalError("subclass must override")
|
||||
}
|
||||
}
|
||||
@@ -303,11 +303,11 @@ private final class ConcreteFetchRequestEraser<Request: FetchRequest>: FetchRequ
|
||||
request.sqlSubquery
|
||||
}
|
||||
|
||||
override func fetchCount(_ db: Database) throws -> Int {
|
||||
override func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try request.fetchCount(db)
|
||||
}
|
||||
|
||||
override func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
override func makePreparedRequest<API>(_ db: DatabaseBase<API>, forSingleResult singleResult: Bool) throws -> PreparedRequestBase<API> {
|
||||
try request.makePreparedRequest(db, forSingleResult: singleResult)
|
||||
}
|
||||
}
|
||||
+31
-31
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -234,7 +234,7 @@ public final class Row {
|
||||
/// The row is implemented on top of StatementRowImpl, which grants *direct*
|
||||
/// access to the SQLite statement. Iteration of the statement does modify
|
||||
/// the row.
|
||||
init(statement: Statement) {
|
||||
init(statement: StatementBase<some SQLiteAPI>) {
|
||||
self.statement = statement
|
||||
self.sqliteStatement = statement.sqliteStatement
|
||||
self.impl = StatementRowImpl(sqliteStatement: statement.sqliteStatement, statement: statement)
|
||||
@@ -243,7 +243,7 @@ public final class Row {
|
||||
|
||||
/// Creates a row that maps an SQLite statement. Further calls to
|
||||
/// sqlite3_step() modify the row.
|
||||
init(sqliteStatement: SQLiteStatement) {
|
||||
init(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>) {
|
||||
self.statement = nil
|
||||
self.sqliteStatement = sqliteStatement
|
||||
self.impl = SQLiteStatementRowImpl(sqliteStatement: sqliteStatement)
|
||||
@@ -257,8 +257,8 @@ public final class Row {
|
||||
/// the values from the SQLite statement so that further iteration of the
|
||||
/// statement does not modify the row.
|
||||
convenience init(
|
||||
copiedFromSQLiteStatement sqliteStatement: SQLiteStatement,
|
||||
statement: Statement)
|
||||
copiedFromSQLiteStatement sqliteStatement: SQLiteStatementBase<some SQLiteAPI>,
|
||||
statement: StatementBase<some SQLiteAPI>)
|
||||
{
|
||||
self.init(impl: StatementCopyRowImpl(
|
||||
sqliteStatement: sqliteStatement,
|
||||
@@ -1736,7 +1736,7 @@ extension Row {
|
||||
/// - returns: A ``RowCursor`` over fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> RowCursor
|
||||
@@ -1764,7 +1764,7 @@ extension Row {
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> [Row]
|
||||
@@ -1793,7 +1793,7 @@ extension Row {
|
||||
/// - returns: A set of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Set<Row>
|
||||
@@ -1822,7 +1822,7 @@ extension Row {
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Row?
|
||||
@@ -1877,7 +1877,7 @@ extension Row {
|
||||
/// - returns: A ``RowCursor`` over fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -1906,7 +1906,7 @@ extension Row {
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -1935,7 +1935,7 @@ extension Row {
|
||||
/// - returns: A set of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -1964,7 +1964,7 @@ extension Row {
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -2027,7 +2027,7 @@ extension Row {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A ``RowCursor`` over fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: some FetchRequest) throws -> RowCursor {
|
||||
public static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> RowCursor {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
precondition(request.supplementaryFetch == nil, "Not implemented: fetchCursor with supplementary fetch")
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
@@ -2064,7 +2064,7 @@ extension Row {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: some FetchRequest) throws -> [Row] {
|
||||
public static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> [Row] {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
let rows = try fetchAll(request.statement, adapter: request.adapter)
|
||||
try request.supplementaryFetch?(db, rows, nil)
|
||||
@@ -2102,7 +2102,7 @@ extension Row {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A set of rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(_ db: Database, _ request: some FetchRequest) throws -> Set<Row> {
|
||||
public static func fetchSet(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Set<Row> {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
if let supplementaryFetch = request.supplementaryFetch {
|
||||
let rows = try fetchAll(request.statement, adapter: request.adapter)
|
||||
@@ -2144,7 +2144,7 @@ extension Row {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: some FetchRequest) throws -> Row? {
|
||||
public static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Row? {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
guard let row = try fetchOne(request.statement, adapter: request.adapter) else {
|
||||
return nil
|
||||
@@ -2193,7 +2193,7 @@ extension FetchRequest<Row> {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``RowCursor`` over fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RowCursor {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowCursor {
|
||||
try Row.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
@@ -2214,7 +2214,7 @@ extension FetchRequest<Row> {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [Row] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [Row] {
|
||||
try Row.fetchAll(db, self)
|
||||
}
|
||||
|
||||
@@ -2235,7 +2235,7 @@ extension FetchRequest<Row> {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<Row> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<Row> {
|
||||
try Row.fetchSet(db, self)
|
||||
}
|
||||
|
||||
@@ -2256,7 +2256,7 @@ extension FetchRequest<Row> {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> Row? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> Row? {
|
||||
try Row.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A key that is used to decode a value in a row
|
||||
@usableFromInline
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ public struct SQL: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A tuple made of a raw SQL string, and statement arguments.
|
||||
public func build(_ db: Database) throws -> (sql: String, arguments: StatementArguments) {
|
||||
public func build(_ db: DatabaseBase<some SQLiteAPI>) throws -> (sql: String, arguments: StatementArguments) {
|
||||
let context = SQLGenerationContext(db)
|
||||
let sql = try self.sql(context)
|
||||
return (sql: sql, arguments: context.arguments)
|
||||
|
||||
@@ -191,14 +191,14 @@ extension SQLRequest: FetchRequest {
|
||||
.literal(sqlLiteral)
|
||||
}
|
||||
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
public func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try SQLRequest<Int>("SELECT COUNT(*) FROM (\(self))").fetchOne(db)!
|
||||
}
|
||||
|
||||
public func makePreparedRequest(
|
||||
_ db: Database,
|
||||
public func makePreparedRequest<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
forSingleResult singleResult: Bool = false)
|
||||
throws -> PreparedRequest
|
||||
throws -> PreparedRequestBase<API>
|
||||
{
|
||||
let context = SQLGenerationContext(db)
|
||||
let sql = try sqlLiteral.sql(context)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
public protocol SQLiteAPI {
|
||||
static var SQLITE_NULL: CInt { get }
|
||||
static var SQLITE_OK: CInt { get }
|
||||
|
||||
static func sqlite3_bind_double(_: OpaquePointer?, _: CInt, _: CDouble) -> CInt
|
||||
static func sqlite3_bind_int64(_: OpaquePointer?, _: CInt, _: Int64) -> CInt
|
||||
static func sqlite3_bind_null(_: OpaquePointer?, _: CInt) -> CInt
|
||||
static func sqlite3_bind_text(_: OpaquePointer?, _: CInt, _: UnsafePointer<CChar>?, _: CInt, _: (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> CInt
|
||||
|
||||
static func sqlite3_column_double(_: OpaquePointer?, _ iCol: CInt) -> Double
|
||||
static func sqlite3_column_int64(_: OpaquePointer?, _ iCol: CInt) -> Int64
|
||||
static func sqlite3_column_text(_: OpaquePointer?, _ iCol: CInt) -> UnsafePointer<CChar>?
|
||||
static func sqlite3_column_type(_: OpaquePointer?, _ iCol: CInt) -> CInt
|
||||
|
||||
@discardableResult static func sqlite3_commit_hook(_: OpaquePointer?, _: (@convention(c) (UnsafeMutableRawPointer?) -> Int32)?, _: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer?
|
||||
@discardableResult static func sqlite3_rollback_hook(_: OpaquePointer?, _: (@convention(c) (UnsafeMutableRawPointer?) -> Void)?, _: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer?
|
||||
@discardableResult static func sqlite3_update_hook(_: OpaquePointer?, _: (@convention(c) (UnsafeMutableRawPointer?, Int32, UnsafePointer<CChar>?, UnsafePointer<CChar>?, Int64) -> Void)?, _: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer?
|
||||
}
|
||||
|
||||
public typealias sqlite3_destructor_type = @convention(c) (UnsafeMutableRawPointer?) -> Void
|
||||
@@ -59,7 +59,7 @@ final class SchedulingWatchdog: @unchecked Sendable {
|
||||
}
|
||||
|
||||
static func preconditionValidQueue(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
_ message: @autoclosure() -> String = "Database was not used on the correct thread.",
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line)
|
||||
@@ -69,11 +69,11 @@ final class SchedulingWatchdog: @unchecked Sendable {
|
||||
|
||||
/// Returns whether the database argument can be used in the current
|
||||
/// dispatch queue.
|
||||
static func allows(_ db: Database) -> Bool {
|
||||
static func allows(_ db: DatabaseBase<some SQLiteAPI>) -> Bool {
|
||||
current?.allows(db) ?? false
|
||||
}
|
||||
|
||||
func allows(_ db: Database) -> Bool {
|
||||
func allows(_ db: DatabaseBase<some SQLiteAPI>) -> Bool {
|
||||
allowedDatabases.contains { $0 === db }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
/// A class that serializes accesses to an SQLite connection.
|
||||
final class SerializedDatabase {
|
||||
final class SerializedDatabaseBase<API: SQLiteAPI> {
|
||||
/// The database connection
|
||||
private let db: Database
|
||||
private let db: DatabaseBase<API>
|
||||
|
||||
/// The actor that performs asynchronous accesses
|
||||
private let actor: DispatchQueueActor
|
||||
@@ -92,7 +92,7 @@ final class SerializedDatabase {
|
||||
/// - parameter allowingLongLivedTransaction: When true, the
|
||||
/// ``Configuration/allowsUnsafeTransactions`` configuration flag is
|
||||
/// ignored until this method is called again with false.
|
||||
func sync<T>(allowingLongLivedTransaction: Bool, _ body: (Database) throws -> T) rethrows -> T {
|
||||
func sync<T>(allowingLongLivedTransaction: Bool, _ body: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try sync { db in
|
||||
self.allowsUnsafeTransactions = allowingLongLivedTransaction
|
||||
return try body(db)
|
||||
@@ -103,7 +103,7 @@ final class SerializedDatabase {
|
||||
/// have finished executing.
|
||||
///
|
||||
/// This method is not reentrant.
|
||||
func sync<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
func sync<T>(_ block: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
// Three different cases:
|
||||
//
|
||||
// 1. A database is invoked from some queue like the main queue:
|
||||
@@ -153,7 +153,7 @@ final class SerializedDatabase {
|
||||
/// - parameter allowingLongLivedTransaction: When true, the
|
||||
/// ``Configuration/allowsUnsafeTransactions`` configuration flag is
|
||||
/// ignored until this method is called again with false.
|
||||
func reentrantSync<T>(allowingLongLivedTransaction: Bool, _ body: (Database) throws -> T) rethrows -> T {
|
||||
func reentrantSync<T>(allowingLongLivedTransaction: Bool, _ body: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
try reentrantSync { db in
|
||||
self.allowsUnsafeTransactions = allowingLongLivedTransaction
|
||||
return try body(db)
|
||||
@@ -164,7 +164,7 @@ final class SerializedDatabase {
|
||||
/// have finished executing.
|
||||
///
|
||||
/// This method is reentrant.
|
||||
func reentrantSync<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
func reentrantSync<T>(_ block: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
// Three different cases:
|
||||
//
|
||||
// 1. A database is invoked from some queue like the main queue:
|
||||
@@ -228,7 +228,7 @@ final class SerializedDatabase {
|
||||
}
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
func async(_ block: @escaping @Sendable (Database) -> Void) {
|
||||
func async(_ block: @escaping @Sendable (DatabaseBase<API>) -> Void) {
|
||||
queue.async {
|
||||
block(self.db)
|
||||
self.preconditionNoUnsafeTransactionLeft(self.db)
|
||||
@@ -243,14 +243,14 @@ final class SerializedDatabase {
|
||||
/// Executes the block in the current queue.
|
||||
///
|
||||
/// - precondition: the current dispatch queue is valid.
|
||||
func execute<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
func execute<T>(_ block: (DatabaseBase<API>) throws -> T) rethrows -> T {
|
||||
preconditionValidQueue()
|
||||
return try block(db)
|
||||
}
|
||||
|
||||
/// Asynchrously executes the block.
|
||||
func execute<T: Sendable>(
|
||||
_ block: @Sendable (Database) throws -> T
|
||||
_ block: @Sendable (DatabaseBase<API>) throws -> T
|
||||
) async throws -> T {
|
||||
let cancelMutex = Mutex<(@Sendable () -> Void)?>(nil)
|
||||
return try await withTaskCancellationHandler {
|
||||
@@ -295,7 +295,7 @@ final class SerializedDatabase {
|
||||
|
||||
/// Fatal error if a transaction has been left opened.
|
||||
private func preconditionNoUnsafeTransactionLeft(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<API>,
|
||||
_ message: @autoclosure() -> String = "A transaction has been left opened at the end of a database access",
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line)
|
||||
|
||||
+19
-16
@@ -1,19 +1,22 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A raw SQLite statement, suitable for the SQLite C API.
|
||||
public typealias SQLiteStatement = OpaquePointer
|
||||
//public typealias SQLiteStatement = OpaquePointer
|
||||
public struct SQLiteStatementBase<API: SQLiteAPI> {
|
||||
public let rawValue: OpaquePointer
|
||||
}
|
||||
|
||||
extension String {
|
||||
/// SQL statements are separated by semicolons and white spaces.
|
||||
@@ -37,7 +40,7 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
public final class Statement {
|
||||
public final class StatementBase<API: SQLiteAPI> {
|
||||
enum TransactionEffect: Equatable {
|
||||
case beginTransaction
|
||||
case commitTransaction
|
||||
@@ -48,7 +51,7 @@ public final class Statement {
|
||||
}
|
||||
|
||||
/// The raw SQLite statement, suitable for the SQLite C API.
|
||||
public let sqliteStatement: SQLiteStatement
|
||||
public let sqliteStatement: SQLiteStatementBase<API>
|
||||
|
||||
/// The SQL query.
|
||||
public var sql: String {
|
||||
@@ -839,11 +842,11 @@ public protocol StatementBinding {
|
||||
/// - parameter sqliteStatement: An SQLite statement.
|
||||
/// - parameter index: 1-based index to statement arguments.
|
||||
/// - returns: the code returned by the `sqlite3_bind_xxx` function.
|
||||
func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt
|
||||
func bind(to sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, at index: CInt) -> CInt
|
||||
}
|
||||
|
||||
/// Helper function for `withBinding(to:at:do:)` methods.
|
||||
func checkBindingSuccess(code: CInt, sqliteStatement: SQLiteStatement) throws {
|
||||
func checkBindingSuccess(code: CInt, sqliteStatement: SQLiteStatementBase<some SQLiteAPI>) throws {
|
||||
if code == SQLITE_OK { return }
|
||||
let message = String(cString: sqlite3_errmsg(sqlite3_db_handle(sqliteStatement)))
|
||||
let sql = String(cString: sqlite3_sql(sqliteStatement)).trimmedSQLStatement
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
#if canImport(string_h)
|
||||
import string_h
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A type that can decode itself from the low-level C interface to
|
||||
/// SQLite results.
|
||||
@@ -92,10 +92,10 @@ public protocol StatementColumnConvertible {
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
/// - returns: A decoded value, or, if decoding is impossible, nil.
|
||||
static func fromStatement(
|
||||
_ sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: CInt)
|
||||
-> Self?
|
||||
static func fromStatement<API>(
|
||||
_ sqliteStatement: SQLiteStatementBase<API>,
|
||||
atUncheckedIndex index: CInt
|
||||
) -> Self?
|
||||
|
||||
/// Creates an instance from a raw SQLite statement pointer, if possible.
|
||||
///
|
||||
@@ -107,7 +107,7 @@ public protocol StatementColumnConvertible {
|
||||
///
|
||||
/// ```swift
|
||||
/// extension Int64: StatementColumnConvertible {
|
||||
/// public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
/// public init(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
/// self = sqlite3_column_int64(sqliteStatement, index)
|
||||
/// }
|
||||
/// }
|
||||
@@ -120,7 +120,7 @@ public protocol StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
init?(sqliteStatement: SQLiteStatement, index: CInt)
|
||||
init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt)
|
||||
}
|
||||
|
||||
extension StatementColumnConvertible {
|
||||
@@ -128,7 +128,10 @@ extension StatementColumnConvertible {
|
||||
/// Default implementation fails on decoding NULL.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public static func fromStatement(_ sqliteStatement: SQLiteStatement, atUncheckedIndex index: CInt) -> Self? {
|
||||
public static func fromStatement<API>(
|
||||
_ sqliteStatement: SQLiteStatementBase<API>,
|
||||
atUncheckedIndex index: CInt
|
||||
) -> Self? {
|
||||
if sqlite3_column_type(sqliteStatement, index) == SQLITE_NULL {
|
||||
return nil
|
||||
}
|
||||
@@ -298,7 +301,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: A ``FastDatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> FastDatabaseValueCursor<Self>
|
||||
@@ -329,7 +332,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> [Self]
|
||||
@@ -363,7 +366,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Self?
|
||||
@@ -401,7 +404,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible & Hash
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ statement: Statement,
|
||||
_ statement: StatementBase<some SQLiteAPI>,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
throws -> Set<Self>
|
||||
@@ -446,7 +449,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: A ``FastDatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -478,7 +481,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -513,7 +516,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -547,7 +550,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible & Hash
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: (any RowAdapter)? = nil)
|
||||
@@ -606,7 +609,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A ``FastDatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: some FetchRequest)
|
||||
public static func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest)
|
||||
throws -> FastDatabaseValueCursor<Self>
|
||||
{
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
@@ -649,7 +652,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: some FetchRequest) throws -> [Self] {
|
||||
public static func fetchAll(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> [Self] {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -693,7 +696,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - request: A fetch request.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: some FetchRequest) throws -> Self? {
|
||||
public static func fetchOne(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Self? {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
return try fetchOne(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -736,7 +739,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible & Hash
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func fetchSet(_ db: Database, _ request: some FetchRequest) throws -> Set<Self> {
|
||||
public static func fetchSet(_ db: DatabaseBase<some SQLiteAPI>, _ request: some FetchRequest) throws -> Set<Self> {
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchSet(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -789,7 +792,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``FastDatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> FastDatabaseValueCursor<RowDecoder> {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> FastDatabaseValueCursor<RowDecoder> {
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
@@ -827,7 +830,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [RowDecoder] {
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
@@ -868,7 +871,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowDecoder? {
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
@@ -908,7 +911,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<RowDecoder> {
|
||||
try RowDecoder.fetchSet(db, self)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Data is convertible to and from DatabaseValue.
|
||||
extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
if let bytes = sqlite3_column_blob(sqliteStatement, index) {
|
||||
let count = Int(sqlite3_column_bytes(sqliteStatement, index))
|
||||
self.init(bytes: bytes, count: count) // copy bytes
|
||||
@@ -49,7 +49,7 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
withUnsafeBytes {
|
||||
sqlite3_bind_blob(sqliteStatement, index, $0.baseAddress, CInt($0.count), SQLITE_TRANSIENT)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -81,7 +81,7 @@ extension DatabaseDateComponents: StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
guard let cString = sqlite3_column_text(sqliteStatement, index) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -136,7 +136,7 @@ extension Date: StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_INTEGER, SQLITE_FLOAT:
|
||||
self.init(timeIntervalSince1970: sqlite3_column_double(sqliteStatement, index))
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if !os(Linux)
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -50,7 +50,7 @@ extension Decimal: DatabaseValueConvertible {
|
||||
extension Decimal: StatementColumnConvertible {
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_INTEGER:
|
||||
self.init(sqlite3_column_int64(sqliteStatement, index))
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -81,7 +81,7 @@ extension UUID: DatabaseValueConvertible {
|
||||
extension UUID: StatementColumnConvertible {
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_TEXT:
|
||||
let string = String(cString: sqlite3_column_text(sqliteStatement, index)!)
|
||||
|
||||
@@ -20,7 +20,7 @@ extension SQLExpressible where Self: RawRepresentable, Self.RawValue: SQLExpress
|
||||
}
|
||||
|
||||
extension StatementBinding where Self: RawRepresentable, Self.RawValue: StatementBinding {
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
public func bind(to sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, at index: CInt) -> CInt {
|
||||
rawValue.bind(to: sqliteStatement, at: index)
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ extension StatementBinding where Self: RawRepresentable, Self.RawValue: Statemen
|
||||
extension StatementColumnConvertible where Self: RawRepresentable, Self.RawValue: StatementColumnConvertible {
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
guard let rawValue = RawValue(sqliteStatement: sqliteStatement, index: index) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
extension Optional: StatementBinding where Wrapped: StatementBinding {
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
switch self {
|
||||
case .none:
|
||||
return sqlite3_bind_null(sqliteStatement, index)
|
||||
return API.sqlite3_bind_null(sqliteStatement.rawValue, index)
|
||||
case let .some(value):
|
||||
return value.bind(to: sqliteStatement, at: index)
|
||||
}
|
||||
@@ -87,11 +87,11 @@ extension Optional: DatabaseValueConvertible where Wrapped: DatabaseValueConvert
|
||||
extension Optional: StatementColumnConvertible where Wrapped: StatementColumnConvertible {
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public static func fromStatement(_ sqliteStatement: SQLiteStatement, atUncheckedIndex index: CInt) -> Self? {
|
||||
public static func fromStatement<API>(_ sqliteStatement: SQLiteStatementBase<API>, atUncheckedIndex index: CInt) -> Self? {
|
||||
if let value = Wrapped.fromStatement(sqliteStatement, atUncheckedIndex: index) {
|
||||
// Valid value
|
||||
return value
|
||||
} else if sqlite3_column_type(sqliteStatement, index) == SQLITE_NULL {
|
||||
} else if API.sqlite3_column_type(sqliteStatement.rawValue, index) == API.SQLITE_NULL {
|
||||
// NULL
|
||||
return .some(.none)
|
||||
} else {
|
||||
@@ -100,7 +100,7 @@ extension Optional: StatementColumnConvertible where Wrapped: StatementColumnCon
|
||||
}
|
||||
}
|
||||
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
public init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
guard let value = Wrapped(sqliteStatement: sqliteStatement, index: index) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
// MARK: - Value Types
|
||||
|
||||
@@ -20,8 +20,8 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
self = sqlite3_column_int64(sqliteStatement, index) != 0
|
||||
public init<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
self = API.sqlite3_column_int64(sqliteStatement.rawValue, index) != 0
|
||||
}
|
||||
|
||||
/// Returns an INTEGER database value.
|
||||
@@ -102,8 +102,8 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, self ? 1 : 0)
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, self ? 1 : 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = Int(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -141,8 +141,8 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = Int8(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -180,8 +180,8 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int8(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = Int16(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -219,8 +219,8 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int16(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = Int32(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -258,8 +258,8 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int32(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,8 +271,8 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
self = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
self = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
}
|
||||
|
||||
/// Returns an INTEGER database value.
|
||||
@@ -301,8 +301,8 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, self)
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,8 +316,8 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = UInt(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -340,8 +340,8 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,8 +355,8 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = UInt8(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -379,8 +379,8 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt8(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,8 +394,8 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = UInt16(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -418,8 +418,8 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt16(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,8 +433,8 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = UInt32(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -457,8 +457,8 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt32(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,8 +472,8 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - index: The column index.
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
public init?<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
let int64 = API.sqlite3_column_int64(sqliteStatement.rawValue, index)
|
||||
guard let v = UInt64(exactly: int64) else { return nil }
|
||||
self = v
|
||||
}
|
||||
@@ -496,8 +496,8 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt64(exactly: $0) }
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_int64(sqliteStatement.rawValue, index, Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,8 +509,8 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
self = sqlite3_column_double(sqliteStatement, index)
|
||||
public init<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
self = API.sqlite3_column_double(sqliteStatement.rawValue, index)
|
||||
}
|
||||
|
||||
/// Returns a REAL database value.
|
||||
@@ -536,8 +536,8 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_double(sqliteStatement, index, self)
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_double(sqliteStatement.rawValue, index, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,8 +549,8 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
self = Float(sqlite3_column_double(sqliteStatement, index))
|
||||
public init<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
self = Float(API.sqlite3_column_double(sqliteStatement.rawValue, index))
|
||||
}
|
||||
|
||||
/// Returns a REAL database value.
|
||||
@@ -576,8 +576,8 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_double(sqliteStatement, index, Double(self))
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_double(sqliteStatement.rawValue, index, Double(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,8 +589,8 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
self = String(cString: sqlite3_column_text(sqliteStatement, index)!)
|
||||
public init<API>(sqliteStatement: SQLiteStatementBase<API>, index: CInt) {
|
||||
self = String(cString: API.sqlite3_column_text(sqliteStatement.rawValue, index)!)
|
||||
}
|
||||
|
||||
/// Returns a TEXT database value.
|
||||
@@ -619,8 +619,8 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_text(sqliteStatement, index, self, -1, SQLITE_TRANSIENT)
|
||||
public func bind<API>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt) -> CInt {
|
||||
API.sqlite3_bind_text(sqliteStatement.rawValue, index, self, -1, SQLITE_TRANSIENT)
|
||||
}
|
||||
|
||||
/// Calls the given closure after binding a statement argument.
|
||||
@@ -630,9 +630,9 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameter sqliteStatement: An SQLite statement.
|
||||
/// - parameter index: 1-based index to statement arguments.
|
||||
/// - parameter body: The closure to execute when argument is bound.
|
||||
func withBinding<T>(to sqliteStatement: SQLiteStatement, at index: CInt, do body: () throws -> T) throws -> T {
|
||||
func withBinding<API, T>(to sqliteStatement: SQLiteStatementBase<API>, at index: CInt, do body: () throws -> T) throws -> T {
|
||||
try withCString {
|
||||
let code = sqlite3_bind_text(sqliteStatement, index, $0, -1, nil /* SQLITE_STATIC */)
|
||||
let code = API.sqlite3_bind_text(sqliteStatement.rawValue, index, $0, -1, nil /* SQLITE_STATIC */)
|
||||
try checkBindingSuccess(code: code, sqliteStatement: sqliteStatement)
|
||||
return try body()
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import Foundation
|
||||
///
|
||||
/// - ``DefaultTransactionClock``
|
||||
/// - ``CustomTransactionClock``
|
||||
public protocol TransactionClock: Sendable {
|
||||
public protocol TransactionClock<API>: Sendable {
|
||||
associatedtype API: SQLiteAPI
|
||||
|
||||
/// Returns the date of the current transaction.
|
||||
///
|
||||
/// This function is called whenever a transaction starts - precisely
|
||||
@@ -20,31 +22,33 @@ public protocol TransactionClock: Sendable {
|
||||
/// called, and the database connection is not in a transaction.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/c3ref/get_autocommit.html>
|
||||
func now(_ db: Database) throws -> Date
|
||||
func now(_ db: DatabaseBase<API>) throws -> Date
|
||||
}
|
||||
|
||||
extension TransactionClock where Self == DefaultTransactionClock {
|
||||
/// Returns the default clock.
|
||||
public static var `default`: Self { DefaultTransactionClock() }
|
||||
}
|
||||
#warning("TODO: expose a version with default api")
|
||||
//extension TransactionClock where Self == DefaultTransactionClock {
|
||||
// /// Returns the default clock.
|
||||
// public static var `default`: Self { DefaultTransactionClock() }
|
||||
//}
|
||||
|
||||
extension TransactionClock where Self == CustomTransactionClock {
|
||||
/// Returns a custom clock.
|
||||
///
|
||||
/// The provided closure is called whenever a transaction starts - precisely
|
||||
/// speaking, whenever the database connection leaves the auto-commit mode.
|
||||
///
|
||||
/// It is also called when the ``Database/transactionDate`` property is
|
||||
/// called, and the database connection is not in a transaction.
|
||||
public static func custom(_ now: @escaping @Sendable (Database) throws -> Date) -> Self {
|
||||
CustomTransactionClock(now)
|
||||
}
|
||||
}
|
||||
#warning("TODO: expose a version with default api")
|
||||
//extension TransactionClock where Self == CustomTransactionClock {
|
||||
// /// Returns a custom clock.
|
||||
// ///
|
||||
// /// The provided closure is called whenever a transaction starts - precisely
|
||||
// /// speaking, whenever the database connection leaves the auto-commit mode.
|
||||
// ///
|
||||
// /// It is also called when the ``Database/transactionDate`` property is
|
||||
// /// called, and the database connection is not in a transaction.
|
||||
// public static func custom(_ now: @escaping @Sendable (Database) throws -> Date) -> Self {
|
||||
// CustomTransactionClock(now)
|
||||
// }
|
||||
//}
|
||||
|
||||
/// The default transaction clock.
|
||||
public struct DefaultTransactionClock: TransactionClock {
|
||||
public struct DefaultTransactionClock<API: SQLiteAPI>: TransactionClock {
|
||||
/// Returns the start date of the current transaction.
|
||||
public func now(_ db: Database) throws -> Date {
|
||||
public func now(_ db: DatabaseBase<API>) throws -> Date {
|
||||
// An opportunity to fetch transaction time from the database when
|
||||
// SQLite supports the feature.
|
||||
Date()
|
||||
@@ -52,14 +56,14 @@ public struct DefaultTransactionClock: TransactionClock {
|
||||
}
|
||||
|
||||
/// A custom transaction clock.
|
||||
public struct CustomTransactionClock: TransactionClock {
|
||||
let _now: @Sendable (Database) throws -> Date
|
||||
public struct CustomTransactionClock<API: SQLiteAPI>: TransactionClock {
|
||||
let _now: @Sendable (DatabaseBase<API>) throws -> Date
|
||||
|
||||
public init(_ now: @escaping @Sendable (Database) throws -> Date) {
|
||||
public init(_ now: @escaping @Sendable (DatabaseBase<API>) throws -> Date) {
|
||||
self._now = now
|
||||
}
|
||||
|
||||
public func now(_ db: Database) throws -> Date {
|
||||
public func now(_ db: DatabaseBase<API>) throws -> Date {
|
||||
try _now(db)
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
@@ -33,8 +33,8 @@ extension Database {
|
||||
/// the observer lifetime (observation lasts until observer
|
||||
/// is deallocated).
|
||||
public func add(
|
||||
transactionObserver: some TransactionObserver,
|
||||
extent: TransactionObservationExtent = .observerLifetime)
|
||||
transactionObserver: some TransactionObserverBase<API>,
|
||||
extent: DatabaseTransactionObservationExtent = .observerLifetime)
|
||||
{
|
||||
SchedulingWatchdog.preconditionValidQueue(self)
|
||||
guard let observationBroker else { return }
|
||||
@@ -57,7 +57,7 @@ extension Database {
|
||||
/// db.remove(transactionObserver: myObserver)
|
||||
/// }
|
||||
/// ```
|
||||
public func remove(transactionObserver: some TransactionObserver) {
|
||||
public func remove(transactionObserver: some TransactionObserverBase<API>) {
|
||||
SchedulingWatchdog.preconditionValidQueue(self)
|
||||
guard let observationBroker else { return }
|
||||
|
||||
@@ -82,7 +82,7 @@ extension Database {
|
||||
/// ```swift
|
||||
/// /// Inserts a region in the database, and start monitoring upon
|
||||
/// /// successful insertion.
|
||||
/// func startMonitoring(_ db: Database, region: CLRegion) throws {
|
||||
/// func startMonitoring(_ db: DatabaseBase<some SQLiteAPI>, region: CLRegion) throws {
|
||||
/// // Make sure database is inside a transaction
|
||||
/// try db.inSavepoint {
|
||||
///
|
||||
@@ -113,34 +113,9 @@ extension Database {
|
||||
/// - parameter onCommit: A closure executed on transaction commit.
|
||||
/// - parameter onRollback: A closure executed on transaction rollback.
|
||||
public func afterNextTransaction(
|
||||
onCommit: @escaping @Sendable (Database) -> Void,
|
||||
onRollback: @escaping @Sendable (Database) -> Void = { _ in })
|
||||
onCommit: @escaping @Sendable (DatabaseBase<API>) -> Void,
|
||||
onRollback: @escaping @Sendable (DatabaseBase<API>) -> Void = { _ in })
|
||||
{
|
||||
class TransactionHandler: TransactionObserver {
|
||||
let onCommit: @Sendable (Database) -> Void
|
||||
let onRollback: @Sendable (Database) -> Void
|
||||
|
||||
init(
|
||||
onCommit: @escaping @Sendable (Database) -> Void,
|
||||
onRollback: @escaping @Sendable (Database) -> Void
|
||||
) {
|
||||
self.onCommit = onCommit
|
||||
self.onRollback = onRollback
|
||||
}
|
||||
|
||||
// Ignore changes
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { false }
|
||||
func databaseDidChange(with event: DatabaseEvent) { }
|
||||
|
||||
func databaseDidCommit(_ db: Database) {
|
||||
onCommit(db)
|
||||
}
|
||||
|
||||
func databaseDidRollback(_ db: Database) {
|
||||
onRollback(db)
|
||||
}
|
||||
}
|
||||
|
||||
// We don't notify read-only transactions to transaction observers
|
||||
GRDBPrecondition(!isReadOnly, "Read-only transactions are not notified")
|
||||
|
||||
@@ -148,16 +123,42 @@ extension Database {
|
||||
transactionObserver: TransactionHandler(onCommit: onCommit, onRollback: onRollback),
|
||||
extent: .nextTransaction)
|
||||
}
|
||||
|
||||
/// The extent of the observation performed by a ``TransactionObserver``.
|
||||
public enum TransactionObservationExtent: Sendable {
|
||||
/// Observation lasts until observer is deallocated.
|
||||
case observerLifetime
|
||||
/// Observation lasts until the next transaction.
|
||||
case nextTransaction
|
||||
/// Observation lasts until the database is closed.
|
||||
case databaseLifetime
|
||||
}
|
||||
|
||||
fileprivate class TransactionHandler<API: SQLiteAPI>: TransactionObserverBase {
|
||||
let onCommit: @Sendable (DatabaseBase<API>) -> Void
|
||||
let onRollback: @Sendable (DatabaseBase<API>) -> Void
|
||||
|
||||
init(
|
||||
onCommit: @escaping @Sendable (DatabaseBase<API>) -> Void,
|
||||
onRollback: @escaping @Sendable (DatabaseBase<API>) -> Void
|
||||
) {
|
||||
self.onCommit = onCommit
|
||||
self.onRollback = onRollback
|
||||
}
|
||||
|
||||
// Ignore changes
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { false }
|
||||
func databaseDidChange(with event: DatabaseEvent) { }
|
||||
|
||||
func databaseDidCommit(_ db: DatabaseBase<API>) {
|
||||
onCommit(db)
|
||||
}
|
||||
|
||||
func databaseDidRollback(_ db: DatabaseBase<API>) {
|
||||
onRollback(db)
|
||||
}
|
||||
}
|
||||
|
||||
#warning("TODO: export as Database.TransactionObservationExtent")
|
||||
/// The extent of the observation performed by a ``TransactionObserver``.
|
||||
public enum DatabaseTransactionObservationExtent: Sendable {
|
||||
/// Observation lasts until observer is deallocated.
|
||||
case observerLifetime
|
||||
/// Observation lasts until the next transaction.
|
||||
case nextTransaction
|
||||
/// Observation lasts until the database is closed.
|
||||
case databaseLifetime
|
||||
}
|
||||
|
||||
// MARK: - DatabaseObservationBroker
|
||||
@@ -170,8 +171,8 @@ extension Database {
|
||||
/// func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool
|
||||
/// func databaseDidChange(with event: DatabaseEvent)
|
||||
/// func databaseWillCommit() throws
|
||||
/// func databaseDidCommit(_ db: Database)
|
||||
/// func databaseDidRollback(_ db: Database)
|
||||
/// func databaseDidCommit(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
/// func databaseDidRollback(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
/// }
|
||||
///
|
||||
/// First observer is added, and a transaction is started. At this point,
|
||||
@@ -244,8 +245,8 @@ extension Database {
|
||||
///
|
||||
/// After the statement *has been executed*, the broker calls
|
||||
/// observer.databaseDidCommit().
|
||||
class DatabaseObservationBroker {
|
||||
private unowned let database: Database
|
||||
class DatabaseObservationBroker<API: SQLiteAPI> {
|
||||
private unowned let database: DatabaseBase<API>
|
||||
|
||||
/// The savepoint stack allows us to hold database event notifications until
|
||||
/// all savepoints are released. The goal is to only tell transaction
|
||||
@@ -258,10 +259,10 @@ class DatabaseObservationBroker {
|
||||
private var transactionCompletion = TransactionCompletion.none
|
||||
|
||||
/// The registered transaction observers.
|
||||
private var transactionObservations: [TransactionObservation] = []
|
||||
private var transactionObservations: [TransactionObservation<API>] = []
|
||||
|
||||
/// The observers for an individual statement execution.
|
||||
private var statementObservations: [StatementObservation] = [] {
|
||||
private var statementObservations: [StatementObservation<API>] = [] {
|
||||
didSet {
|
||||
let isEmpty = statementObservations.isEmpty
|
||||
if isEmpty != oldValue.isEmpty {
|
||||
@@ -275,22 +276,22 @@ class DatabaseObservationBroker {
|
||||
}
|
||||
}
|
||||
|
||||
init(_ database: Database) {
|
||||
init(_ database: DatabaseBase<API>) {
|
||||
self.database = database
|
||||
}
|
||||
|
||||
// MARK: - Transaction observers
|
||||
|
||||
func add(transactionObserver: some TransactionObserver, extent: Database.TransactionObservationExtent) {
|
||||
func add(transactionObserver: some TransactionObserverBase<API>, extent: DatabaseTransactionObservationExtent) {
|
||||
transactionObservations.append(TransactionObservation(observer: transactionObserver, extent: extent))
|
||||
}
|
||||
|
||||
func remove(transactionObserver: some TransactionObserver) {
|
||||
func remove(transactionObserver: some TransactionObserverBase<API>) {
|
||||
transactionObservations.removeFirst { $0.isWrapping(transactionObserver) }
|
||||
}
|
||||
|
||||
/// Called from ``TransactionObserver/stopObservingDatabaseChangesUntilNextTransaction()``.
|
||||
func disableUntilNextTransaction(transactionObserver: some TransactionObserver) {
|
||||
func disableUntilNextTransaction(transactionObserver: some TransactionObserverBase<API>) {
|
||||
if let observation = transactionObservations.first(where: { $0.isWrapping(transactionObserver) }) {
|
||||
observation.isEnabled = false
|
||||
statementObservations.removeFirst { $0.transactionObservation === observation }
|
||||
@@ -322,7 +323,7 @@ class DatabaseObservationBroker {
|
||||
}
|
||||
|
||||
/// Prepares observation of changes that are about to be performed by the statement.
|
||||
func statementWillExecute(_ statement: Statement) {
|
||||
func statementWillExecute(_ statement: StatementBase<API>) {
|
||||
if !database.isReadOnly && !transactionObservations.isEmpty {
|
||||
// As statement executes, it may trigger database changes that will
|
||||
// be notified to transaction observers. As a consequence, observers
|
||||
@@ -398,7 +399,7 @@ class DatabaseObservationBroker {
|
||||
|
||||
/// May throw the user-provided cancelled commit error, if a transaction
|
||||
/// observer has cancelled a transaction.
|
||||
func statementDidFail(_ statement: Statement) throws {
|
||||
func statementDidFail(_ statement: StatementBase<API>) throws {
|
||||
// Undo statementWillExecute
|
||||
statementObservations = []
|
||||
SchedulingWatchdog.current!.databaseObservationBroker = nil
|
||||
@@ -425,7 +426,7 @@ class DatabaseObservationBroker {
|
||||
/// May throw the user-provided cancelled commit error, if the statement
|
||||
/// commits an empty transaction, and a transaction observer cancels this
|
||||
/// empty transaction.
|
||||
func statementDidExecute(_ statement: Statement) throws {
|
||||
func statementDidExecute(_ statement: StatementBase<API>) throws {
|
||||
// Undo statementWillExecute
|
||||
if transactionObservations.isEmpty == false {
|
||||
statementObservations = []
|
||||
@@ -711,7 +712,7 @@ class DatabaseObservationBroker {
|
||||
func installCommitAndRollbackHooks() {
|
||||
let brokerPointer = Unmanaged.passUnretained(self).toOpaque()
|
||||
|
||||
sqlite3_commit_hook(database.sqliteConnection, { brokerPointer in
|
||||
API.sqlite3_commit_hook(database.sqliteConnection, { brokerPointer in
|
||||
let broker = Unmanaged<DatabaseObservationBroker>.fromOpaque(brokerPointer!).takeUnretainedValue()
|
||||
do {
|
||||
try broker.databaseWillCommit()
|
||||
@@ -725,7 +726,7 @@ class DatabaseObservationBroker {
|
||||
}
|
||||
}, brokerPointer)
|
||||
|
||||
sqlite3_rollback_hook(database.sqliteConnection, { brokerPointer in
|
||||
API.sqlite3_rollback_hook(database.sqliteConnection, { brokerPointer in
|
||||
let broker = Unmanaged<DatabaseObservationBroker>.fromOpaque(brokerPointer!).takeUnretainedValue()
|
||||
switch broker.transactionCompletion {
|
||||
case .cancelledCommit:
|
||||
@@ -741,7 +742,7 @@ class DatabaseObservationBroker {
|
||||
private func installUpdateHook() {
|
||||
let brokerPointer = Unmanaged.passUnretained(self).toOpaque()
|
||||
|
||||
sqlite3_update_hook(
|
||||
API.sqlite3_update_hook(
|
||||
database.sqliteConnection,
|
||||
{ (brokerPointer, updateKind, databaseNameCString, tableNameCString, rowID) in
|
||||
let broker = Unmanaged<DatabaseObservationBroker>.fromOpaque(brokerPointer!).takeUnretainedValue()
|
||||
@@ -774,7 +775,7 @@ class DatabaseObservationBroker {
|
||||
}
|
||||
|
||||
private func uninstallUpdateHook() {
|
||||
sqlite3_update_hook(database.sqliteConnection, nil, nil)
|
||||
API.sqlite3_update_hook(database.sqliteConnection, nil, nil)
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
sqlite3_preupdate_hook(database.sqliteConnection, nil, nil)
|
||||
#endif
|
||||
@@ -800,7 +801,8 @@ class DatabaseObservationBroker {
|
||||
|
||||
// MARK: - TransactionObserver
|
||||
|
||||
public protocol TransactionObserver: AnyObject {
|
||||
public protocol TransactionObserverBase<API>: AnyObject {
|
||||
associatedtype API: SQLiteAPI
|
||||
|
||||
/// Returns whether specific kinds of database changes should be notified
|
||||
/// to the observer.
|
||||
@@ -864,10 +866,10 @@ public protocol TransactionObserver: AnyObject {
|
||||
func databaseWillCommit() throws
|
||||
|
||||
/// Called when a transaction has been committed on disk.
|
||||
func databaseDidCommit(_ db: Database)
|
||||
func databaseDidCommit(_ db: DatabaseBase<API>)
|
||||
|
||||
/// Called when a transaction has been rollbacked.
|
||||
func databaseDidRollback(_ db: Database)
|
||||
func databaseDidRollback(_ db: DatabaseBase<API>)
|
||||
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
/// Called when the database is changed by an insert, update, or
|
||||
@@ -901,7 +903,7 @@ public protocol TransactionObserver: AnyObject {
|
||||
#endif
|
||||
}
|
||||
|
||||
extension TransactionObserver {
|
||||
extension TransactionObserverBase {
|
||||
/// The default implementation does nothing.
|
||||
public func databaseWillCommit() throws { }
|
||||
|
||||
@@ -963,22 +965,25 @@ extension TransactionObserver {
|
||||
// MARK: - TransactionObservation
|
||||
|
||||
/// This class manages the observation extent of a transaction observer
|
||||
final class TransactionObservation {
|
||||
let extent: Database.TransactionObservationExtent
|
||||
final class TransactionObservation<API: SQLiteAPI> {
|
||||
let extent: DatabaseTransactionObservationExtent
|
||||
|
||||
/// A disabled observation is not interested in individual database changes.
|
||||
/// It is still interested in transactions commits & rollbacks.
|
||||
var isEnabled = true
|
||||
|
||||
private weak var weakObserver: (any TransactionObserver)?
|
||||
private var strongObserver: (any TransactionObserver)?
|
||||
private var observer: (any TransactionObserver)? { strongObserver ?? weakObserver }
|
||||
private weak var weakObserver: (any TransactionObserverBase<API>)?
|
||||
private var strongObserver: (any TransactionObserverBase<API>)?
|
||||
private var observer: (any TransactionObserverBase<API>)? {
|
||||
if let strongObserver { return strongObserver }
|
||||
return weakObserver
|
||||
}
|
||||
|
||||
fileprivate var isObserving: Bool {
|
||||
observer != nil
|
||||
}
|
||||
|
||||
init(observer: some TransactionObserver, extent: Database.TransactionObservationExtent) {
|
||||
init(observer: some TransactionObserverBase<API>, extent: DatabaseTransactionObservationExtent) {
|
||||
self.extent = extent
|
||||
switch extent {
|
||||
case .observerLifetime:
|
||||
@@ -991,7 +996,7 @@ final class TransactionObservation {
|
||||
}
|
||||
}
|
||||
|
||||
func isWrapping(_ observer: some TransactionObserver) -> Bool {
|
||||
func isWrapping(_ observer: some TransactionObserverBase<API>) -> Bool {
|
||||
self.observer === observer
|
||||
}
|
||||
|
||||
@@ -1020,7 +1025,7 @@ final class TransactionObservation {
|
||||
try observer?.databaseWillCommit()
|
||||
}
|
||||
|
||||
func databaseDidCommit(_ db: Database) {
|
||||
func databaseDidCommit(_ db: DatabaseBase<API>) {
|
||||
switch extent {
|
||||
case .observerLifetime, .databaseLifetime:
|
||||
observer?.databaseDidCommit(db)
|
||||
@@ -1036,7 +1041,7 @@ final class TransactionObservation {
|
||||
}
|
||||
}
|
||||
|
||||
func databaseDidRollback(_ db: Database) {
|
||||
func databaseDidRollback(_ db: DatabaseBase<API>) {
|
||||
switch extent {
|
||||
case .observerLifetime, .databaseLifetime:
|
||||
observer?.databaseDidRollback(db)
|
||||
@@ -1055,8 +1060,8 @@ final class TransactionObservation {
|
||||
|
||||
/// The observation of one particular statement, by a particular
|
||||
/// transaction observer.
|
||||
struct StatementObservation {
|
||||
var transactionObservation: TransactionObservation
|
||||
struct StatementObservation<API: SQLiteAPI> {
|
||||
var transactionObservation: TransactionObservation<API>
|
||||
|
||||
/// A predicate that filters database events that should be notified.
|
||||
///
|
||||
@@ -1067,7 +1072,7 @@ struct StatementObservation {
|
||||
/// ```
|
||||
var tracksEvent: DatabaseEventPredicate
|
||||
|
||||
init(transactionObservation: TransactionObservation, trackingEvents predicate: DatabaseEventPredicate) {
|
||||
init(transactionObservation: TransactionObservation<API>, trackingEvents predicate: DatabaseEventPredicate) {
|
||||
self.transactionObservation = transactionObservation
|
||||
self.tracksEvent = predicate
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// An instance of WALSnapshot records the state of a WAL mode database for some
|
||||
/// specific point in history.
|
||||
@@ -25,12 +25,12 @@ final class WALSnapshot: @unchecked Sendable {
|
||||
// <https://www.sqlite.org/c3ref/snapshot.html>
|
||||
let sqliteSnapshot: UnsafeMutablePointer<sqlite3_snapshot>
|
||||
|
||||
init(_ db: Database) throws {
|
||||
init(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
var sqliteSnapshot: UnsafeMutablePointer<sqlite3_snapshot>?
|
||||
let code = withUnsafeMutablePointer(to: &sqliteSnapshot) {
|
||||
return sqlite3_snapshot_get(db.sqliteConnection, "main", $0)
|
||||
}
|
||||
guard code == SQLITE_OK else {
|
||||
guard code == API.SQLITE_OK else {
|
||||
// <https://www.sqlite.org/c3ref/snapshot_get.html>
|
||||
//
|
||||
// > The following must be true for sqlite3_snapshot_get() to succeed. [...]
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
///
|
||||
/// `WALSnapshotTransaction` **takes ownership** of its reader
|
||||
/// `SerializedDatabase` (TODO: make it a move-only type eventually).
|
||||
final class WALSnapshotTransaction: @unchecked Sendable {
|
||||
final class WALSnapshotTransactionBase<API: SQLiteAPI>: @unchecked Sendable {
|
||||
// @unchecked because `databaseAccess` is protected by a mutex.
|
||||
|
||||
private struct DatabaseAccess {
|
||||
let reader: SerializedDatabase
|
||||
let reader: SerializedDatabaseBase<API>
|
||||
let release: @Sendable (_ isInsideTransaction: Bool) -> Void
|
||||
|
||||
// MUST be called only once
|
||||
@@ -60,7 +60,7 @@ final class WALSnapshotTransaction: @unchecked Sendable {
|
||||
/// - parameter release: A closure to call when the read-only connection
|
||||
/// is no longer used.
|
||||
init(
|
||||
onReader reader: SerializedDatabase,
|
||||
onReader reader: SerializedDatabaseBase<API>,
|
||||
release: @escaping @Sendable (_ isInsideTransaction: Bool) -> Void)
|
||||
throws
|
||||
{
|
||||
@@ -90,7 +90,7 @@ final class WALSnapshotTransaction: @unchecked Sendable {
|
||||
|
||||
/// Executes database operations in the snapshot transaction, and
|
||||
/// returns their result after they have finished executing.
|
||||
func read<T>(_ value: (Database) throws -> T) throws -> T {
|
||||
func read<T>(_ value: (DatabaseBase<API>) throws -> T) throws -> T {
|
||||
try databaseAccessMutex.withLock { databaseAccess in
|
||||
guard let databaseAccess else {
|
||||
throw DatabaseError.snapshotIsLost()
|
||||
@@ -103,7 +103,7 @@ final class WALSnapshotTransaction: @unchecked Sendable {
|
||||
|
||||
/// Schedules database operations for execution, and
|
||||
/// returns immediately.
|
||||
func asyncRead(_ value: @escaping @Sendable (Result<Database, Error>) -> Void) {
|
||||
func asyncRead(_ value: @escaping @Sendable (Result<DatabaseBase<API>, Error>) -> Void) {
|
||||
databaseAccessMutex.withLock { databaseAccess in
|
||||
guard let databaseAccess else {
|
||||
value(.failure(DatabaseError.snapshotIsLost()))
|
||||
|
||||
@@ -128,7 +128,7 @@ For example:
|
||||
|
||||
```swift
|
||||
extension EvenInteger: StatementColumnConvertible {
|
||||
init?(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
init?(sqliteStatement: SQLiteStatementBase<some SQLiteAPI>, index: CInt) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let value = Int(exactly: int64) else {
|
||||
return nil // Does not fit Int (probably a 32-bit architecture)
|
||||
|
||||
@@ -69,7 +69,7 @@ On insertion, the `Player` record should get fresh `creationDate` and `modificat
|
||||
extension Player: Encodable, MutablePersistableRecord {
|
||||
/// Sets both `creationDate` and `modificationDate` to the
|
||||
/// transaction date, if they are not set yet.
|
||||
mutating func willInsert(_ db: Database) throws {
|
||||
mutating func willInsert(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
if creationDate == nil {
|
||||
creationDate = try db.transactionDate
|
||||
}
|
||||
@@ -182,7 +182,7 @@ extension Player: Encodable, MutablePersistableRecord {
|
||||
|
||||
/// Sets both `creationDate` and `modificationDate` to the
|
||||
/// transaction date, if they are not set yet.
|
||||
mutating func willInsert(_ db: Database) throws {
|
||||
mutating func willInsert(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
if creationDate == nil {
|
||||
creationDate = try db.transactionDate
|
||||
}
|
||||
@@ -311,7 +311,7 @@ You can copy it in your application, or use it as an inspiration. Not all apps h
|
||||
extension Player {
|
||||
/// If the player has a non-nil primary key and a matching row in
|
||||
/// the database, the player is updated. Otherwise, it is inserted.
|
||||
mutating func saveWithTimestamp(_ db: Database) throws {
|
||||
mutating func saveWithTimestamp(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
// Test the presence of id first, so that we don't perform an
|
||||
// update that would surely throw RecordError.recordNotFound.
|
||||
if id == nil {
|
||||
@@ -346,7 +346,7 @@ extension TimestampedRecord {
|
||||
/// `TimestampedRecord` types that customize the `willInsert`
|
||||
/// persistence callback should call `initializeTimestamps` from
|
||||
/// their implementation.
|
||||
mutating func willInsert(_ db: Database) throws {
|
||||
mutating func willInsert(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try initializeTimestamps(db)
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ extension TimestampedRecord {
|
||||
/// It is called automatically before insertion, if your type does not
|
||||
/// customize the `willInsert` persistence callback. If you customize
|
||||
/// this callback, call `initializeTimestamps` from your implementation.
|
||||
mutating func initializeTimestamps(_ db: Database) throws {
|
||||
mutating func initializeTimestamps(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
if creationDate == nil {
|
||||
creationDate = try db.transactionDate
|
||||
}
|
||||
@@ -370,7 +370,7 @@ extension TimestampedRecord {
|
||||
///
|
||||
/// - parameter modificationDate: The modification date. If nil, the
|
||||
/// transaction date is used.
|
||||
mutating func updateWithTimestamp(_ db: Database, modificationDate: Date? = nil) throws {
|
||||
mutating func updateWithTimestamp(_ db: DatabaseBase<some SQLiteAPI>, modificationDate: Date? = nil) throws {
|
||||
self.modificationDate = try modificationDate ?? db.transactionDate
|
||||
try update(db)
|
||||
}
|
||||
@@ -403,7 +403,7 @@ extension TimestampedRecord {
|
||||
/// - returns: Whether the record was changed and updated.
|
||||
@discardableResult
|
||||
mutating func updateChangesWithTimestamp(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
modificationDate: Date? = nil,
|
||||
modify: (inout Self) -> Void)
|
||||
throws -> Bool
|
||||
@@ -431,7 +431,7 @@ extension TimestampedRecord {
|
||||
///
|
||||
/// - parameter modificationDate: The modification date. If nil, the
|
||||
/// transaction date is used.
|
||||
mutating func touch(_ db: Database, modificationDate: Date? = nil) throws {
|
||||
mutating func touch(_ db: DatabaseBase<some SQLiteAPI>, modificationDate: Date? = nil) throws {
|
||||
try updateChanges(db) {
|
||||
$0.modificationDate = try modificationDate ?? db.transactionDate
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ We have seen in the <doc:SingleRowTables#The-Single-Row-Table> section that by d
|
||||
|
||||
```swift
|
||||
// Customize the default PersistableRecord behavior
|
||||
func willUpdate(_ db: Database, columns: Set<String>) throws {
|
||||
func willUpdate(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws {
|
||||
// Insert the default configuration if it does not exist yet.
|
||||
if try !exists(db) {
|
||||
try AppConfiguration.default.insert(db)
|
||||
@@ -141,7 +141,7 @@ The standard GRDB method ``FetchableRecord/fetchOne(_:)`` returns an optional wh
|
||||
```swift
|
||||
/// Returns the persisted configuration, or the default one if the
|
||||
/// database table is empty.
|
||||
static func find(_ db: Database) throws -> AppConfiguration {
|
||||
static func find(_ db: DatabaseBase<some SQLiteAPI>) throws -> AppConfiguration {
|
||||
try fetchOne(db) ?? .default
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ extension AppConfiguration {
|
||||
// Database Access
|
||||
extension AppConfiguration: FetchableRecord, PersistableRecord {
|
||||
// Customize the default PersistableRecord behavior
|
||||
func willUpdate(_ db: Database, columns: Set<String>) throws {
|
||||
func willUpdate(_ db: DatabaseBase<some SQLiteAPI>, columns: Set<String>) throws {
|
||||
// Insert the default configuration if it does not exist yet.
|
||||
if try !exists(db) {
|
||||
try AppConfiguration.default.insert(db)
|
||||
@@ -242,7 +242,7 @@ extension AppConfiguration: FetchableRecord, PersistableRecord {
|
||||
|
||||
/// Returns the persisted configuration, or the default one if the
|
||||
/// database table is empty.
|
||||
static func find(_ db: Database) throws -> AppConfiguration {
|
||||
static func find(_ db: DatabaseBase<some SQLiteAPI>) throws -> AppConfiguration {
|
||||
try fetchOne(db) ?? .default
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ let count = try await writer.read { db in
|
||||
}
|
||||
|
||||
// Shorthand notation:
|
||||
// ⚠️ Converting non-sendable function value to '@Sendable (Database)
|
||||
// ⚠️ Converting non-sendable function value to '@Sendable (DatabaseBase<some SQLiteAPI>)
|
||||
// throws -> Int' may introduce data races.
|
||||
let count = try await writer.read(Player.fetchCount)
|
||||
```
|
||||
|
||||
@@ -160,7 +160,7 @@ This restriction can be left with the ``Configuration/allowsUnsafeTransactions``
|
||||
It is possible to ask if a transaction is currently opened:
|
||||
|
||||
```swift
|
||||
func myCriticalMethod(_ db: Database) throws {
|
||||
func myCriticalMethod(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
precondition(db.isInsideTransaction, "This method requires a transaction")
|
||||
try ...
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func myCriticalMethod(_ db: Database) throws {
|
||||
Yet, there is a better option than checking for transactions. Critical database sections should use savepoints, described below:
|
||||
|
||||
```swift
|
||||
func myCriticalMethod(_ db: Database) throws {
|
||||
func myCriticalMethod(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try db.inSavepoint {
|
||||
// Here the database is guaranteed to be inside a transaction.
|
||||
try ...
|
||||
|
||||
@@ -125,7 +125,7 @@ To instruct GRDB about the primary key, define a **schema source**, a type that
|
||||
struct GameSchemaSource: DatabaseSchemaSource {
|
||||
/// Returns the names of the columns for the primary key in the
|
||||
/// provided database view.
|
||||
func columnsForPrimaryKey(_ db: Database, inView view: DatabaseObjectID) throws -> [String]? {
|
||||
func columnsForPrimaryKey(_ db: DatabaseBase<some SQLiteAPI>, inView view: DatabaseObjectID) throws -> [String]? {
|
||||
["id"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import Foundation
|
||||
|
||||
// MARK: - Dump
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Prints the results of all statements in the provided SQL.
|
||||
///
|
||||
/// For example:
|
||||
@@ -183,7 +183,7 @@ extension Database {
|
||||
|
||||
// MARK: -
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
func _dumpStatements(
|
||||
_ statements: some Cursor<Statement>,
|
||||
format: some DumpFormat,
|
||||
@@ -317,8 +317,8 @@ extension Database {
|
||||
}
|
||||
|
||||
private func ignoresObject(named name: String) throws -> Bool {
|
||||
if Database.isSQLiteInternalTable(name) { return true }
|
||||
if Database.isGRDBInternalTable(name) { return true }
|
||||
if Self.isSQLiteInternalTable(name) { return true }
|
||||
if Self.isGRDBInternalTable(name) { return true }
|
||||
if try isShadowTable(name) { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extension DatabaseReader {
|
||||
extension DatabaseReaderBase {
|
||||
/// Prints the results of all statements in the provided SQL.
|
||||
///
|
||||
/// For example:
|
||||
|
||||
@@ -33,26 +33,28 @@
|
||||
/// - ``writeRow(_:statement:to:)``
|
||||
/// - ``finalize(_:statement:to:)``
|
||||
public protocol DumpFormat {
|
||||
#warning("TODO: incompatible with GRDB 7")
|
||||
/// Writes a row from the given statement.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - db: A connection to the database
|
||||
/// - statement: The iterated statement
|
||||
/// - stream: A stream for text output.
|
||||
mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream) throws
|
||||
|
||||
#warning("TODO: incompatible with GRDB 7")
|
||||
/// All rows from the statement have been printed.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - db: A connection to the database
|
||||
/// - statement: The statement that was iterated.
|
||||
/// - stream: A stream for text output.
|
||||
mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -61,9 +61,9 @@ public struct DebugDumpFormat: Sendable {
|
||||
}
|
||||
|
||||
extension DebugDumpFormat: DumpFormat {
|
||||
public mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
if firstRow {
|
||||
@@ -91,15 +91,15 @@ extension DebugDumpFormat: DumpFormat {
|
||||
stream.write("\n")
|
||||
}
|
||||
|
||||
public mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
firstRow = true
|
||||
}
|
||||
|
||||
private func formattedValue(_ db: Database, in sqliteStatement: SQLiteStatement, at index: CInt) -> String {
|
||||
private func formattedValue(_ db: DatabaseBase<some SQLiteAPI>, in sqliteStatement: SQLiteStatement, at index: CInt) -> String {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_NULL:
|
||||
return nullValue
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -80,9 +80,9 @@ public struct JSONDumpFormat: Sendable {
|
||||
}
|
||||
|
||||
extension JSONDumpFormat: DumpFormat {
|
||||
public mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
throws {
|
||||
if firstRow {
|
||||
@@ -127,9 +127,9 @@ extension JSONDumpFormat: DumpFormat {
|
||||
stream.write("}")
|
||||
}
|
||||
|
||||
public mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
if firstRow {
|
||||
@@ -145,7 +145,7 @@ extension JSONDumpFormat: DumpFormat {
|
||||
firstRow = true
|
||||
}
|
||||
|
||||
private func formattedValue(_ db: Database, in sqliteStatement: SQLiteStatement, at index: CInt) throws -> String {
|
||||
private func formattedValue(_ db: DatabaseBase<some SQLiteAPI>, in sqliteStatement: SQLiteStatement, at index: CInt) throws -> String {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_NULL:
|
||||
return "null"
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -43,9 +43,9 @@ public struct LineDumpFormat: Sendable {
|
||||
}
|
||||
|
||||
extension LineDumpFormat: DumpFormat {
|
||||
public mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
var lines: [(column: String, value: String)] = []
|
||||
@@ -76,9 +76,9 @@ extension LineDumpFormat: DumpFormat {
|
||||
}
|
||||
}
|
||||
|
||||
public mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
if firstRow == false {
|
||||
@@ -88,7 +88,7 @@ extension LineDumpFormat: DumpFormat {
|
||||
}
|
||||
|
||||
func formattedValue(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
in sqliteStatement: SQLiteStatement,
|
||||
at index: CInt)
|
||||
-> String
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -58,9 +58,9 @@ public struct ListDumpFormat: Sendable {
|
||||
}
|
||||
|
||||
extension ListDumpFormat: DumpFormat {
|
||||
public mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
if firstRow {
|
||||
@@ -88,16 +88,16 @@ extension ListDumpFormat: DumpFormat {
|
||||
stream.write("\n")
|
||||
}
|
||||
|
||||
public mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
firstRow = true
|
||||
}
|
||||
|
||||
func formattedValue(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
in sqliteStatement: SQLiteStatement,
|
||||
at index: CInt)
|
||||
-> String
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A format that prints one line per database row, formatting values
|
||||
/// as SQL literals.
|
||||
@@ -47,9 +47,9 @@ public struct QuoteDumpFormat: Sendable {
|
||||
}
|
||||
|
||||
extension QuoteDumpFormat: DumpFormat {
|
||||
public mutating func writeRow(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func writeRow<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
if firstRow {
|
||||
@@ -81,9 +81,9 @@ extension QuoteDumpFormat: DumpFormat {
|
||||
stream.write("\n")
|
||||
}
|
||||
|
||||
public mutating func finalize(
|
||||
_ db: Database,
|
||||
statement: Statement,
|
||||
public mutating func finalize<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
statement: StatementBase<API>,
|
||||
to stream: inout DumpStream)
|
||||
{
|
||||
firstRow = true
|
||||
|
||||
+7
-5
@@ -66,6 +66,7 @@ public struct FTS3 {
|
||||
/// See ``Database/create(virtualTable:options:using:_:)``
|
||||
public init() { }
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Returns an array of tokens found in the string argument.
|
||||
///
|
||||
/// For example:
|
||||
@@ -94,12 +95,13 @@ public struct FTS3 {
|
||||
/// - <https://www.sqlite.org/fts3.html#querying_tokenizers>
|
||||
///
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public static func tokenize(
|
||||
public static func tokenize<API: SQLiteAPI>(
|
||||
_ string: String,
|
||||
withTokenizer tokenizer: FTS3TokenizerDescriptor = .simple)
|
||||
withTokenizer tokenizer: FTS3TokenizerDescriptor = .simple,
|
||||
api: API.Type)
|
||||
throws -> [String]
|
||||
{
|
||||
try DatabaseQueue().inDatabase { db in
|
||||
try DatabaseQueueBase<API>().inDatabase { db in
|
||||
var tokenizerChunks: [String] = []
|
||||
tokenizerChunks.append(tokenizer.name)
|
||||
for option in tokenizer.arguments {
|
||||
@@ -121,7 +123,7 @@ extension FTS3: VirtualTableModule {
|
||||
FTS3TableDefinition()
|
||||
}
|
||||
|
||||
public func moduleArguments(for definition: FTS3TableDefinition, in db: Database) -> [String] {
|
||||
public func moduleArguments(for definition: FTS3TableDefinition, in db: DatabaseBase<some SQLiteAPI>) -> [String] {
|
||||
var arguments = definition.columns
|
||||
if let tokenizer = definition.tokenizer {
|
||||
if tokenizer.arguments.isEmpty {
|
||||
@@ -136,7 +138,7 @@ extension FTS3: VirtualTableModule {
|
||||
return arguments
|
||||
}
|
||||
|
||||
public func database(_ db: Database, didCreate tableName: String, using definition: FTS3TableDefinition) { }
|
||||
public func database(_ db: DatabaseBase<some SQLiteAPI>, didCreate tableName: String, using definition: FTS3TableDefinition) { }
|
||||
}
|
||||
|
||||
/// A `FTS3TableDefinition` lets you define the components of an FTS3
|
||||
|
||||
+34
-14
@@ -22,6 +22,7 @@ public struct FTS3Pattern: Sendable {
|
||||
/// It is guaranteed to be a valid FTS3/4 pattern.
|
||||
public let rawPattern: String
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Creates a pattern from a raw pattern string.
|
||||
///
|
||||
/// The pattern syntax is documented at <https://www.sqlite.org/fts3.html#full_text_index_queries>
|
||||
@@ -37,14 +38,17 @@ public struct FTS3Pattern: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// - throws: A ``DatabaseError`` if the pattern has an invalid syntax.
|
||||
public init(rawPattern: String) throws {
|
||||
public init<API: SQLiteAPI>(
|
||||
rawPattern: String,
|
||||
api: API.Type
|
||||
) throws {
|
||||
// Correctness above all: use SQLite to validate the pattern.
|
||||
//
|
||||
// Invalid patterns have SQLite return an error on the first
|
||||
// call to sqlite3_step() on a statement that matches against
|
||||
// that pattern.
|
||||
do {
|
||||
try DatabaseQueue().inDatabase { db in
|
||||
try DatabaseQueueBase<API>().inDatabase { db in
|
||||
try db.execute(literal: """
|
||||
CREATE VIRTUAL TABLE documents USING fts3();
|
||||
SELECT * FROM documents WHERE content MATCH \(rawPattern);
|
||||
@@ -59,6 +63,7 @@ public struct FTS3Pattern: Sendable {
|
||||
self.rawPattern = rawPattern
|
||||
}
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Creates a pattern that matches any token found in the input string.
|
||||
///
|
||||
/// The result is nil if no pattern could be built.
|
||||
@@ -71,13 +76,17 @@ public struct FTS3Pattern: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS3 pattern.
|
||||
public init?(matchingAnyTokenIn string: String) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple),
|
||||
public init?<API: SQLiteAPI>(
|
||||
matchingAnyTokenIn string: String,
|
||||
api: API.Type
|
||||
) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple, api: api),
|
||||
!tokens.isEmpty
|
||||
else { return nil }
|
||||
try? self.init(rawPattern: tokens.joined(separator: " OR "))
|
||||
try? self.init(rawPattern: tokens.joined(separator: " OR "), api: api)
|
||||
}
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Creates a pattern that matches all tokens found in the input string.
|
||||
///
|
||||
/// The result is nil if no pattern could be built.
|
||||
@@ -90,13 +99,17 @@ public struct FTS3Pattern: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS3 pattern.
|
||||
public init?(matchingAllTokensIn string: String) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple),
|
||||
public init?<API: SQLiteAPI>(
|
||||
matchingAllTokensIn string: String,
|
||||
api: API.Type
|
||||
) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple, api: api),
|
||||
!tokens.isEmpty
|
||||
else { return nil }
|
||||
try? self.init(rawPattern: tokens.joined(separator: " "))
|
||||
try? self.init(rawPattern: tokens.joined(separator: " "), api: api)
|
||||
}
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Creates a pattern that matches all token prefixes found in the input
|
||||
/// string.
|
||||
///
|
||||
@@ -110,13 +123,17 @@ public struct FTS3Pattern: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS3 pattern.
|
||||
public init?(matchingAllPrefixesIn string: String) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple),
|
||||
public init?<API: SQLiteAPI>(
|
||||
matchingAllPrefixesIn string: String,
|
||||
api: API.Type
|
||||
) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple, api: api),
|
||||
!tokens.isEmpty
|
||||
else { return nil }
|
||||
try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " "))
|
||||
try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " "), api: api)
|
||||
}
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Creates a pattern that matches a contiguous string.
|
||||
///
|
||||
/// The result is nil if no pattern could be built.
|
||||
@@ -129,11 +146,14 @@ public struct FTS3Pattern: Sendable {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS3 pattern.
|
||||
public init?(matchingPhrase string: String) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple),
|
||||
public init?<API: SQLiteAPI>(
|
||||
matchingPhrase string: String,
|
||||
api: API.Type
|
||||
) {
|
||||
guard let tokens = try? FTS3.tokenize(string, withTokenizer: .simple, api: api),
|
||||
!tokens.isEmpty
|
||||
else { return nil }
|
||||
try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"")
|
||||
try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"", api: api)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -42,7 +42,10 @@ extension FTS4: VirtualTableModule {
|
||||
FTS4TableDefinition(configuration: configuration)
|
||||
}
|
||||
|
||||
public func moduleArguments(for definition: FTS4TableDefinition, in db: Database) -> [String] {
|
||||
public func moduleArguments(
|
||||
for definition: FTS4TableDefinition,
|
||||
in db: DatabaseBase<some SQLiteAPI>
|
||||
) -> [String] {
|
||||
var arguments: [String] = []
|
||||
|
||||
for column in definition.columns {
|
||||
@@ -95,7 +98,7 @@ extension FTS4: VirtualTableModule {
|
||||
return arguments
|
||||
}
|
||||
|
||||
public func database(_ db: Database, didCreate tableName: String, using definition: FTS4TableDefinition) throws {
|
||||
public func database(_ db: DatabaseBase<some SQLiteAPI>, didCreate tableName: String, using definition: FTS4TableDefinition) throws {
|
||||
switch definition.contentMode {
|
||||
case .raw:
|
||||
break
|
||||
@@ -397,7 +400,7 @@ public final class FTS4ColumnDefinition {
|
||||
@available(*, unavailable)
|
||||
extension FTS4ColumnDefinition: Sendable { }
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Deletes the synchronization triggers for a synchronized FTS4 table.
|
||||
///
|
||||
/// See ``FTS4TableDefinition/synchronize(withTable:)``.
|
||||
|
||||
+18
-15
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -119,7 +119,7 @@ public struct FTS5 {
|
||||
/// Returns a pointer to the `fts5_api` structure.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#extending_fts5>
|
||||
public static func api(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
public static func api(_ db: DatabaseBase<some SQLiteAPI>) -> UnsafePointer<fts5_api> {
|
||||
var statement: SQLiteStatement?
|
||||
var api: UnsafePointer<fts5_api>?
|
||||
let type: StaticString = "fts5_api_ptr"
|
||||
@@ -152,7 +152,10 @@ extension FTS5: VirtualTableModule {
|
||||
}
|
||||
|
||||
/// Don't use this method.
|
||||
public func moduleArguments(for definition: FTS5TableDefinition, in db: Database) throws -> [String] {
|
||||
public func moduleArguments(
|
||||
for definition: FTS5TableDefinition,
|
||||
in db: DatabaseBase<some SQLiteAPI>
|
||||
) throws -> [String] {
|
||||
var arguments: [String] = []
|
||||
|
||||
if definition.columns.isEmpty {
|
||||
@@ -223,7 +226,7 @@ extension FTS5: VirtualTableModule {
|
||||
/// Reserved; part of the VirtualTableModule protocol.
|
||||
///
|
||||
/// See Database.create(virtualTable:options:using:_:)
|
||||
public func database(_ db: Database, didCreate tableName: String, using definition: FTS5TableDefinition) throws {
|
||||
public func database(_ db: DatabaseBase<some SQLiteAPI>, didCreate tableName: String, using definition: FTS5TableDefinition) throws {
|
||||
switch definition.contentMode {
|
||||
case .raw:
|
||||
break
|
||||
@@ -531,7 +534,7 @@ extension Column {
|
||||
public static let rank = Column("rank")
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Deletes the synchronization triggers for a synchronized FTS5 table.
|
||||
public func dropFTS5SynchronizationTriggers(forTable tableName: String) throws {
|
||||
try execute(sql: """
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
/// A type that implements a custom tokenizer for the ``FTS5`` full-text engine.
|
||||
///
|
||||
@@ -34,7 +34,7 @@ public protocol FTS5CustomTokenizer: FTS5Tokenizer {
|
||||
///
|
||||
/// - parameter db: A Database connection
|
||||
/// - parameter arguments: An array of string arguments
|
||||
init(db: Database, arguments: [String]) throws
|
||||
init(db: DatabaseBase<some SQLiteAPI>, arguments: [String]) throws
|
||||
}
|
||||
|
||||
extension FTS5CustomTokenizer {
|
||||
@@ -52,12 +52,12 @@ extension FTS5CustomTokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - FTS5
|
||||
|
||||
private class FTS5TokenizerConstructor {
|
||||
let db: Database
|
||||
let db: DatabaseBase<some SQLiteAPI>
|
||||
let constructor: (Database, [String], UnsafeMutablePointer<OpaquePointer?>?) -> CInt
|
||||
|
||||
init(
|
||||
|
||||
@@ -173,7 +173,7 @@ public struct FTS5Pattern: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - FTS5
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
@@ -194,7 +194,7 @@ extension FTS5Tokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - FTS5
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ public class DatabaseFuture<Value> { }
|
||||
|
||||
extension DatabasePool {
|
||||
@available(*, unavailable, message: "concurrentRead has been removed. Use `asyncConcurrentRead` instead.")
|
||||
public func concurrentRead<T>(_ value: @escaping (Database) throws -> T) -> DatabaseFuture<T> { preconditionFailure() }
|
||||
public func concurrentRead<T>(_ value: @escaping (DatabaseBase<some SQLiteAPI>) throws -> T) -> DatabaseFuture<T> { preconditionFailure() }
|
||||
}
|
||||
|
||||
// swiftlint:enable all
|
||||
@@ -1,7 +1,7 @@
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
// MARK: - JSON
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Validates and minifies a JSON string, with the `JSON` SQL function.
|
||||
///
|
||||
/// For example:
|
||||
@@ -453,7 +453,7 @@ extension Database {
|
||||
|
||||
// MARK: - JSONB
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
public struct JSONValidationOptions: OptionSet, Sendable {
|
||||
public let rawValue: Int
|
||||
|
||||
@@ -791,7 +791,7 @@ extension Database {
|
||||
#else
|
||||
// MARK: - JSON
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
/// Validates and minifies a JSON string, with the `JSON` SQL function.
|
||||
///
|
||||
/// For example:
|
||||
|
||||
@@ -213,7 +213,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
public mutating func registerMigration(
|
||||
_ identifier: String,
|
||||
foreignKeyChecks: ForeignKeyChecks = .deferred,
|
||||
migrate: @escaping @Sendable (Database) throws -> Void)
|
||||
migrate: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> Void)
|
||||
{
|
||||
registerMigration(identifier, foreignKeyChecks: foreignKeyChecks, merging: []) { db, ids in
|
||||
precondition(ids.isEmpty)
|
||||
@@ -314,7 +314,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
_ identifier: String,
|
||||
foreignKeyChecks: ForeignKeyChecks = .deferred,
|
||||
merging mergedIdentifiers: Set<String> = [],
|
||||
migrate: @escaping @Sendable (_ db: Database, _ appliedIdentifiers: Set<String>) throws -> Void)
|
||||
migrate: @escaping @Sendable (_ db: DatabaseBase<some SQLiteAPI>, _ appliedIdentifiers: Set<String>) throws -> Void)
|
||||
{
|
||||
let migrationChecks: Migration.ForeignKeyChecks
|
||||
switch foreignKeyChecks {
|
||||
@@ -382,7 +382,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
/// from succeeding.
|
||||
public func asyncMigrate(
|
||||
_ writer: any DatabaseWriter,
|
||||
completion: @escaping @Sendable (Result<Database, Error>) -> Void)
|
||||
completion: @escaping @Sendable (Result<DatabaseBase<some SQLiteAPI>, Error>) -> Void)
|
||||
{
|
||||
writer.asyncBarrierWriteWithoutTransaction { dbResult in
|
||||
do {
|
||||
@@ -424,7 +424,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
/// try migrator.migrate(dbQueue)
|
||||
/// ```
|
||||
///
|
||||
public func hasSchemaChanges(_ db: Database) throws -> Bool {
|
||||
public func hasSchemaChanges(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool {
|
||||
let appliedIdentifiers = try appliedIdentifiers(db)
|
||||
let knownIdentifiers = Set(_migrations.map { $0.identifier })
|
||||
if !appliedIdentifiers.isSubset(of: knownIdentifiers) {
|
||||
@@ -500,7 +500,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func appliedMigrations(_ db: Database) throws -> [String] {
|
||||
public func appliedMigrations(_ db: DatabaseBase<some SQLiteAPI>) throws -> [String] {
|
||||
let appliedIdentifiers = try self.appliedIdentifiers(db)
|
||||
return _migrations.map { $0.identifier }.filter { appliedIdentifiers.contains($0) }
|
||||
}
|
||||
@@ -509,7 +509,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func appliedIdentifiers(_ db: Database) throws -> Set<String> {
|
||||
public func appliedIdentifiers(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<String> {
|
||||
do {
|
||||
return try String.fetchSet(db, sql: "SELECT identifier FROM grdb_migrations")
|
||||
} catch {
|
||||
@@ -529,7 +529,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func completedMigrations(_ db: Database) throws -> [String] {
|
||||
public func completedMigrations(_ db: DatabaseBase<some SQLiteAPI>) throws -> [String] {
|
||||
let appliedIdentifiers = try appliedMigrations(db)
|
||||
let knownIdentifiers = _migrations.map(\.identifier)
|
||||
return zip(appliedIdentifiers, knownIdentifiers)
|
||||
@@ -542,7 +542,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func hasCompletedMigrations(_ db: Database) throws -> Bool {
|
||||
public func hasCompletedMigrations(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool {
|
||||
try completedMigrations(db).last == _migrations.last?.identifier
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func hasBeenSuperseded(_ db: Database) throws -> Bool {
|
||||
public func hasBeenSuperseded(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool {
|
||||
let appliedIdentifiers = try self.appliedIdentifiers(db)
|
||||
let knownIdentifiers = _migrations.map(\.identifier)
|
||||
return appliedIdentifiers.contains { !knownIdentifiers.contains($0) }
|
||||
@@ -611,7 +611,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private func runMigrations(_ db: Database, upTo targetIdentifier: String) throws {
|
||||
private func runMigrations(_ db: DatabaseBase<some SQLiteAPI>, upTo targetIdentifier: String) throws {
|
||||
try db.execute(sql: "CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)")
|
||||
|
||||
// Subsequent migration must not be applied
|
||||
@@ -643,7 +643,7 @@ public struct DatabaseMigrator: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private func migrate(_ db: Database, upTo targetIdentifier: String) throws {
|
||||
private func migrate(_ db: DatabaseBase<some SQLiteAPI>, upTo targetIdentifier: String) throws {
|
||||
if eraseDatabaseOnSchemaChange {
|
||||
var needsErase = false
|
||||
try db.inTransaction(.deferred) {
|
||||
|
||||
@@ -6,7 +6,7 @@ struct Migration: Sendable {
|
||||
case disabled
|
||||
}
|
||||
|
||||
typealias Migrate = @Sendable (_ db: Database, _ mergedIdentifiers: Set<String>) throws -> Void
|
||||
typealias Migrate = @Sendable (_ db: DatabaseBase<some SQLiteAPI>, _ mergedIdentifiers: Set<String>) throws -> Void
|
||||
|
||||
let identifier: String
|
||||
let mergedIdentifiers: Set<String>
|
||||
@@ -26,7 +26,7 @@ struct Migration: Sendable {
|
||||
self.migrate = migrate
|
||||
}
|
||||
|
||||
func run(_ db: Database, mergedIdentifiers: Set<String>) throws {
|
||||
func run(_ db: DatabaseBase<some SQLiteAPI>, mergedIdentifiers: Set<String>) throws {
|
||||
// Migrations access the raw SQLite schema, without alteration due
|
||||
// to the schemaSource. The goal is to ensure that migrations are
|
||||
// immutable, immune from spooky actions at a distance.
|
||||
@@ -47,13 +47,13 @@ struct Migration: Sendable {
|
||||
}
|
||||
|
||||
|
||||
func deleteMergedIdentifiers(_ db: Database) throws {
|
||||
func deleteMergedIdentifiers(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
if mergedIdentifiers.isEmpty == false {
|
||||
try db.execute(literal: "DELETE FROM grdb_migrations WHERE identifier IN \(mergedIdentifiers)")
|
||||
}
|
||||
}
|
||||
|
||||
private func runWithImmediateForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
|
||||
private func runWithImmediateForeignKeysChecks(_ db: DatabaseBase<some SQLiteAPI>, mergedIdentifiers: Set<String>) throws {
|
||||
try db.inTransaction(.immediate) {
|
||||
try migrate(db, mergedIdentifiers)
|
||||
try updateAppliedIdentifier(db)
|
||||
@@ -61,7 +61,7 @@ struct Migration: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private func runWithDisabledForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
|
||||
private func runWithDisabledForeignKeysChecks(_ db: DatabaseBase<some SQLiteAPI>, mergedIdentifiers: Set<String>) throws {
|
||||
try db.execute(sql: "PRAGMA foreign_keys = OFF")
|
||||
try throwingFirstError(
|
||||
execute: {
|
||||
@@ -76,7 +76,7 @@ struct Migration: Sendable {
|
||||
})
|
||||
}
|
||||
|
||||
private func runWithDeferredForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
|
||||
private func runWithDeferredForeignKeysChecks(_ db: DatabaseBase<some SQLiteAPI>, mergedIdentifiers: Set<String>) throws {
|
||||
// Support for database alterations described at
|
||||
// https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
//
|
||||
@@ -108,7 +108,7 @@ struct Migration: Sendable {
|
||||
})
|
||||
}
|
||||
|
||||
private func updateAppliedIdentifier(_ db: Database) throws {
|
||||
private func updateAppliedIdentifier(_ db: DatabaseBase<some SQLiteAPI>) throws {
|
||||
try deleteMergedIdentifiers(db)
|
||||
try db.execute(literal: "INSERT INTO grdb_migrations (identifier) VALUES (\(identifier))")
|
||||
}
|
||||
|
||||
@@ -173,8 +173,10 @@ extension Association {
|
||||
|
||||
// SelectionRequest conformance
|
||||
extension Association {
|
||||
public func selectWhenConnected(
|
||||
_ selection: @escaping @Sendable (Database) throws -> [any SQLSelectable]
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func selectWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable]
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.selectWhenConnected { db in
|
||||
@@ -183,8 +185,10 @@ extension Association {
|
||||
}
|
||||
}
|
||||
|
||||
public func annotatedWhenConnected(
|
||||
with selection: @escaping @Sendable (Database) throws -> [any SQLSelectable]
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func annotatedWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
with selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable]
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.annotatedWhenConnected { db in
|
||||
@@ -196,8 +200,10 @@ extension Association {
|
||||
|
||||
// FilteredRequest conformance
|
||||
extension Association {
|
||||
public func filterWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func filterWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<API>) throws -> any SQLExpressible
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.filterWhenConnected { db in
|
||||
@@ -209,8 +215,10 @@ extension Association {
|
||||
|
||||
// OrderedRequest conformance
|
||||
extension Association {
|
||||
public func orderWhenConnected(
|
||||
_ orderings: @escaping @Sendable (Database) throws -> [any SQLOrderingTerm]
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func orderWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ orderings: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLOrderingTerm]
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.orderWhenConnected { db in
|
||||
@@ -247,8 +255,10 @@ extension Association {
|
||||
|
||||
// AggregatingRequest conformance
|
||||
extension Association {
|
||||
public func groupWhenConnected(
|
||||
_ expressions: @escaping @Sendable (Database) throws -> [any SQLExpressible]
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func groupWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ expressions: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLExpressible]
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.groupWhenConnected { db in
|
||||
@@ -257,8 +267,10 @@ extension Association {
|
||||
}
|
||||
}
|
||||
|
||||
public func havingWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func havingWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<API>) throws -> any SQLExpressible
|
||||
) -> Self {
|
||||
withDestinationRelation { relation in
|
||||
relation = relation.havingWhenConnected { db in
|
||||
|
||||
@@ -1131,7 +1131,7 @@ public func abs<RowDecoder>(_ aggregate: AssociationAggregate<RowDecoder>)
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_expr.html#castexpr>
|
||||
public func cast<RowDecoder>(
|
||||
_ aggregate: AssociationAggregate<RowDecoder>,
|
||||
as storageClass: Database.StorageClass)
|
||||
as storageClass: DatabaseStorageClass)
|
||||
-> AssociationAggregate<RowDecoder>
|
||||
{
|
||||
aggregate
|
||||
|
||||
@@ -333,7 +333,7 @@ struct SQLCTE {
|
||||
var isRecursive: Bool
|
||||
|
||||
/// The number of columns in the common table expression.
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
func columnCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
if let columns {
|
||||
// No need to hit the database
|
||||
return columns.count
|
||||
|
||||
@@ -106,14 +106,14 @@ extension QueryInterfaceRequest: FetchRequest {
|
||||
.relation(relation)
|
||||
}
|
||||
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
public func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try relation.fetchCount(db)
|
||||
}
|
||||
|
||||
public func makePreparedRequest(
|
||||
_ db: Database,
|
||||
public func makePreparedRequest<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
forSingleResult singleResult: Bool = false)
|
||||
throws -> PreparedRequest
|
||||
throws -> PreparedRequestBase<API>
|
||||
{
|
||||
let generator = SQLQueryGenerator(relation: relation, forSingleResult: singleResult)
|
||||
var preparedRequest = try generator.makePreparedRequest(db)
|
||||
@@ -136,8 +136,10 @@ extension QueryInterfaceRequest: FetchRequest {
|
||||
// MARK: - Request Derivation
|
||||
|
||||
extension QueryInterfaceRequest: SelectionRequest {
|
||||
public func selectWhenConnected(
|
||||
_ selection: @escaping @Sendable (Database) throws -> [any SQLSelectable])
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func selectWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable])
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -373,8 +375,10 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
}.asRequest(of: RowDecoder.ID.self)
|
||||
}
|
||||
|
||||
public func annotatedWhenConnected(
|
||||
with selection: @escaping @Sendable (Database) throws -> [any SQLSelectable])
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func annotatedWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
with selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable])
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -386,8 +390,10 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest: FilteredRequest {
|
||||
public func filterWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible)
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func filterWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<API>) throws -> any SQLExpressible)
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -399,8 +405,10 @@ extension QueryInterfaceRequest: FilteredRequest {
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest: OrderedRequest {
|
||||
public func orderWhenConnected(
|
||||
_ orderings: @escaping @Sendable (Database) throws -> [any SQLOrderingTerm])
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func orderWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ orderings: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLOrderingTerm])
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -467,8 +475,10 @@ extension QueryInterfaceRequest: OrderedRequest {
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest: AggregatingRequest {
|
||||
public func groupWhenConnected(
|
||||
_ expressions: @escaping @Sendable (Database) throws -> [any SQLExpressible])
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func groupWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ expressions: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLExpressible])
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -478,8 +488,10 @@ extension QueryInterfaceRequest: AggregatingRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public func havingWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible)
|
||||
#warning("TODO: expose a version with default api")
|
||||
public func havingWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<API>) throws -> any SQLExpressible)
|
||||
-> Self
|
||||
{
|
||||
with {
|
||||
@@ -619,7 +631,7 @@ extension QueryInterfaceRequest {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func isEmpty(_ db: Database) throws -> Bool {
|
||||
public func isEmpty(_ db: DatabaseBase<some SQLiteAPI>) throws -> Bool {
|
||||
try !SQLRequest("SELECT \(exists())").fetchOne(db)!
|
||||
}
|
||||
}
|
||||
@@ -633,7 +645,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: The number of deleted rows
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func deleteAll(_ db: Database) throws -> Int {
|
||||
public func deleteAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
let statement = try SQLQueryGenerator(relation: relation).makeDeleteStatement(db)
|
||||
var changesCount = 0
|
||||
try db.countChanges(&changesCount, forTable: relation.source.tableName) {
|
||||
@@ -668,11 +680,10 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A prepared statement.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `selection` is not empty.
|
||||
public func deleteAndFetchStatement(
|
||||
_ db: Database,
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement
|
||||
{
|
||||
public func deleteAndFetchStatement<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
selection: [any SQLSelectable]
|
||||
) throws -> StatementBase<API> {
|
||||
GRDBPrecondition(!selection.isEmpty, "Invalid empty selection")
|
||||
return try SQLQueryGenerator(relation: relation).makeDeleteStatement(db, selection: selection)
|
||||
}
|
||||
@@ -706,7 +717,7 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: The result of `select` is not empty.
|
||||
public func deleteAndFetchStatement(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
select: (DatabaseComponents) throws -> [any SQLSelectable]
|
||||
) throws -> Statement
|
||||
where RowDecoder: TableRecord
|
||||
@@ -736,7 +747,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``RecordCursor`` over the deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func deleteAndFetchCursor(_ db: Database)
|
||||
public func deleteAndFetchCursor(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
{
|
||||
@@ -763,7 +774,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func deleteAndFetchAll(_ db: Database)
|
||||
public func deleteAndFetchAll(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
{
|
||||
@@ -789,7 +800,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func deleteAndFetchSet(_ db: Database)
|
||||
public func deleteAndFetchSet(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
{
|
||||
@@ -815,7 +826,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of deleted ids.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func deleteAndFetchIds(_ db: Database)
|
||||
public func deleteAndFetchIds(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> Set<RowDecoder.ID>
|
||||
where RowDecoder: TableRecord & Identifiable,
|
||||
RowDecoder.ID: Hashable & DatabaseValueConvertible & StatementColumnConvertible
|
||||
@@ -852,11 +863,10 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchStatement(
|
||||
_ db: Database,
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement
|
||||
{
|
||||
public func deleteAndFetchStatement<API>(
|
||||
_ db: DatabaseBase<API>,
|
||||
selection: [any SQLSelectable]
|
||||
) throws -> StatementBase<API> {
|
||||
GRDBPrecondition(!selection.isEmpty, "Invalid empty selection")
|
||||
return try SQLQueryGenerator(relation: relation).makeDeleteStatement(db, selection: selection)
|
||||
}
|
||||
@@ -891,7 +901,7 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: The result of `select` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchStatement(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
select: (DatabaseComponents) throws -> [any SQLSelectable]
|
||||
) throws -> Statement
|
||||
where RowDecoder: TableRecord
|
||||
@@ -922,7 +932,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A ``RecordCursor`` over the deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchCursor(_ db: Database)
|
||||
public func deleteAndFetchCursor(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
{
|
||||
@@ -950,7 +960,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: An array of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchAll(_ db: Database)
|
||||
public func deleteAndFetchAll(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
{
|
||||
@@ -977,7 +987,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A set of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchSet(_ db: Database)
|
||||
public func deleteAndFetchSet(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
{
|
||||
@@ -1004,7 +1014,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A set of deleted ids.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchIds(_ db: Database)
|
||||
public func deleteAndFetchIds(_ db: DatabaseBase<some SQLiteAPI>)
|
||||
throws -> Set<RowDecoder.ID>
|
||||
where RowDecoder: TableRecord & Identifiable,
|
||||
RowDecoder.ID: Hashable & DatabaseValueConvertible & StatementColumnConvertible
|
||||
@@ -1025,7 +1035,7 @@ extension QueryInterfaceRequest {
|
||||
|
||||
extension QueryInterfaceRequest {
|
||||
/// The conflict resolution to use for batch updates
|
||||
private var defaultConflictResolutionForUpdate: Database.ConflictResolution {
|
||||
private var defaultConflictResolutionForUpdate: DatabaseConflictResolution {
|
||||
// In order to look for the default conflict resolution, we perform a
|
||||
// runtime check for MutablePersistableRecord, and look for a
|
||||
// user-defined default. Such dynamic dispatch is unusual in GRDB, but
|
||||
@@ -1062,8 +1072,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignment: (DatabaseComponents) throws -> ColumnAssignment
|
||||
) throws -> Int
|
||||
where RowDecoder: TableRecord
|
||||
@@ -1097,8 +1107,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> Int
|
||||
where RowDecoder: TableRecord
|
||||
@@ -1125,8 +1135,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment]) throws -> Int
|
||||
{
|
||||
let conflictResolution = conflictResolution ?? defaultConflictResolutionForUpdate
|
||||
@@ -1164,8 +1174,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: ColumnAssignment...)
|
||||
throws -> Int
|
||||
{
|
||||
@@ -1214,8 +1224,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: The results of `select` and `assignments` results
|
||||
/// are not empty.
|
||||
public func updateAndFetchStatement(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment],
|
||||
select: (DatabaseComponents) -> [any SQLSelectable]
|
||||
) throws -> Statement
|
||||
@@ -1255,8 +1265,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `selection` and `assignments` are not empty.
|
||||
public func updateAndFetchStatement(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment],
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement
|
||||
@@ -1309,8 +1319,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
public func updateAndFetchCursor(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1344,8 +1354,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
public func updateAndFetchCursor(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1388,8 +1398,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
public func updateAndFetchAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1420,8 +1430,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
public func updateAndFetchAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1459,8 +1469,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
public func updateAndFetchSet(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
@@ -1491,8 +1501,8 @@ extension QueryInterfaceRequest {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
public func updateAndFetchSet(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
@@ -1538,8 +1548,8 @@ extension QueryInterfaceRequest {
|
||||
/// are not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchStatement(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment],
|
||||
select: (DatabaseComponents) throws -> [any SQLSelectable]
|
||||
) throws -> Statement
|
||||
@@ -1580,8 +1590,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: `selection` and `assignments` are not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchStatement(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment],
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement
|
||||
@@ -1635,8 +1645,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchCursor(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1671,8 +1681,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchCursor(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1716,8 +1726,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1749,8 +1759,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -1789,8 +1799,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: The result of `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchSet(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
@@ -1822,8 +1832,8 @@ extension QueryInterfaceRequest {
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchSet(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
@@ -2144,7 +2154,7 @@ extension ColumnExpression {
|
||||
/// - parameter willExecuteSupplementaryRequest: A closure executed before a
|
||||
/// supplementary fetch is performed.
|
||||
private func prefetch(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
associations: [_SQLAssociation],
|
||||
from originRelation: SQLRelation,
|
||||
into originRows: [Row],
|
||||
@@ -2311,7 +2321,7 @@ func makePrefetchRequest(
|
||||
// CAUTION: Keep this code in sync with prefetch(_:associations:in:)
|
||||
/// Returns the region of prefetched associations
|
||||
func prefetchedRegion(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
associations: [_SQLAssociation],
|
||||
from originTable: String)
|
||||
throws -> DatabaseRegion
|
||||
@@ -2333,7 +2343,7 @@ throws -> DatabaseRegion
|
||||
|
||||
// CAUTION: Keep this code in sync with prefetch(_:associations:in:)
|
||||
func prefetchedRegion(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
association: _SQLAssociation,
|
||||
pivotMapping: JoinMapping)
|
||||
throws -> DatabaseRegion
|
||||
|
||||
@@ -40,6 +40,7 @@ public protocol TypedRequest<RowDecoder> {
|
||||
/// - ``select(_:)-30yzl``
|
||||
/// - ``select(_:)-7e2y5``
|
||||
public protocol SelectionRequest {
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Defines the result columns.
|
||||
///
|
||||
/// The `selection` parameter is a closure that accepts a database
|
||||
@@ -67,10 +68,12 @@ public protocol SelectionRequest {
|
||||
///
|
||||
/// - parameter selection: A closure that accepts a database connection and
|
||||
/// returns an array of result columns.
|
||||
func selectWhenConnected(
|
||||
_ selection: @escaping @Sendable (Database) throws -> [any SQLSelectable]
|
||||
func selectWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable]
|
||||
) -> Self
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Appends result columns to the selected columns.
|
||||
///
|
||||
/// The `selection` parameter is a closure that accepts a database
|
||||
@@ -89,8 +92,9 @@ public protocol SelectionRequest {
|
||||
///
|
||||
/// - parameter selection: A closure that accepts a database connection and
|
||||
/// returns an array of result columns.
|
||||
func annotatedWhenConnected(
|
||||
with selection: @escaping @Sendable (Database) throws -> [any SQLSelectable]
|
||||
func annotatedWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
with selection: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLSelectable]
|
||||
) -> Self
|
||||
}
|
||||
|
||||
@@ -358,6 +362,7 @@ extension SelectionRequest where Self: TypedRequest, Self.RowDecoder: TableRecor
|
||||
///
|
||||
/// - ``filter(_:)-48a4t``
|
||||
public protocol FilteredRequest {
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Filters the fetched rows with a boolean SQL expression.
|
||||
///
|
||||
/// The `predicate` parameter is a closure that accepts a database
|
||||
@@ -377,8 +382,9 @@ public protocol FilteredRequest {
|
||||
///
|
||||
/// - parameter predicate: A closure that accepts a database connection and
|
||||
/// returns a boolean SQL expression.
|
||||
func filterWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible
|
||||
func filterWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<$API>) throws -> any SQLExpressible
|
||||
) -> Self
|
||||
}
|
||||
|
||||
@@ -747,7 +753,10 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
|
||||
/// let request = try Player...filterWhenConnected(keys: { db in [1, 2, 3] })
|
||||
///
|
||||
/// - parameter keys: A collection of primary keys
|
||||
fileprivate func filterWhenConnected(keys: @escaping @Sendable (Database) throws -> [SQLExpression]) -> Self {
|
||||
fileprivate func filterWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
keys: @escaping @Sendable (DatabaseBase<API>) throws -> [SQLExpression]
|
||||
) -> Self {
|
||||
let databaseTableName = self.databaseTableName
|
||||
return filterWhenConnected { db in
|
||||
// Don't bother removing NULLs. We'd lose CPU cycles, and this does not
|
||||
@@ -992,6 +1001,7 @@ extension TableRequest where Self: AggregatingRequest {
|
||||
/// - ``group(_:)-4216o``
|
||||
/// - ``having(_:)-2ssg9``
|
||||
public protocol AggregatingRequest {
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Returns an aggregate request grouped on the given SQL expressions.
|
||||
///
|
||||
/// The `expressions` parameter is a closure that accepts a database
|
||||
@@ -1014,10 +1024,12 @@ public protocol AggregatingRequest {
|
||||
///
|
||||
/// - parameter expressions: A closure that accepts a database connection
|
||||
/// and returns an array of SQL expressions.
|
||||
func groupWhenConnected(
|
||||
_ expressions: @escaping @Sendable (Database) throws -> [any SQLExpressible]
|
||||
func groupWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ expressions: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLExpressible]
|
||||
) -> Self
|
||||
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Filters the aggregated groups with a boolean SQL expression.
|
||||
///
|
||||
/// The `predicate` parameter is a closure that accepts a database
|
||||
@@ -1040,8 +1052,9 @@ public protocol AggregatingRequest {
|
||||
///
|
||||
/// - parameter predicate: A closure that accepts a database connection and
|
||||
/// returns a boolean SQL expression.
|
||||
func havingWhenConnected(
|
||||
_ predicate: @escaping @Sendable (Database) throws -> any SQLExpressible
|
||||
func havingWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ predicate: @escaping @Sendable (DatabaseBase<API>) throws -> any SQLExpressible
|
||||
) -> Self
|
||||
}
|
||||
|
||||
@@ -1270,6 +1283,7 @@ extension AggregatingRequest where Self: TypedRequest, Self.RowDecoder: TableRec
|
||||
/// - ``order(_:)-63rzl``
|
||||
/// - ``order(_:)-6co0m``
|
||||
public protocol OrderedRequest {
|
||||
#warning("TODO: expose a version with default api")
|
||||
/// Sorts the fetched rows according to the given SQL ordering terms.
|
||||
///
|
||||
/// The `orderings` parameter is a closure that accepts a database
|
||||
@@ -1297,8 +1311,9 @@ public protocol OrderedRequest {
|
||||
///
|
||||
/// - parameter orderings: A closure that accepts a database connection and
|
||||
/// returns an array of SQL ordering terms.
|
||||
func orderWhenConnected(
|
||||
_ orderings: @escaping @Sendable (Database) throws -> [any SQLOrderingTerm]
|
||||
func orderWhenConnected<API: SQLiteAPI>(
|
||||
api: API.Type,
|
||||
_ orderings: @escaping @Sendable (DatabaseBase<API>) throws -> [any SQLOrderingTerm]
|
||||
) -> Self
|
||||
|
||||
/// Returns a request with reversed ordering.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
/// see SQLRelation.filterPromise.
|
||||
struct DatabasePromise<T> {
|
||||
/// Returns the resolved value.
|
||||
let resolve: @Sendable (Database) throws -> T
|
||||
let resolve: @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T
|
||||
|
||||
/// Creates a promise that resolves to a value.
|
||||
init(value: T) where T: Sendable {
|
||||
@@ -31,7 +31,7 @@ struct DatabasePromise<T> {
|
||||
}
|
||||
|
||||
/// Creates a promise from a closure.
|
||||
init(_ resolve: @escaping @Sendable (Database) throws -> T) {
|
||||
init(_ resolve: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> T) {
|
||||
self.resolve = resolve
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public struct SQLExpression: Sendable {
|
||||
/// The `CAST(expr AS storage-class)` expression.
|
||||
///
|
||||
/// See <https://www.sqlite.org/lang_expr.html#castexpr>.
|
||||
indirect case cast(SQLExpression, Database.StorageClass)
|
||||
indirect case cast(SQLExpression, DatabaseStorageClass)
|
||||
|
||||
/// The `BETWEEN` and `NOT BETWEEN` operators.
|
||||
///
|
||||
@@ -1135,7 +1135,7 @@ extension SQLExpression {
|
||||
/// The `CAST(expr AS storage-class)` expression.
|
||||
///
|
||||
/// See <https://www.sqlite.org/lang_expr.html#castexpr>.
|
||||
static func cast(_ expression: SQLExpression, as storageClass: Database.StorageClass) -> Self {
|
||||
static func cast(_ expression: SQLExpression, as storageClass: DatabaseStorageClass) -> Self {
|
||||
self.init(impl: .cast(expression, storageClass))
|
||||
}
|
||||
|
||||
@@ -1193,7 +1193,7 @@ extension SQLExpression {
|
||||
/// The expression as a quoted SQL literal (not public in order to avoid abuses)
|
||||
///
|
||||
/// try "foo'bar".databaseValue.quotedSQL(db) // "'foo''bar'""
|
||||
func quotedSQL(_ db: Database) throws -> String {
|
||||
func quotedSQL(_ db: DatabaseBase<some SQLiteAPI>) throws -> String {
|
||||
let context = SQLGenerationContext(db, argumentsSink: .literalValues)
|
||||
return try sql(context)
|
||||
}
|
||||
@@ -1223,7 +1223,7 @@ extension SQLExpression {
|
||||
/// - parameter acceptsBijection: If true, expressions that define a
|
||||
/// bijection on a column return this column. For example: `-score`
|
||||
/// returns `score`.
|
||||
func column(_ db: Database, for alias: TableAliasBase, acceptsBijection: Bool = false) throws -> String? {
|
||||
func column(_ db: DatabaseBase<some SQLiteAPI>, for alias: TableAliasBase, acceptsBijection: Bool = false) throws -> String? {
|
||||
switch impl {
|
||||
case let .qualifiedColumn(name, a):
|
||||
if alias == a {
|
||||
@@ -1510,7 +1510,7 @@ extension SQLExpression {
|
||||
///
|
||||
/// // SELECT * FROM "player" WHERE "name" = 'Arthur' LIMIT 1
|
||||
/// try Player.filter(Column("name") == "Arthur").fetchOne(db)
|
||||
func identifyingColums(_ db: Database, for alias: TableAliasBase) throws -> Set<String> {
|
||||
func identifyingColums(_ db: DatabaseBase<some SQLiteAPI>, for alias: TableAliasBase) throws -> Set<String> {
|
||||
switch impl {
|
||||
case let .rowValue(expressions):
|
||||
assert(!expressions.isEmpty)
|
||||
@@ -1578,7 +1578,7 @@ extension SQLExpression {
|
||||
/// let request = Player.filter(keys: [1, 2, 3])
|
||||
/// let regionObservation = DatabaseRegionObservation(tracking: request)
|
||||
/// let valueObservation = ValueObservation.tracking(request.fetchAll)
|
||||
func identifyingRowIDs(_ db: Database, for alias: TableAliasBase) throws -> Set<Int64>? {
|
||||
func identifyingRowIDs(_ db: DatabaseBase<some SQLiteAPI>, for alias: TableAliasBase) throws -> Set<Int64>? {
|
||||
switch impl {
|
||||
case let .databaseValue(dbValue):
|
||||
if dbValue.isNull || dbValue == false.databaseValue {
|
||||
@@ -1993,7 +1993,7 @@ struct SQLSimpleFunctionInvocation {
|
||||
isJSONValue: isJSONValue)
|
||||
}
|
||||
|
||||
func column(_ db: Database, for alias: TableAliasBase) throws -> String? {
|
||||
func column(_ db: DatabaseBase<some SQLiteAPI>, for alias: TableAliasBase) throws -> String? {
|
||||
let name = name.uppercased()
|
||||
if ["HEX", "QUOTE"].contains(name) && arguments.count == 1 {
|
||||
return try arguments[0].column(db, for: alias, acceptsBijection: true)
|
||||
|
||||
@@ -21,7 +21,7 @@ struct SQLForeignKeyRequest {
|
||||
}
|
||||
|
||||
/// The (origin, destination) column pairs that join a left table to a right table.
|
||||
func fetchForeignKeyMapping(_ db: Database) throws -> ForeignKeyMapping {
|
||||
func fetchForeignKeyMapping(_ db: DatabaseBase<some SQLiteAPI>) throws -> ForeignKeyMapping {
|
||||
if let originColumns, let destinationColumns {
|
||||
// Total information: no need to query the database schema.
|
||||
GRDBPrecondition(originColumns.count == destinationColumns.count, "Number of columns don't match")
|
||||
@@ -122,7 +122,7 @@ struct SQLForeignKeyRequest {
|
||||
var isView: Bool
|
||||
}
|
||||
|
||||
private func tableType(_ db: Database, for name: String) throws -> TableType? {
|
||||
private func tableType(_ db: DatabaseBase<some SQLiteAPI>, for name: String) throws -> TableType? {
|
||||
for schemaID in try db.fetchSchemaIdentifiers() {
|
||||
if try db.schema(schemaID).containsObjectNamed(name, ofType: .table) {
|
||||
return TableType(isView: false)
|
||||
|
||||
@@ -67,7 +67,7 @@ public func average(_ value: some SQLSpecificExpressible) -> SQLExpression {
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_expr.html#castexpr>
|
||||
public func cast(_ expression: some SQLSpecificExpressible, as storageClass: Database.StorageClass) -> SQLExpression {
|
||||
public func cast(_ expression: some SQLSpecificExpressible, as storageClass: DatabaseStorageClass) -> SQLExpression {
|
||||
.cast(expression.sqlExpression, as: storageClass)
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ extension SQLRelation {
|
||||
/// Convenience factory methods which selects all rows from a table.
|
||||
static func all(
|
||||
fromTable tableName: String,
|
||||
selection: @escaping @Sendable (Database) -> [SQLSelection] = { _ in [.allColumns] })
|
||||
selection: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) -> [SQLSelection] = { _ in [.allColumns] })
|
||||
-> Self
|
||||
{
|
||||
SQLRelation(
|
||||
@@ -197,7 +197,7 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
extension SQLRelation: Refinable {
|
||||
func selectWhenConnected(_ selection: @escaping @Sendable (Database) throws -> [SQLSelection]) -> Self {
|
||||
func selectWhenConnected(_ selection: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> [SQLSelection]) -> Self {
|
||||
with {
|
||||
$0.selectionPromise = DatabasePromise(selection)
|
||||
}
|
||||
@@ -228,7 +228,7 @@ extension SQLRelation: Refinable {
|
||||
}
|
||||
}
|
||||
|
||||
func annotatedWhenConnected(with selection: @escaping @Sendable (Database) throws -> [SQLSelection]) -> Self {
|
||||
func annotatedWhenConnected(with selection: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> [SQLSelection]) -> Self {
|
||||
with {
|
||||
let old = $0.selectionPromise
|
||||
$0.selectionPromise = DatabasePromise { db in
|
||||
@@ -242,7 +242,7 @@ extension SQLRelation: Refinable {
|
||||
annotatedWhenConnected(with: { _ in selection })
|
||||
}
|
||||
|
||||
func filterWhenConnected(_ predicate: @escaping @Sendable (Database) throws -> SQLExpression) -> Self {
|
||||
func filterWhenConnected(_ predicate: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> SQLExpression) -> Self {
|
||||
with {
|
||||
if let old = $0.filterPromise {
|
||||
$0.filterPromise = DatabasePromise { db in
|
||||
@@ -259,7 +259,7 @@ extension SQLRelation: Refinable {
|
||||
filterWhenConnected { _ in predicate }
|
||||
}
|
||||
|
||||
func orderWhenConnected(_ orderings: @escaping @Sendable (Database) throws -> [SQLOrdering]) -> Self {
|
||||
func orderWhenConnected(_ orderings: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> [SQLOrdering]) -> Self {
|
||||
with {
|
||||
$0.ordering = SQLRelation.Ordering(orderings: orderings)
|
||||
}
|
||||
@@ -315,13 +315,13 @@ extension SQLRelation: Refinable {
|
||||
}
|
||||
}
|
||||
|
||||
func groupWhenConnected(_ expressions: @escaping @Sendable (Database) throws -> [SQLExpression]) -> Self {
|
||||
func groupWhenConnected(_ expressions: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> [SQLExpression]) -> Self {
|
||||
with {
|
||||
$0.groupPromise = DatabasePromise(expressions)
|
||||
}
|
||||
}
|
||||
|
||||
func havingWhenConnected(_ predicate: @escaping @Sendable (Database) throws -> SQLExpression) -> Self {
|
||||
func havingWhenConnected(_ predicate: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> SQLExpression) -> Self {
|
||||
with {
|
||||
if let old = $0.havingExpressionPromise {
|
||||
$0.havingExpressionPromise = DatabasePromise { db in
|
||||
@@ -602,7 +602,7 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
extension SQLRelation {
|
||||
func fetchCount(_ db: Database) throws -> Int {
|
||||
func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
guard groupPromise == nil && limit == nil && ctes.isEmpty else {
|
||||
// SELECT ... GROUP BY ...
|
||||
// SELECT ... LIMIT ...
|
||||
@@ -651,7 +651,7 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
// SELECT COUNT(*) FROM (self)
|
||||
private func fetchTrivialCount(_ db: Database) throws -> Int {
|
||||
private func fetchTrivialCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
let countRequest: SQLRequest<Int> = "SELECT COUNT(*) FROM (\(SQLSubquery.relation(unordered())))"
|
||||
return try countRequest.fetchOne(db)!
|
||||
}
|
||||
@@ -716,7 +716,7 @@ extension SQLRelation {
|
||||
}
|
||||
}
|
||||
|
||||
func resolve(_ db: Database) throws -> [SQLOrdering] {
|
||||
func resolve(_ db: DatabaseBase<some SQLiteAPI>) throws -> [SQLOrdering] {
|
||||
switch self {
|
||||
case .terms(let terms):
|
||||
return try terms.resolve(db)
|
||||
@@ -742,7 +742,7 @@ extension SQLRelation {
|
||||
isReversed: false)
|
||||
}
|
||||
|
||||
init(orderings: @escaping @Sendable (Database) throws -> [SQLOrdering]) {
|
||||
init(orderings: @escaping @Sendable (DatabaseBase<some SQLiteAPI>) throws -> [SQLOrdering]) {
|
||||
self.init(
|
||||
elements: [.terms(DatabasePromise(orderings))],
|
||||
isReversed: false)
|
||||
@@ -766,7 +766,7 @@ extension SQLRelation {
|
||||
isReversed: isReversed)
|
||||
}
|
||||
|
||||
func resolve(_ db: Database) throws -> [SQLOrdering] {
|
||||
func resolve(_ db: DatabaseBase<some SQLiteAPI>) throws -> [SQLOrdering] {
|
||||
if isReversed {
|
||||
return try elements.flatMap { try $0.reversed.resolve(db) }
|
||||
} else {
|
||||
@@ -832,7 +832,7 @@ enum SQLAssociationCondition: Sendable {
|
||||
}
|
||||
|
||||
func joinExpression(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
leftAlias: TableAliasBase,
|
||||
rightAlias: TableAliasBase)
|
||||
throws -> SQLExpression?
|
||||
@@ -891,7 +891,7 @@ struct SQLForeignKeyCondition: Equatable {
|
||||
|
||||
/// Turns the foreign key condition into a `JoinMapping` that can feed an
|
||||
/// SQL JOIN clause.
|
||||
func joinMapping(_ db: Database, from originTable: String) throws -> JoinMapping {
|
||||
func joinMapping(_ db: DatabaseBase<some SQLiteAPI>, from originTable: String) throws -> JoinMapping {
|
||||
try foreignKeyRequest(from: originTable)
|
||||
.fetchForeignKeyMapping(db)
|
||||
.joinMapping(originIsLeft: originIsLeft)
|
||||
|
||||
@@ -314,7 +314,7 @@ extension [SQLSelection] {
|
||||
/// This method raises a fatal error if the selection contains a literal,
|
||||
///
|
||||
/// See `SQLSelection.columnCount(_:)` for testability.
|
||||
func columnCount(_ context: SQLGenerationContext) throws -> Int {
|
||||
func columnCount(_ context: SQLGenerationContext<some SQLiteAPI>) throws -> Int {
|
||||
try reduce(0) { acc, selection in
|
||||
guard let count = try selection.columnCount(context) else {
|
||||
// Found an SQL literal:
|
||||
|
||||
@@ -40,7 +40,7 @@ extension SQLSubquery {
|
||||
/// // We know that "SELECT 1 AS a, 2 AS b" selects two columns,
|
||||
/// // so we can find cte columns in the row:
|
||||
/// row.scopes["cte"] // [a:1, b:2]
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
func columnCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
switch impl {
|
||||
case let .literal(sqlLiteral):
|
||||
// Compile request. We can freely use the statement cache because we
|
||||
|
||||
@@ -177,7 +177,7 @@ extension Table where RowDecoder == Row {
|
||||
}
|
||||
|
||||
extension Table: DatabaseRegionConvertible {
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
public func databaseRegion(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseRegion {
|
||||
DatabaseRegion(table: tableName)
|
||||
}
|
||||
}
|
||||
@@ -848,7 +848,7 @@ extension Table {
|
||||
/// ```
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
public func fetchCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try all().fetchCount(db)
|
||||
}
|
||||
}
|
||||
@@ -885,7 +885,7 @@ extension Table where RowDecoder: FetchableRecord {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``RecordCursor`` over fetched records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder> {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> RecordCursor<RowDecoder> {
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
@@ -908,7 +908,7 @@ extension Table where RowDecoder: FetchableRecord {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [RowDecoder] {
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
@@ -928,7 +928,7 @@ extension Table where RowDecoder: FetchableRecord {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowDecoder? {
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
@@ -950,7 +950,7 @@ extension Table where RowDecoder: FetchableRecord & Hashable {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<RowDecoder> {
|
||||
try all().fetchSet(db)
|
||||
}
|
||||
}
|
||||
@@ -987,7 +987,7 @@ extension Table where RowDecoder == Row {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``RowCursor`` over fetched rows.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RowCursor {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowCursor {
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
@@ -1009,7 +1009,7 @@ extension Table where RowDecoder == Row {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [Row] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [Row] {
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
@@ -1028,7 +1028,7 @@ extension Table where RowDecoder == Row {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> Row? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> Row? {
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
|
||||
@@ -1047,7 +1047,7 @@ extension Table where RowDecoder == Row {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<Row> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<Row> {
|
||||
try all().fetchSet(db)
|
||||
}
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ extension Table where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``DatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
@@ -1082,7 +1082,7 @@ extension Table where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [RowDecoder] {
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
@@ -1096,7 +1096,7 @@ extension Table where RowDecoder: DatabaseValueConvertible {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowDecoder? {
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
@@ -1109,7 +1109,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & Hashable {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<RowDecoder> {
|
||||
try all().fetchSet(db)
|
||||
}
|
||||
}
|
||||
@@ -1133,7 +1133,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``FastDatabaseValueCursor`` over fetched values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> FastDatabaseValueCursor<RowDecoder> {
|
||||
public func fetchCursor(_ db: DatabaseBase<some SQLiteAPI>) throws -> FastDatabaseValueCursor<RowDecoder> {
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
@@ -1144,7 +1144,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
public func fetchAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> [RowDecoder] {
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
@@ -1158,7 +1158,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
public func fetchOne(_ db: DatabaseBase<some SQLiteAPI>) throws -> RowDecoder? {
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
@@ -1171,7 +1171,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of values.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
|
||||
public func fetchSet(_ db: DatabaseBase<some SQLiteAPI>) throws -> Set<RowDecoder> {
|
||||
try all().fetchSet(db)
|
||||
}
|
||||
}
|
||||
@@ -1568,7 +1568,7 @@ extension Table {
|
||||
/// - returns: The number of deleted rows
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func deleteAll(_ db: Database) throws -> Int {
|
||||
public func deleteAll(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try all().deleteAll(db)
|
||||
}
|
||||
}
|
||||
@@ -1594,7 +1594,7 @@ extension Table {
|
||||
/// - db: A database connection.
|
||||
/// - key: A primary key value.
|
||||
/// - returns: Whether a row exists for this primary key.
|
||||
public func exists(_ db: Database, key: some DatabaseValueConvertible) throws -> Bool {
|
||||
public func exists(_ db: DatabaseBase<some SQLiteAPI>, key: some DatabaseValueConvertible) throws -> Bool {
|
||||
try !filter(key: key).isEmpty(db)
|
||||
}
|
||||
}
|
||||
@@ -1628,7 +1628,7 @@ where RowDecoder: Identifiable,
|
||||
/// - db: A database connection.
|
||||
/// - id: A primary key value.
|
||||
/// - returns: Whether a row exists for this primary key.
|
||||
public func exists(_ db: Database, id: RowDecoder.ID) throws -> Bool {
|
||||
public func exists(_ db: DatabaseBase<some SQLiteAPI>, id: RowDecoder.ID) throws -> Bool {
|
||||
if id.databaseValue.isNull {
|
||||
// Don't hit the database
|
||||
return false
|
||||
@@ -1665,7 +1665,7 @@ extension Table {
|
||||
/// - db: A database connection.
|
||||
/// - key: A key dictionary.
|
||||
/// - returns: Whether a row exists for this key.
|
||||
public func exists(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
|
||||
public func exists(_ db: DatabaseBase<some SQLiteAPI>, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
|
||||
try !filter(key: key).isEmpty(db)
|
||||
}
|
||||
}
|
||||
@@ -1697,7 +1697,7 @@ extension Table {
|
||||
/// - returns: The number of deleted rows.
|
||||
@discardableResult
|
||||
public func deleteAll(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
keys: some Collection<some DatabaseValueConvertible>
|
||||
) throws -> Int {
|
||||
if keys.isEmpty {
|
||||
@@ -1730,7 +1730,7 @@ extension Table {
|
||||
/// - key: A primary key value.
|
||||
/// - returns: Whether a row was deleted.
|
||||
@discardableResult
|
||||
public func deleteOne(_ db: Database, key: some DatabaseValueConvertible) throws -> Bool {
|
||||
public func deleteOne(_ db: DatabaseBase<some SQLiteAPI>, key: some DatabaseValueConvertible) throws -> Bool {
|
||||
if key.databaseValue.isNull {
|
||||
// Don't hit the database
|
||||
return false
|
||||
@@ -1774,7 +1774,7 @@ where RowDecoder: Identifiable,
|
||||
/// - returns: The number of deleted rows.
|
||||
@discardableResult
|
||||
public func deleteAll(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
ids: some Collection<RowDecoder.ID>
|
||||
) throws -> Int {
|
||||
if ids.isEmpty {
|
||||
@@ -1814,7 +1814,7 @@ where RowDecoder: Identifiable,
|
||||
/// - id: A primary key value.
|
||||
/// - returns: Whether a row was deleted.
|
||||
@discardableResult
|
||||
public func deleteOne(_ db: Database, id: RowDecoder.ID) throws -> Bool {
|
||||
public func deleteOne(_ db: DatabaseBase<some SQLiteAPI>, id: RowDecoder.ID) throws -> Bool {
|
||||
if id.databaseValue.isNull {
|
||||
// Don't hit the database
|
||||
return false
|
||||
@@ -1857,7 +1857,7 @@ extension Table {
|
||||
/// - keys: An array of key dictionaries.
|
||||
/// - returns: The number of deleted rows.
|
||||
@discardableResult
|
||||
public func deleteAll(_ db: Database, keys: [[String: (any DatabaseValueConvertible)?]]) throws -> Int {
|
||||
public func deleteAll(_ db: DatabaseBase<some SQLiteAPI>, keys: [[String: (any DatabaseValueConvertible)?]]) throws -> Int {
|
||||
if keys.isEmpty {
|
||||
// Avoid hitting the database
|
||||
return 0
|
||||
@@ -1896,7 +1896,7 @@ extension Table {
|
||||
/// - key: A key dictionary.
|
||||
/// - returns: Whether a row was deleted.
|
||||
@discardableResult
|
||||
public func deleteOne(_ db: Database, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
|
||||
public func deleteOne(_ db: DatabaseBase<some SQLiteAPI>, key: [String: (any DatabaseValueConvertible)?]) throws -> Bool {
|
||||
try deleteAll(db, keys: [key]) > 0
|
||||
}
|
||||
}
|
||||
@@ -1930,8 +1930,8 @@ extension Table {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignment: (DatabaseComponents) throws -> ColumnAssignment
|
||||
) throws -> Int
|
||||
where RowDecoder: TableRecord
|
||||
@@ -1966,8 +1966,8 @@ extension Table {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
|
||||
) throws -> Int
|
||||
where RowDecoder: TableRecord
|
||||
@@ -1995,8 +1995,8 @@ extension Table {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: [ColumnAssignment])
|
||||
throws -> Int
|
||||
{
|
||||
@@ -2023,8 +2023,8 @@ extension Table {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public func updateAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
_ assignments: ColumnAssignment...)
|
||||
throws -> Int
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ enum SQLColumnGenerator {
|
||||
/// primary key columns in the table that contains the column. If
|
||||
/// the result is nil, the primary key is the hidden rowID.
|
||||
func sql(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
tableName: String,
|
||||
primaryKeyColumns: () throws -> [SQLColumnDescriptor]?)
|
||||
throws -> String
|
||||
@@ -27,7 +27,7 @@ enum SQLColumnGenerator {
|
||||
}
|
||||
|
||||
private func columnSQL(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
column: ColumnDefinition,
|
||||
tableName: String,
|
||||
primaryKeyColumns: () throws -> [SQLColumnDescriptor]?)
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
/// and columns.
|
||||
///
|
||||
/// - It gathers SQL arguments in order to prevent SQL injection.
|
||||
final class SQLGenerationContext {
|
||||
final class SQLGenerationContext<API: SQLiteAPI> {
|
||||
private enum Parent {
|
||||
case none(db: Database, argumentsSink: StatementArgumentsSink)
|
||||
case none(db: DatabaseBase<API>, argumentsSink: StatementArgumentsSink)
|
||||
case context(SQLGenerationContext)
|
||||
}
|
||||
|
||||
/// A database connection.
|
||||
var db: Database {
|
||||
var db: DatabaseBase<API> {
|
||||
switch parent {
|
||||
case let .none(db: db, argumentsSink: _): return db
|
||||
case let .context(context): return context.db
|
||||
@@ -48,7 +48,7 @@ final class SQLGenerationContext {
|
||||
/// - parameter aliases: An array of table aliases to disambiguate.
|
||||
/// - parameter ctes: An dictionary of available CTEs.
|
||||
init(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<API>,
|
||||
argumentsSink: StatementArgumentsSink = StatementArgumentsSink(),
|
||||
aliases: [TableAliasBase] = [],
|
||||
ctes: OrderedDictionary<String, SQLCTE> = [:])
|
||||
|
||||
@@ -5,7 +5,7 @@ struct SQLIndexGenerator {
|
||||
let options: IndexOptions
|
||||
let condition: SQLExpression?
|
||||
|
||||
func sql(_ db: Database) throws -> String {
|
||||
func sql(_ db: DatabaseBase<some SQLiteAPI>) throws -> String {
|
||||
var sql: SQL = "CREATE"
|
||||
|
||||
if options.contains(.unique) {
|
||||
|
||||
@@ -91,14 +91,14 @@ struct SQLQueryGenerator: Refinable {
|
||||
return sql
|
||||
}
|
||||
|
||||
func makePreparedRequest(_ db: Database) throws -> PreparedRequest {
|
||||
try PreparedRequest(
|
||||
func makePreparedRequest<API>(_ db: DatabaseBase<API>) throws -> PreparedRequestBase<API> {
|
||||
try PreparedRequestBase(
|
||||
statement: makeStatement(db),
|
||||
adapter: rowAdapter(SQLGenerationContext(db, ctes: relation.ctes)))
|
||||
}
|
||||
|
||||
/// The number of fetched columns.
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
func columnCount(_ db: DatabaseBase<some SQLiteAPI>) throws -> Int {
|
||||
try relation
|
||||
.selectionPromise
|
||||
.resolve(db)
|
||||
@@ -106,7 +106,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
}
|
||||
|
||||
/// Returns a prepared statement
|
||||
func makeStatement(_ db: Database) throws -> Statement {
|
||||
func makeStatement<API>(_ db: DatabaseBase<API>) throws -> StatementBase<API> {
|
||||
// Build
|
||||
let context = SQLGenerationContext(db)
|
||||
let sql = try requestSQL(context)
|
||||
@@ -149,7 +149,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
///
|
||||
/// The optimized region allows us to track individual rowids, and also
|
||||
/// discard some provably empty requests such as `Player.none()`.
|
||||
private func optimizedSelectedRegion(_ db: Database, _ selectedRegion: DatabaseRegion) throws -> DatabaseRegion {
|
||||
private func optimizedSelectedRegion(_ db: DatabaseBase<some SQLiteAPI>, _ selectedRegion: DatabaseRegion) throws -> DatabaseRegion {
|
||||
var optimizedRegion = selectedRegion
|
||||
|
||||
// Give up unless request feeds from a database table
|
||||
@@ -175,7 +175,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
/// If true, executing this query yields at most one row.
|
||||
/// If false, we don't know how many rows this query returns.
|
||||
private func expectsSingleResult(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
selection: [SQLSelection],
|
||||
filter: SQLExpression?,
|
||||
groupExpressions: [SQLExpression])
|
||||
@@ -207,7 +207,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
|
||||
/// Returns a `DELETE` statement, with `RETURNING` clause if `selection`
|
||||
/// is not empty.
|
||||
func makeDeleteStatement(_ db: Database, selection: [any SQLSelectable] = []) throws -> Statement {
|
||||
func makeDeleteStatement(_ db: DatabaseBase<some SQLiteAPI>, selection: [any SQLSelectable] = []) throws -> Statement {
|
||||
switch try grouping(db) {
|
||||
case .none:
|
||||
guard relation.joins.isEmpty else {
|
||||
@@ -252,7 +252,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
|
||||
/// DELETE FROM table WHERE id IN (SELECT id FROM table ...)
|
||||
/// DELETE FROM table WHERE id IN (SELECT id FROM table ...) RETURNING ...
|
||||
private func makeTrivialDeleteStatement(_ db: Database, selection: [any SQLSelectable]) throws -> Statement {
|
||||
private func makeTrivialDeleteStatement(_ db: DatabaseBase<some SQLiteAPI>, selection: [any SQLSelectable]) throws -> Statement {
|
||||
let tableName = relation.source.tableName
|
||||
let alias = TableAlias(tableName: tableName)
|
||||
let context = SQLGenerationContext(db, aliases: [alias])
|
||||
@@ -280,8 +280,8 @@ struct SQLQueryGenerator: Refinable {
|
||||
///
|
||||
/// Returns nil if assignments is empty.
|
||||
func makeUpdateStatement(
|
||||
_ db: Database,
|
||||
conflictResolution: Database.ConflictResolution,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
conflictResolution: DatabaseConflictResolution,
|
||||
assignments: [ColumnAssignment],
|
||||
selection: [any SQLSelectable] = [])
|
||||
throws -> Statement?
|
||||
@@ -354,8 +354,8 @@ struct SQLQueryGenerator: Refinable {
|
||||
/// UPDATE table SET ... WHERE id IN (SELECT id FROM table ...) RETURNING ...
|
||||
/// Returns nil if assignments is empty
|
||||
private func makeTrivialUpdateStatement(
|
||||
_ db: Database,
|
||||
conflictResolution: Database.ConflictResolution,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
conflictResolution: DatabaseConflictResolution,
|
||||
assignments: [ColumnAssignment],
|
||||
selection: [any SQLSelectable])
|
||||
throws -> Statement?
|
||||
@@ -401,7 +401,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
|
||||
// Support for the RETURNING clause
|
||||
private func makeStatement(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
sql: String,
|
||||
arguments: StatementArguments,
|
||||
returning selection: [any SQLSelectable],
|
||||
@@ -471,7 +471,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
}
|
||||
|
||||
/// Informs about the query grouping
|
||||
private func grouping(_ db: Database) throws -> GroupingInfo {
|
||||
private func grouping(_ db: DatabaseBase<some SQLiteAPI>) throws -> GroupingInfo {
|
||||
// Empty group clause: no grouping
|
||||
// SELECT * FROM player
|
||||
guard let groupExpressions = try relation.groupPromise?.resolve(db), groupExpressions.isEmpty == false else {
|
||||
|
||||
@@ -9,7 +9,7 @@ struct SQLTableAlterationGenerator {
|
||||
private var name: String
|
||||
private var alterations: [TableAlterationKind] = []
|
||||
|
||||
func sql(_ db: Database) throws -> String {
|
||||
func sql(_ db: DatabaseBase<some SQLiteAPI>) throws -> String {
|
||||
var statements: [String] = []
|
||||
|
||||
for alteration in alterations {
|
||||
|
||||
@@ -17,10 +17,10 @@ struct SQLTableGenerator {
|
||||
|
||||
struct KeyConstraint {
|
||||
var columns: [String]
|
||||
var conflictResolution: Database.ConflictResolution?
|
||||
var conflictResolution: DatabaseConflictResolution?
|
||||
}
|
||||
|
||||
func sql(_ db: Database) throws -> String {
|
||||
func sql(_ db: DatabaseBase<some SQLiteAPI>) throws -> String {
|
||||
var statements: [String] = []
|
||||
|
||||
do {
|
||||
@@ -156,12 +156,12 @@ struct SQLTableGenerator {
|
||||
}
|
||||
|
||||
extension SQLTableGenerator {
|
||||
init(_ db: Database, table: TableDefinition) throws {
|
||||
init(_ db: DatabaseBase<some SQLiteAPI>, table: TableDefinition) throws {
|
||||
var indexOptions: IndexOptions = []
|
||||
if table.options.contains(.ifNotExists) { indexOptions.insert(.ifNotExists) }
|
||||
|
||||
func makeKeyConstraint(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
constraint: TableDefinition.KeyConstraint,
|
||||
forwardPrimaryKey: SQLPrimaryKeyDescriptor)
|
||||
throws -> SQLTableGenerator.KeyConstraint
|
||||
@@ -258,7 +258,7 @@ extension SQLTableGenerator {
|
||||
}
|
||||
|
||||
private static func forwardPrimaryKeyColumns(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
primaryKeyConstraint: TableDefinition.KeyConstraint,
|
||||
originTable: String)
|
||||
throws -> [SQLColumnDescriptor]?
|
||||
@@ -291,7 +291,7 @@ extension SQLTableGenerator {
|
||||
}
|
||||
|
||||
private static func makeForeignKeyGenerator(
|
||||
_ db: Database,
|
||||
_ db: DatabaseBase<some SQLiteAPI>,
|
||||
foreignKey: ForeignKeyDefinition,
|
||||
originTable: String,
|
||||
forwardPrimaryKey: SQLPrimaryKeyDescriptor?,
|
||||
@@ -464,7 +464,7 @@ struct SQLPrimaryKeyDescriptor {
|
||||
}
|
||||
|
||||
extension SQLPrimaryKeyDescriptor {
|
||||
static func find(_ db: Database, table: String) throws -> Self {
|
||||
static func find(_ db: DatabaseBase<some SQLiteAPI>, table: String) throws -> Self {
|
||||
let columnInfos = try db.primaryKey(table).columnInfos
|
||||
return SQLPrimaryKeyDescriptor(
|
||||
tableName: table,
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
public final class ColumnDefinition {
|
||||
enum Indexing {
|
||||
case index
|
||||
case unique(Database.ConflictResolution)
|
||||
case unique(DatabaseConflictResolution)
|
||||
}
|
||||
|
||||
struct ForeignKeyConstraint {
|
||||
@@ -90,9 +90,9 @@ public final class ColumnDefinition {
|
||||
|
||||
let name: String
|
||||
let type: Database.ColumnType?
|
||||
var primaryKey: (conflictResolution: Database.ConflictResolution?, autoincrement: Bool)?
|
||||
var primaryKey: (conflictResolution: DatabaseConflictResolution?, autoincrement: Bool)?
|
||||
var indexing: Indexing?
|
||||
var notNullConflictResolution: Database.ConflictResolution?
|
||||
var notNullConflictResolution: DatabaseConflictResolution?
|
||||
var checkConstraints: [SQLExpression] = []
|
||||
var foreignKeyConstraints: [ForeignKeyConstraint] = []
|
||||
var defaultExpression: SQLExpression?
|
||||
@@ -133,7 +133,7 @@ public final class ColumnDefinition {
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func primaryKey(
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
autoincrement: Bool = false)
|
||||
-> Self
|
||||
{
|
||||
@@ -159,7 +159,7 @@ public final class ColumnDefinition {
|
||||
/// - parameter conflictResolution: An optional ``Database/ConflictResolution``.
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func notNull(onConflict conflictResolution: Database.ConflictResolution? = nil) -> Self {
|
||||
public func notNull(onConflict conflictResolution: DatabaseConflictResolution? = nil) -> Self {
|
||||
notNullConflictResolution = conflictResolution ?? .abort
|
||||
return self
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public final class ColumnDefinition {
|
||||
/// - parameter conflictResolution: An optional ``Database/ConflictResolution``.
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func unique(onConflict conflictResolution: Database.ConflictResolution? = nil) -> Self {
|
||||
public func unique(onConflict conflictResolution: DatabaseConflictResolution? = nil) -> Self {
|
||||
indexing = .unique(conflictResolution ?? .abort)
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Database Schema
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class ForeignKeyDefinition {
|
||||
var updateAction: Database.ForeignKeyAction?
|
||||
var indexing: Indexing?
|
||||
var isDeferred: Bool
|
||||
var notNullConflictResolution: Database.ConflictResolution?
|
||||
var notNullConflictResolution: DatabaseConflictResolution?
|
||||
|
||||
init(
|
||||
name: String,
|
||||
@@ -59,7 +59,7 @@ public final class ForeignKeyDefinition {
|
||||
/// - returns: `self` so that you can further refine the definition of
|
||||
/// the association.
|
||||
@discardableResult
|
||||
public func notNull(onConflict conflictResolution: Database.ConflictResolution? = nil) -> Self {
|
||||
public func notNull(onConflict conflictResolution: DatabaseConflictResolution? = nil) -> Self {
|
||||
notNullConflictResolution = conflictResolution ?? .abort
|
||||
return self
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public final class ForeignKeyDefinition {
|
||||
return self
|
||||
}
|
||||
|
||||
func primaryKey(_ db: Database) throws -> SQLPrimaryKeyDescriptor {
|
||||
func primaryKey(_ db: DatabaseBase<some SQLiteAPI>) throws -> SQLPrimaryKeyDescriptor {
|
||||
if let table {
|
||||
return try SQLPrimaryKeyDescriptor.find(db, table: table)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public struct IndexOptions: OptionSet, Sendable {
|
||||
public static let unique = IndexOptions(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
static func defaultIndexName(on table: String, columns: [String]) -> String {
|
||||
"index_\(table)_on_\(columns.joined(separator: "_"))"
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ public final class TableDefinition {
|
||||
case foreignKeyDefinition(ForeignKeyDefinition)
|
||||
}
|
||||
var components: [Component]
|
||||
var conflictResolution: Database.ConflictResolution?
|
||||
var conflictResolution: DatabaseConflictResolution?
|
||||
|
||||
init(components: [Component], conflictResolution: Database.ConflictResolution?) {
|
||||
init(components: [Component], conflictResolution: DatabaseConflictResolution?) {
|
||||
self.components = components
|
||||
self.conflictResolution = conflictResolution
|
||||
}
|
||||
|
||||
init(columns: [String], conflictResolution: Database.ConflictResolution?) {
|
||||
init(columns: [String], conflictResolution: DatabaseConflictResolution?) {
|
||||
let components = columns.map { name in
|
||||
Component.columnName(name)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public final class TableDefinition {
|
||||
@discardableResult
|
||||
public func autoIncrementedPrimaryKey(
|
||||
_ name: String,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil)
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil)
|
||||
-> ColumnDefinition
|
||||
{
|
||||
column(name, .integer).primaryKey(onConflict: conflictResolution, autoincrement: true)
|
||||
@@ -172,7 +172,7 @@ public final class TableDefinition {
|
||||
public func primaryKey(
|
||||
_ name: String,
|
||||
_ type: Database.ColumnType,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil)
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil)
|
||||
-> ColumnDefinition
|
||||
{
|
||||
let pk = column(name, type).primaryKey(onConflict: conflictResolution)
|
||||
@@ -208,7 +208,7 @@ public final class TableDefinition {
|
||||
///
|
||||
/// A NOT NULL constraint is always added to the wrapped primary key columns.
|
||||
public func primaryKey(
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
onConflict conflictResolution: DatabaseConflictResolution? = nil,
|
||||
body: () throws -> Void)
|
||||
rethrows
|
||||
{
|
||||
@@ -318,7 +318,7 @@ public final class TableDefinition {
|
||||
/// - parameter columns: The primary key columns.
|
||||
/// - parameter conflictResolution: An optional conflict resolution
|
||||
/// (see <https://www.sqlite.org/lang_conflict.html>).
|
||||
public func primaryKey(_ columns: [String], onConflict conflictResolution: Database.ConflictResolution? = nil) {
|
||||
public func primaryKey(_ columns: [String], onConflict conflictResolution: DatabaseConflictResolution? = nil) {
|
||||
guard primaryKeyConstraint == nil else {
|
||||
// Programmer error
|
||||
fatalError("can't define several primary keys")
|
||||
@@ -360,7 +360,7 @@ public final class TableDefinition {
|
||||
/// - parameter columns: The unique key columns.
|
||||
/// - parameter conflictResolution: An optional conflict resolution
|
||||
/// (see <https://www.sqlite.org/lang_conflict.html>).
|
||||
public func uniqueKey(_ columns: [String], onConflict conflictResolution: Database.ConflictResolution? = nil) {
|
||||
public func uniqueKey(_ columns: [String], onConflict conflictResolution: DatabaseConflictResolution? = nil) {
|
||||
uniqueKeyConstraints.append(KeyConstraint(columns: columns, conflictResolution: conflictResolution))
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public protocol VirtualTableModule {
|
||||
|
||||
/// Execute any relevant database statement after the virtual table has
|
||||
/// been created.
|
||||
func database(_ db: Database, didCreate tableName: String, using definition: TableDefinition) throws
|
||||
func database(_ db: DatabaseBase<some SQLiteAPI>, didCreate tableName: String, using definition: TableDefinition) throws
|
||||
}
|
||||
|
||||
// TODO: Question the existence of this API. VirtualTableConfiguration was
|
||||
@@ -79,7 +79,7 @@ public struct VirtualTableOptions: OptionSet, Sendable {
|
||||
public static let temporary = VirtualTableOptions(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
extension Database {
|
||||
extension DatabaseBase {
|
||||
|
||||
// MARK: - Database Schema
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ public struct PersistenceContainer: Sendable {
|
||||
|
||||
/// Convenience initializer from a database connection and a record
|
||||
@usableFromInline
|
||||
init(_ db: Database, _ record: some EncodableRecord & TableRecord) throws {
|
||||
init(_ db: DatabaseBase<some SQLiteAPI>, _ record: some EncodableRecord & TableRecord) throws {
|
||||
let databaseTableName = type(of: record).databaseTableName
|
||||
let columnCount = try db.columns(in: databaseTableName).count
|
||||
self.init(minimumCapacity: columnCount) // Optimization
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
import SQLite3
|
||||
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
// #elseif SomeTrait
|
||||
// import ...
|
||||
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
import GRDBSQLite
|
||||
#endif
|
||||
//// Import C SQLite functions
|
||||
//#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
//import SQLCipher
|
||||
//#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
|
||||
//import SQLite3
|
||||
//#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
|
||||
//// #elseif SomeTrait
|
||||
//// import ...
|
||||
//#else // Default SPM trait must be the default. It impossible to detect from Xcode.
|
||||
//import GRDBSQLite
|
||||
//#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
Loaded 100 of 189 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user