mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Merge branch 'development'
This commit is contained in:
commit
e76cda27dc
148 files changed
+1606
-773
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
## https://github.com/github/gitignore/blob/master/Global/OSX.gitignore
|
||||
## https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
|
||||
@@ -4,6 +4,46 @@ Here is a list of people who were happy to meet GRDB :-)
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/DamienPetrilli/status/1623922310976786433
|
||||
|
||||
> I can't overstate how much more productive I am since I ditched the obsolete Core Data framework and started to use GRDB instead.
|
||||
>
|
||||
> The hard stuff is doable, and the simple stuff is even simpler, as it should be.
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/fullqueuedev/status/1603350969357684736
|
||||
|
||||
> Yes, I much prefer GRDB. I’ve tested many SQLite wrappers over the years 💜
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/cassiuspacheco/status/1574948903857770497
|
||||
|
||||
> SQLite using @groue’s GRDB, no brainer! Awesome documentation, support and beautifully designed.
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/simrandotdev/status/1552004471122587649
|
||||
|
||||
> We get Core Data from Apple which is the worst library to deal with.
|
||||
> Then there is Realm which is nice but again you do not get the RAW SQL power as it is its own type of Db.
|
||||
> Then comes the most beautiful library every written which is very close to Room called GRDB.
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/bellebcooper/status/1534070340850094080
|
||||
|
||||
> When I first started using GRDB I didn't know SQL or much at all about databases 😬 So I've always really liked the query API. But these days I really appreciate that you support raw SQL too, because it gives me more control and freedom when I need it. 👍👍👍
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/mikeash/status/1504810545429499909
|
||||
|
||||
> Another cool library using SQL interpolation!
|
||||
|
||||
---
|
||||
|
||||
https://twitter.com/swiftkarim/status/1354753451377483781
|
||||
|
||||
> I cannot recommend GRDB enough. It works well with Swift and eliminates whole classes of potential programming errors that can be made with Core Data. Also being able to use raw SQL queries if needed can be extremely useful!
|
||||
|
||||
+20
-7
@@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
#### 6.x Releases
|
||||
|
||||
- `6.7.x` Releases - [6.7.0](#670)
|
||||
- `6.6.x` Releases - [6.6.0](#660) - [6.6.1](#661)
|
||||
- `6.5.x` Releases - [6.5.0](#650)
|
||||
- `6.4.x` Releases - [6.4.0](#640)
|
||||
@@ -104,6 +105,18 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
---
|
||||
|
||||
## 6.7.0
|
||||
|
||||
Released February 19, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.6.1...v6.7.0)
|
||||
|
||||
- **Fixed**: [#1316](https://github.com/groue/GRDB.swift/pull/1316) and [#1320](https://github.com/groue/GRDB.swift/pull/1320) by [@baekteun](https://github.com/baekteun): Replace "OSX" with "macOS".
|
||||
- **Fixed**: [#1328](https://github.com/groue/GRDB.swift/pull/1328) by [@ytti](https://github.com/ytti): Fix documentation about Data passphrases.
|
||||
- **Fixed**: [#1327](https://github.com/groue/GRDB.swift/pull/1327) by [@groue](https://github.com/groue): Remove dependency on any specific SwiftLint version.
|
||||
- **New**: [#1331](https://github.com/groue/GRDB.swift/pull/1331) by [@groue](https://github.com/groue): Transaction Date
|
||||
- **New**: [#1336](https://github.com/groue/GRDB.swift/pull/1336) by [@groue](https://github.com/groue): Enable FTS5 by default
|
||||
- **Documentation Update**: The new [Record Timestamps and Transaction Date](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/recordtimestamps) article explains how applications can save the creation and modification date of records.
|
||||
- Added support for `Table` in SQL interpolation.
|
||||
|
||||
## 6.6.1
|
||||
|
||||
Released January 15, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.6.0...v6.6.1)
|
||||
@@ -3660,7 +3673,7 @@ It comes with breaking changes, but the good news is that they are the last (unt
|
||||
|
||||
As a matter of fact, GRDB 1.0 still supports Xcode 8.1 and Swift 3.0. But future versions are free to use Swift 3.1 features, and will require Xcode 8.3+.
|
||||
|
||||
The targetted operating systems are unchanged: iOS 8.0+ / OSX 10.9+ / watchOS 2.0+
|
||||
The targetted operating systems are unchanged: iOS 8.0+ / macOS 10.9+ / watchOS 2.0+
|
||||
|
||||
- **[Record types](https://github.com/groue/GRDB.swift#records) have their `persistentDictionary` property replaced with the `encode(to:)` method:**
|
||||
|
||||
@@ -5468,11 +5481,11 @@ Released May 17, 2016
|
||||
|
||||
**Fixed**
|
||||
|
||||
- Restored support for iOS before 8.2 and OS X before 10.10. Fixes [#51](https://github.com/groue/GRDB.swift/issues/51).
|
||||
- Restored support for iOS before 8.2 and macOS before 10.10. Fixes [#51](https://github.com/groue/GRDB.swift/issues/51).
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- Support for advanced migrations is not available until iOS 8.2 and OS X 10.10:
|
||||
- Support for advanced migrations is not available until iOS 8.2 and macOS 10.10:
|
||||
|
||||
```diff
|
||||
struct DatabaseMigrator {
|
||||
@@ -5528,7 +5541,7 @@ Released May 10, 2016
|
||||
|
||||
**New**
|
||||
|
||||
- `FetchedRecordsController` is now exposed in OSX CocoaPods framework ([documentation](https://github.com/groue/GRDB.swift#fetchedrecordscontroller))
|
||||
- `FetchedRecordsController` is now exposed in macOS CocoaPods framework ([documentation](https://github.com/groue/GRDB.swift#fetchedrecordscontroller))
|
||||
|
||||
**Fixed**
|
||||
|
||||
@@ -5661,7 +5674,7 @@ Released April 5, 2016
|
||||
|
||||
**Fixed**
|
||||
|
||||
- Restored CocoaPods support for iOS 8+ and OS X 10.9+
|
||||
- Restored CocoaPods support for iOS 8+ and macOS 10.9+
|
||||
|
||||
|
||||
## 0.56.0
|
||||
@@ -5704,7 +5717,7 @@ Released March 31, 2016
|
||||
|
||||
Released March 29, 2016
|
||||
|
||||
This release restores CocoaPods support for iOS 9.0+ and OSX 10.11+. We'll try to bring back CocoaPods support for iOS 8.0+ or OSX 10.9+ in a further release.
|
||||
This release restores CocoaPods support for iOS 9.0+ and macOS 10.11+. We'll try to bring back CocoaPods support for iOS 8.0+ or macOS 10.9+ in a further release.
|
||||
|
||||
|
||||
## 0.54.0
|
||||
@@ -6603,7 +6616,7 @@ Released August 25, 2015
|
||||
|
||||
**Fixed**
|
||||
|
||||
- Reduced iOS Deployment Target to 8.0, and OSX Deployment Target to 10.9.
|
||||
- Reduced iOS Deployment Target to 8.0, and macOS Deployment Target to 10.9.
|
||||
- `DatabaseQueue.inTransaction()` is now declared as `rethrows`.
|
||||
|
||||
**Breaking changes**
|
||||
|
||||
@@ -40,6 +40,20 @@
|
||||
remoteGlobalIDString = 56B036021E8D9EBE003B6DA4;
|
||||
remoteInfo = GRDBDemoiOS;
|
||||
};
|
||||
5642252F29A2390800D714BF /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 56B036261E8D9F79003B6DA4 /* GRDB.xcodeproj */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = DC3773F219C8CBB3004FCF85;
|
||||
remoteInfo = GRDB;
|
||||
};
|
||||
5642253329A2391900D714BF /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 56B036261E8D9F79003B6DA4 /* GRDB.xcodeproj */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = DC3773F219C8CBB3004FCF85;
|
||||
remoteInfo = GRDB;
|
||||
};
|
||||
56606D092355931F00185962 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 56B036261E8D9F79003B6DA4 /* GRDB.xcodeproj */;
|
||||
@@ -328,6 +342,7 @@
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
5642253429A2391900D714BF /* PBXTargetDependency */,
|
||||
);
|
||||
name = "GRDBDemoWatchOS Extension";
|
||||
productName = "GRDBDemoWatchOS Extension";
|
||||
@@ -347,6 +362,7 @@
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
5642253029A2390800D714BF /* PBXTargetDependency */,
|
||||
568E5FD81E926430002582E0 /* PBXTargetDependency */,
|
||||
);
|
||||
name = GRDBDemoiOS;
|
||||
@@ -511,6 +527,16 @@
|
||||
target = 56B036021E8D9EBE003B6DA4 /* GRDBDemoiOS */;
|
||||
targetProxy = 56185BF525B80B8900B9C30F /* PBXContainerItemProxy */;
|
||||
};
|
||||
5642253029A2390800D714BF /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
name = GRDB;
|
||||
targetProxy = 5642252F29A2390800D714BF /* PBXContainerItemProxy */;
|
||||
};
|
||||
5642253429A2391900D714BF /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
name = GRDB;
|
||||
targetProxy = 5642253329A2391900D714BF /* PBXContainerItemProxy */;
|
||||
};
|
||||
568E5FCE1E926430002582E0 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 568E5FCA1E926430002582E0 /* GRDBDemoWatchOS Extension */;
|
||||
|
||||
@@ -197,7 +197,7 @@ The changes can quite impact your application. We'll describe them below, as wel
|
||||
scheduling: .immediate,
|
||||
onError: { error in ... },
|
||||
onChange: { [weak self] (players: [Player]) in
|
||||
guard let self = self else { return }
|
||||
guard let self else { return }
|
||||
self.updateView(players)
|
||||
})
|
||||
// <- Here the view has already been updated.
|
||||
|
||||
@@ -103,7 +103,7 @@ let authorInfo: AuthorInfo? = try dbQueue.read { db in
|
||||
let books = try author.books.fetchAll(db)
|
||||
return AuthorInfo(author: author, books: books)
|
||||
}
|
||||
if let authorInfo = authorInfo {
|
||||
if let authorInfo {
|
||||
print("\(authorInfo.author.name) has written:")
|
||||
for book in authorInfo.books {
|
||||
print("- \(book.title)")
|
||||
@@ -126,7 +126,7 @@ let bookInfo: BookInfo? = try dbQueue.read { db in
|
||||
.including(required: Book.author)
|
||||
return try BookInfo.fetchOne(db, request)
|
||||
}
|
||||
if let bookInfo = bookInfo {
|
||||
if let bookInfo {
|
||||
print("\(bookInfo.book.title) was written by \(bookInfo.author.name)")
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ Let's extend Player with database methods.
|
||||
|
||||
This chapter lists all kinds of supported interpolations.
|
||||
|
||||
- Types adopting the [TableRecord] protocol:
|
||||
- Types adopting the [TableRecord] protocol and [Table](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/table) instances:
|
||||
|
||||
```swift
|
||||
struct Player: TableRecord { ... }
|
||||
@@ -371,9 +371,13 @@ This chapter lists all kinds of supported interpolations.
|
||||
// SELECT * FROM player
|
||||
"SELECT * FROM \(Player.self)"
|
||||
|
||||
// INSERT INTO player ...
|
||||
// SELECT * FROM player
|
||||
let player: Player = ...
|
||||
"INSERT INTO \(tableOf: player) ..."
|
||||
"SELECT * FROM \(tableOf: player) ..."
|
||||
|
||||
// SELECT * FROM player
|
||||
let playerTable = Table("player")
|
||||
"SELECT * FROM \(playerTable)"
|
||||
```
|
||||
|
||||
- Columns selected by [TableRecord]:
|
||||
|
||||
+4
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDB.swift'
|
||||
s.version = '6.6.1'
|
||||
s.version = '6.7.0'
|
||||
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
|
||||
@@ -20,6 +20,9 @@ Pod::Spec.new do |s|
|
||||
ss.source_files = 'GRDB/**/*.swift', 'Support/grdb_config.h'
|
||||
ss.framework = 'Foundation'
|
||||
ss.library = 'sqlite3'
|
||||
ss.xcconfig = {
|
||||
'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_ENABLE_FTS5',
|
||||
}
|
||||
end
|
||||
|
||||
s.subspec 'SQLCipher' do |ss|
|
||||
|
||||
@@ -250,6 +250,8 @@
|
||||
56AACAA822ACED7100A40F2A /* Fetch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AACAA722ACED7100A40F2A /* Fetch.swift */; };
|
||||
56AE64122229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */; };
|
||||
56AE6424222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */; };
|
||||
56AFEF2F29969F6E00CA1E51 /* TransactionClock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFEF2E29969F6E00CA1E51 /* TransactionClock.swift */; };
|
||||
56AFEF372996B9DC00CA1E51 /* TransactionDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFEF362996B9DC00CA1E51 /* TransactionDateTests.swift */; };
|
||||
56B021C91D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; };
|
||||
56B6EF56208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */; };
|
||||
56B7EE832863781300C0525F /* WALSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7EE822863781300C0525F /* WALSnapshot.swift */; };
|
||||
@@ -711,6 +713,8 @@
|
||||
56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HasOneThroughAssociation.swift; sourceTree = "<group>"; };
|
||||
56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = "<group>"; };
|
||||
56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = "<group>"; };
|
||||
56AFEF2E29969F6E00CA1E51 /* TransactionClock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionClock.swift; sourceTree = "<group>"; };
|
||||
56AFEF362996B9DC00CA1E51 /* TransactionDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionDateTests.swift; sourceTree = "<group>"; };
|
||||
56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = "<group>"; };
|
||||
56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = "<group>"; };
|
||||
56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1368,6 +1372,7 @@
|
||||
568068301EBBA26100EFB8AA /* SQLRequestTests.swift */,
|
||||
56A238201B9C74A90082EB20 /* Statement */,
|
||||
56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */,
|
||||
56AFEF362996B9DC00CA1E51 /* TransactionDateTests.swift */,
|
||||
5607EFD11BB8253300605DE3 /* TransactionObserver */,
|
||||
);
|
||||
name = Core;
|
||||
@@ -1467,6 +1472,7 @@
|
||||
56A238781B9C75030082EB20 /* Statement.swift */,
|
||||
566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */,
|
||||
560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */,
|
||||
56AFEF2E29969F6E00CA1E51 /* TransactionClock.swift */,
|
||||
566B91321FA4D3810012D5B0 /* TransactionObserver.swift */,
|
||||
56B7EE822863781300C0525F /* WALSnapshot.swift */,
|
||||
5605F1471C672E4000235C62 /* Support */,
|
||||
@@ -1950,6 +1956,7 @@
|
||||
56D496791D81309E008276D7 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
56D4966C1D81309E008276D7 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
|
||||
564CE5BE21B8FFA300652B19 /* DatabaseRegionObservationTests.swift in Sources */,
|
||||
56AFEF372996B9DC00CA1E51 /* TransactionDateTests.swift in Sources */,
|
||||
564F9C1E1F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
|
||||
D263F40A26C613090038B07F /* DatabaseColumnEncodingStrategyTests.swift in Sources */,
|
||||
5653EAEE20944B4F00F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
|
||||
@@ -2098,6 +2105,7 @@
|
||||
5657AB0F1D10899D006283EF /* URL.swift in Sources */,
|
||||
560D924B1C672C4B00F4F92B /* TableRecord.swift in Sources */,
|
||||
56DAA2DB1DE9C827006E10C8 /* Cursor.swift in Sources */,
|
||||
56AFEF2F29969F6E00CA1E51 /* TransactionClock.swift in Sources */,
|
||||
5674A6EB1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
|
||||
56D91AA92205F2F100770D8D /* DatabasePromise.swift in Sources */,
|
||||
56959629222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */,
|
||||
|
||||
+3
@@ -17,6 +17,9 @@
|
||||
location = "group:MyPlayground.playground">
|
||||
</FileRef>
|
||||
</Group>
|
||||
<FileRef
|
||||
location = "group:BRAG.md">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:CHANGELOG.md">
|
||||
</FileRef>
|
||||
|
||||
@@ -169,6 +169,21 @@ public struct Configuration {
|
||||
/// ```
|
||||
public var publicStatementArguments = false
|
||||
|
||||
/// The clock that feeds ``Database/transactionDate``.
|
||||
///
|
||||
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
|
||||
///
|
||||
/// The default clock is ``DefaultTransactionClock`` (which returns the
|
||||
/// current date with `Date()`).
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// var config = Configuration()
|
||||
/// config.transactionClock = .custom { db in /* return some Date */ }
|
||||
/// ```
|
||||
public var transactionClock: TransactionClock = .default
|
||||
|
||||
// MARK: - Managing SQLite Connections
|
||||
|
||||
private var setups: [(Database) throws -> Void] = []
|
||||
@@ -406,7 +421,7 @@ public struct Configuration {
|
||||
/// Creates a DispatchQueue which has the quality of service and target
|
||||
/// queue of read accesses.
|
||||
func makeReaderDispatchQueue(label: String) -> DispatchQueue {
|
||||
if let targetQueue = targetQueue {
|
||||
if let targetQueue {
|
||||
return DispatchQueue(label: label, target: targetQueue)
|
||||
} else {
|
||||
return DispatchQueue(label: label, qos: qos)
|
||||
|
||||
@@ -387,7 +387,7 @@ extension Database {
|
||||
return try self.table(for: table)!.hasRowID
|
||||
}
|
||||
#else
|
||||
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) {
|
||||
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) { // SQLite 3.37+
|
||||
return try self.table(for: table)!.hasRowID
|
||||
}
|
||||
#endif
|
||||
@@ -912,7 +912,7 @@ public struct ColumnInfo: FetchableRecord {
|
||||
|
||||
/// Information about an index.
|
||||
///
|
||||
/// You get `ForeignKeyInfo` instances with the ``Database/indexes(on:)``
|
||||
/// You get `IndexInfo` instances with the ``Database/indexes(on:)``
|
||||
/// `Database` method.
|
||||
///
|
||||
/// Related SQLite documentation:
|
||||
@@ -1032,7 +1032,7 @@ public struct ForeignKeyViolation {
|
||||
})
|
||||
|
||||
var description: String
|
||||
if let foreignKey = foreignKey {
|
||||
if let foreignKey {
|
||||
description = """
|
||||
FOREIGN KEY constraint violation - \
|
||||
from \(originTable)(\(foreignKey.originColumns.joined(separator: ", "))) \
|
||||
@@ -1042,9 +1042,9 @@ public struct ForeignKeyViolation {
|
||||
description = "FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable)"
|
||||
}
|
||||
|
||||
if let originRow = originRow {
|
||||
if let originRow {
|
||||
description += ", in \(String(describing: originRow))"
|
||||
} else if let originRowID = originRowID {
|
||||
} else if let originRowID {
|
||||
description += ", in rowid \(originRowID)"
|
||||
}
|
||||
|
||||
@@ -1084,7 +1084,7 @@ extension ForeignKeyViolation: CustomStringConvertible {
|
||||
///
|
||||
/// See also ``failureDescription(_:)``.
|
||||
public var description: String {
|
||||
if let originRowID = originRowID {
|
||||
if let originRowID {
|
||||
return """
|
||||
FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \
|
||||
in rowid \(originRowID)
|
||||
|
||||
@@ -406,8 +406,8 @@ extension SQLStatementCursor: Cursor {
|
||||
/// Check that all arguments were consumed: it is a programmer error to
|
||||
/// provide arguments that do not match the statements.
|
||||
private func checkArgumentsAreEmpty() throws {
|
||||
if let arguments = arguments,
|
||||
let initialArgumentCount = initialArgumentCount,
|
||||
if let arguments,
|
||||
let initialArgumentCount,
|
||||
arguments.values.isEmpty == false
|
||||
{
|
||||
throw DatabaseError(
|
||||
@@ -445,6 +445,8 @@ extension Database {
|
||||
clearSchemaCache()
|
||||
}
|
||||
|
||||
checkForAutocommitTransition()
|
||||
|
||||
// Database observation: cleanup
|
||||
try observationBroker?.statementDidExecute(statement)
|
||||
}
|
||||
@@ -460,6 +462,8 @@ extension Database {
|
||||
internalStatementCache.remove(statement)
|
||||
publicStatementCache.remove(statement)
|
||||
|
||||
checkForAutocommitTransition()
|
||||
|
||||
// Extract values that may be modified by the user in their
|
||||
// `TransactionObserver.databaseDidRollback(_:)` implementation
|
||||
// (see below).
|
||||
@@ -481,6 +485,25 @@ extension Database {
|
||||
arguments: arguments,
|
||||
publicStatementArguments: configuration.publicStatementArguments)
|
||||
}
|
||||
|
||||
private func checkForAutocommitTransition() {
|
||||
if sqlite3_get_autocommit(sqliteConnection) == 0 {
|
||||
if autocommitState == .on {
|
||||
// Record transaction date as soon as the connection leaves
|
||||
// auto-commit mode.
|
||||
// We grab a result, so that this failure is later reported
|
||||
// whenever the user calls `Database.transactionDate`.
|
||||
transactionDateResult = Result { try configuration.transactionClock.now(self) }
|
||||
}
|
||||
autocommitState = .off
|
||||
} else {
|
||||
if autocommitState == .off {
|
||||
// Reset transaction date
|
||||
transactionDateResult = nil
|
||||
}
|
||||
autocommitState = .on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A thread-unsafe statement cache
|
||||
@@ -510,7 +533,7 @@ struct StatementCache {
|
||||
let statement = try db.makeStatement(sql: sql, prepFlags: CUnsignedInt(SQLITE_PREPARE_PERSISTENT))
|
||||
#else
|
||||
let statement: Statement
|
||||
if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) {
|
||||
if #available(iOS 12, macOS 10.14, watchOS 5, *) { // SQLite 3.20+
|
||||
statement = try db.makeStatement(sql: sql, prepFlags: CUnsignedInt(SQLITE_PREPARE_PERSISTENT))
|
||||
} else {
|
||||
statement = try db.makeStatement(sql: sql)
|
||||
|
||||
+65
-10
@@ -61,6 +61,7 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
|
||||
/// - ``inTransaction(_:_:)``
|
||||
/// - ``isInsideTransaction``
|
||||
/// - ``rollback()``
|
||||
/// - ``transactionDate``
|
||||
/// - ``TransactionCompletion``
|
||||
/// - ``TransactionKind``
|
||||
///
|
||||
@@ -276,6 +277,60 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
/// This cache is never cleared: we assume journal mode never changes.
|
||||
var journalModeCache: String?
|
||||
|
||||
// MARK: - Transaction Date
|
||||
|
||||
enum AutocommitState {
|
||||
case off
|
||||
case on
|
||||
}
|
||||
|
||||
/// The state of the auto-commit mode, as left by the last
|
||||
/// executed statement.
|
||||
///
|
||||
/// The goal of this property is to detect changes in the auto-commit mode.
|
||||
/// When you need to know if the database is currently in the auto-commit
|
||||
/// mode, always prefer ``isInsideTransaction``.
|
||||
var autocommitState = AutocommitState.on
|
||||
|
||||
/// The date of the current transaction, wrapped in a result that is an
|
||||
/// error if there was an error grabbing this date when the transaction has
|
||||
/// started.
|
||||
///
|
||||
/// Invariant: `transactionDateResult` is nil iff connection is not
|
||||
/// inside a transaction.
|
||||
var transactionDateResult: Result<Date, Error>?
|
||||
|
||||
/// The date of the current transaction.
|
||||
///
|
||||
/// The returned date is constant at any point during a transaction. It is
|
||||
/// set when the database leaves the
|
||||
/// [autocommit mode](https://www.sqlite.org/c3ref/get_autocommit.html) with
|
||||
/// a `BEGIN` statement.
|
||||
///
|
||||
/// When the database is not currently in a transaction, a new date is
|
||||
/// returned on each call.
|
||||
///
|
||||
/// See <doc:RecordTimestamps> for an example of usage.
|
||||
///
|
||||
/// Transaction dates, by default, are built from a new `Date()` instance.
|
||||
/// You can override this default behavior by configuring
|
||||
/// ``Configuration/transactionClock``.
|
||||
public var transactionDate: Date {
|
||||
get throws {
|
||||
SchedulingWatchdog.preconditionValidQueue(self)
|
||||
|
||||
// Check invariant: `transactionDateResult` is nil iff connection
|
||||
// is not inside a transaction.
|
||||
assert(isInsideTransaction || transactionDateResult == nil)
|
||||
|
||||
if let transactionDateResult {
|
||||
return try transactionDateResult.get()
|
||||
} else {
|
||||
return try configuration.transactionClock.now(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private properties
|
||||
|
||||
/// Support for ``Configuration/busyMode``.
|
||||
@@ -335,10 +390,10 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
_ = sqlite3_close(sqliteConnection) // ignore result code
|
||||
throw DatabaseError(resultCode: code)
|
||||
}
|
||||
if let sqliteConnection = sqliteConnection {
|
||||
return sqliteConnection
|
||||
guard let sqliteConnection else {
|
||||
throw DatabaseError(resultCode: .SQLITE_INTERNAL) // WTF SQLite?
|
||||
}
|
||||
throw DatabaseError(resultCode: .SQLITE_INTERNAL) // WTF SQLite?
|
||||
return sqliteConnection
|
||||
}
|
||||
|
||||
// MARK: - Database Setup
|
||||
@@ -1163,7 +1218,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
}
|
||||
}
|
||||
|
||||
if let firstError = firstError {
|
||||
if let firstError {
|
||||
throw firstError
|
||||
}
|
||||
}
|
||||
@@ -1312,7 +1367,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
}
|
||||
}
|
||||
|
||||
if let firstError = firstError {
|
||||
if let firstError {
|
||||
throw firstError
|
||||
}
|
||||
}
|
||||
@@ -1861,10 +1916,10 @@ extension Database {
|
||||
enum Impl {
|
||||
case trace_v1(String)
|
||||
case trace_v2(
|
||||
sqliteStatement: SQLiteStatement,
|
||||
unexpandedSQL: UnsafePointer<CChar>?,
|
||||
sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer<Int8>?,
|
||||
publicStatementArguments: Bool) // See Configuration.publicStatementArguments
|
||||
sqliteStatement: SQLiteStatement,
|
||||
unexpandedSQL: UnsafePointer<CChar>?,
|
||||
sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer<Int8>?,
|
||||
publicStatementArguments: Bool) // See Configuration.publicStatementArguments
|
||||
}
|
||||
var impl: Impl
|
||||
|
||||
@@ -1886,7 +1941,7 @@ extension Database {
|
||||
fatalError("Unavailable statement SQL")
|
||||
|
||||
case let .trace_v2(sqliteStatement, unexpandedSQL, _, _):
|
||||
if let unexpandedSQL = unexpandedSQL {
|
||||
if let unexpandedSQL {
|
||||
return String(cString: unexpandedSQL).trimmedSQLStatement
|
||||
} else {
|
||||
return String(cString: sqlite3_sql(sqliteStatement)).trimmedSQLStatement
|
||||
|
||||
@@ -198,7 +198,7 @@ extension ResultCode: CustomStringConvertible {
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
if let errorString = errorString {
|
||||
if let errorString {
|
||||
return "\(rawValue) (\(errorString))"
|
||||
} else {
|
||||
return "\(rawValue)"
|
||||
@@ -543,13 +543,13 @@ extension DatabaseError: CustomStringConvertible {
|
||||
/// without notice: don't have your application rely on any specific format.
|
||||
public var description: String {
|
||||
var description = "SQLite error \(resultCode.rawValue)"
|
||||
if let message = message {
|
||||
if let message {
|
||||
description += ": \(message)"
|
||||
}
|
||||
if let sql = sql {
|
||||
if let sql {
|
||||
description += " - while executing `\(sql)`"
|
||||
}
|
||||
if publicStatementArguments, let arguments = arguments, !arguments.isEmpty {
|
||||
if publicStatementArguments, let arguments, !arguments.isEmpty {
|
||||
description += " with arguments \(arguments)"
|
||||
}
|
||||
return description
|
||||
@@ -571,13 +571,13 @@ extension DatabaseError: CustomStringConvertible {
|
||||
/// property with care.
|
||||
public var expandedDescription: String {
|
||||
var description = "SQLite error \(resultCode.rawValue)"
|
||||
if let message = message {
|
||||
if let message {
|
||||
description += ": \(message)"
|
||||
}
|
||||
if let sql = sql {
|
||||
if let sql {
|
||||
description += " - while executing `\(sql)`"
|
||||
}
|
||||
if let arguments = arguments, !arguments.isEmpty {
|
||||
if let arguments, !arguments.isEmpty {
|
||||
description += " with arguments \(arguments)"
|
||||
}
|
||||
return description
|
||||
@@ -598,7 +598,7 @@ extension DatabaseError: CustomNSError {
|
||||
/// Part of the `CustomNSError` conformance.
|
||||
public var errorUserInfo: [String: Any] {
|
||||
var userInfo = [NSLocalizedDescriptionKey: description]
|
||||
if let message = message {
|
||||
if let message {
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = message
|
||||
}
|
||||
return userInfo
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class DatabasePool {
|
||||
// Undo job done in setupMemoryManagement()
|
||||
//
|
||||
// https://developer.apple.com/library/mac/releasenotes/Foundation/RN-Foundation/index.html#10_11Error
|
||||
// Explicit unregistration is required before OS X 10.11.
|
||||
// Explicit unregistration is required before macOS 10.11.
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
|
||||
// Close reader connections before the writer connection.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#if canImport(Combine)
|
||||
/// A namespace for database Combine publishers.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public enum DatabasePublishers { }
|
||||
#endif
|
||||
@@ -103,7 +103,7 @@ public final class DatabaseQueue {
|
||||
// Undo job done in setupMemoryManagement()
|
||||
//
|
||||
// https://developer.apple.com/library/mac/releasenotes/Foundation/RN-Foundation/index.html#10_11Error
|
||||
// Explicit unregistration is required before OS X 10.11.
|
||||
// Explicit unregistration is required before macOS 10.11.
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ extension DatabaseReader {
|
||||
/// - 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.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func read<T>(_ value: @Sendable @escaping (Database) throws -> T) async throws -> T {
|
||||
try await withUnsafeThrowingContinuation { continuation in
|
||||
asyncRead { result in
|
||||
@@ -487,7 +487,7 @@ extension DatabaseReader {
|
||||
/// - 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.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func unsafeRead<T>(_ value: @Sendable @escaping (Database) throws -> T) async throws -> T {
|
||||
try await withUnsafeThrowingContinuation { continuation in
|
||||
asyncUnsafeRead { result in
|
||||
@@ -532,7 +532,7 @@ extension DatabaseReader {
|
||||
///
|
||||
/// - parameter scheduler: A Combine Scheduler.
|
||||
/// - parameter value: A closure which accesses the database.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func readPublisher<Output>(
|
||||
receiveOn scheduler: some Combine.Scheduler = DispatchQueue.main,
|
||||
value: @escaping (Database) throws -> Output)
|
||||
@@ -550,7 +550,7 @@ extension DatabaseReader {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabasePublishers {
|
||||
/// A publisher that reads from the database.
|
||||
///
|
||||
@@ -569,7 +569,7 @@ extension DatabasePublishers {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Publisher where Failure == Error {
|
||||
fileprivate func eraseToReadPublisher() -> DatabasePublishers.Read<Output> {
|
||||
.init(upstream: eraseToAnyPublisher())
|
||||
|
||||
@@ -287,8 +287,8 @@ private struct TableRegion: Equatable {
|
||||
var rowIds: Set<Int64>? // nil means "all rowids"
|
||||
|
||||
var isEmpty: Bool {
|
||||
if let columns = columns, columns.isEmpty { return true }
|
||||
if let rowIds = rowIds, rowIds.isEmpty { return true }
|
||||
if let columns, columns.isEmpty { return true }
|
||||
if let rowIds, rowIds.isEmpty { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ extension DatabaseRegionObservation {
|
||||
}
|
||||
|
||||
#if canImport(Combine)
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabaseRegionObservation {
|
||||
// MARK: - Publishing Impactful Transactions
|
||||
|
||||
@@ -243,7 +243,7 @@ extension DatabaseRegionObservation {
|
||||
///
|
||||
/// Do not reschedule the publisher with `receive(on:options:)` or any
|
||||
/// `Publisher` method that schedules publisher elements.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func publisher(in writer: some DatabaseWriter) -> DatabasePublishers.DatabaseRegion {
|
||||
DatabasePublishers.DatabaseRegion(self, in: writer)
|
||||
}
|
||||
@@ -284,7 +284,7 @@ private class DatabaseRegionObserver: TransactionObserver {
|
||||
}
|
||||
|
||||
#if canImport(Combine)
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabasePublishers {
|
||||
/// A publisher that tracks transactions that modify a database region.
|
||||
///
|
||||
|
||||
@@ -322,7 +322,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
return result
|
||||
}
|
||||
} else {
|
||||
/// There is no unsafe access to a snapshot.
|
||||
// There is no unsafe access to a snapshot.
|
||||
return try read(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible>: Databas
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: (any RowAdapter)? = nil) throws {
|
||||
self._statement = statement
|
||||
if let adapter = adapter {
|
||||
if let adapter {
|
||||
// adapter may redefine the index of the leftmost column
|
||||
columnIndex = try CInt(adapter.baseColumnIndex(atIndex: 0, layout: statement))
|
||||
} else {
|
||||
|
||||
@@ -516,7 +516,7 @@ extension DatabaseWriter {
|
||||
///
|
||||
/// - Parameter filePath: file path for new database
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
@available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *)
|
||||
@available(iOS 14, macOS 10.16, tvOS 14, watchOS 7, *)
|
||||
public func vacuum(into filePath: String) throws {
|
||||
try writeWithoutTransaction {
|
||||
try $0.execute(sql: "VACUUM INTO ?", arguments: [filePath])
|
||||
@@ -582,7 +582,7 @@ extension DatabaseWriter {
|
||||
/// - throws: The error thrown by `updates`, or any ``DatabaseError`` that
|
||||
/// would happen while establishing the database access or committing
|
||||
/// the transaction.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func write<T>(_ updates: @Sendable @escaping (Database) throws -> T) async throws -> T {
|
||||
try await withUnsafeThrowingContinuation { continuation in
|
||||
asyncWrite(updates, completion: { _, result in
|
||||
@@ -620,7 +620,7 @@ extension DatabaseWriter {
|
||||
///
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func writeWithoutTransaction<T>(_ updates: @Sendable @escaping (Database) throws -> T) async throws -> T {
|
||||
try await withUnsafeThrowingContinuation { continuation in
|
||||
asyncWriteWithoutTransaction { db in
|
||||
@@ -672,7 +672,7 @@ extension DatabaseWriter {
|
||||
///
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
/// - throws: The error thrown by `updates`.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func barrierWriteWithoutTransaction<T>(
|
||||
_ updates: @Sendable @escaping (Database) throws -> T)
|
||||
async throws -> T
|
||||
@@ -687,7 +687,7 @@ extension DatabaseWriter {
|
||||
/// Erases the content of the database.
|
||||
///
|
||||
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func erase() async throws {
|
||||
try await writeWithoutTransaction { try $0.erase() }
|
||||
}
|
||||
@@ -698,7 +698,7 @@ extension DatabaseWriter {
|
||||
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_vacuum.html>
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func vacuum() async throws {
|
||||
try await writeWithoutTransaction { try $0.execute(sql: "VACUUM") }
|
||||
}
|
||||
@@ -715,7 +715,7 @@ extension DatabaseWriter {
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_vacuum.html#vacuuminto>
|
||||
///
|
||||
/// - Parameter filePath: file path for new database
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func vacuum(into filePath: String) async throws {
|
||||
try await writeWithoutTransaction {
|
||||
try $0.execute(sql: "VACUUM INTO ?", arguments: [filePath])
|
||||
@@ -730,7 +730,7 @@ extension DatabaseWriter {
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_vacuum.html#vacuuminto>
|
||||
///
|
||||
/// - Parameter filePath: file path for new database
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func vacuum(into filePath: String) async throws {
|
||||
try await writeWithoutTransaction {
|
||||
try $0.execute(sql: "VACUUM INTO ?", arguments: [filePath])
|
||||
@@ -775,7 +775,7 @@ extension DatabaseWriter {
|
||||
///
|
||||
/// - parameter scheduler: A Combine Scheduler.
|
||||
/// - parameter updates: A closure which accesses the database.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func writePublisher<Output>(
|
||||
receiveOn scheduler: some Combine.Scheduler = DispatchQueue.main,
|
||||
updates: @escaping (Database) throws -> Output)
|
||||
@@ -840,7 +840,7 @@ extension DatabaseWriter {
|
||||
/// - parameter scheduler: A Combine Scheduler.
|
||||
/// - parameter updates: A closure which writes in the database.
|
||||
/// - parameter value: A closure which reads from the database.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func writePublisher<S, T, Output>(
|
||||
receiveOn scheduler: S = DispatchQueue.main,
|
||||
updates: @escaping (Database) throws -> T,
|
||||
@@ -872,7 +872,7 @@ extension DatabaseWriter {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabasePublishers {
|
||||
/// A publisher that writes into the database.
|
||||
///
|
||||
@@ -891,7 +891,7 @@ extension DatabasePublishers {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Publisher where Failure == Error {
|
||||
fileprivate func eraseToWritePublisher() -> DatabasePublishers.Write<Output> {
|
||||
.init(upstream: self.eraseToAnyPublisher())
|
||||
|
||||
+3
-3
@@ -682,7 +682,7 @@ extension Row {
|
||||
/// ``JoinableRequest/including(optional:)`` request methods define scopes
|
||||
/// named after the key of included associations between record types.
|
||||
///
|
||||
/// A depth-first search is performed in all available scopes in the row,
|
||||
/// A breadth-first search is performed in all available scopes in the row,
|
||||
/// recursively.
|
||||
///
|
||||
/// A fatal error is raised if the scope is not available, or contains only
|
||||
@@ -726,7 +726,7 @@ extension Row {
|
||||
/// ``JoinableRequest/including(optional:)`` request methods define scopes
|
||||
/// named after the key of included associations between record types.
|
||||
///
|
||||
/// A depth-first search is performed in all available scopes in the row,
|
||||
/// A breadth-first search is performed in all available scopes in the row,
|
||||
/// recursively.
|
||||
///
|
||||
/// The result is nil if the scope is not available, or contains only
|
||||
@@ -879,7 +879,7 @@ extension Row {
|
||||
/// A view on the scopes tree defined by row adapters.
|
||||
///
|
||||
/// The returned object provides an access to all available scopes in
|
||||
/// the row, recursively. For any given scope identifier, a depth-first
|
||||
/// the row, recursively. For any given scope identifier, a breadth-first
|
||||
/// search is performed.
|
||||
///
|
||||
/// Row scopes can be defined manually, with ``ScopeAdapter``.
|
||||
|
||||
+2
-2
@@ -121,8 +121,8 @@ public struct SQL {
|
||||
fileprivate func qualified(with alias: TableAlias) -> Element {
|
||||
switch self {
|
||||
case .sql:
|
||||
/// A raw SQL string can't be qualified with a table alias,
|
||||
/// because we can't parse it.
|
||||
// A raw SQL string can't be qualified with a table alias,
|
||||
// because we can't parse it.
|
||||
return self
|
||||
case .subquery:
|
||||
// Subqueries don't need table alias
|
||||
|
||||
@@ -206,9 +206,9 @@ extension SQLRequest: FetchRequest {
|
||||
switch cache {
|
||||
case .none:
|
||||
statement = try db.makeStatement(sql: sql)
|
||||
case .public?:
|
||||
case .public:
|
||||
statement = try db.cachedStatement(sql: sql)
|
||||
case .internal?:
|
||||
case .internal:
|
||||
statement = try db.internalCachedStatement(sql: sql)
|
||||
}
|
||||
try statement.setArguments(context.arguments)
|
||||
|
||||
@@ -175,7 +175,7 @@ public final class Statement {
|
||||
database.sqliteConnection, statementStart, -1, prepFlags,
|
||||
&sqliteStatement, statementEnd)
|
||||
#else
|
||||
if #available(iOS 12.0, OSX 10.14, tvOS 12.0, watchOS 5.0, *) {
|
||||
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *) { // SQLite 3.20+
|
||||
code = sqlite3_prepare_v3(
|
||||
database.sqliteConnection, statementStart, -1, prepFlags,
|
||||
&sqliteStatement, statementEnd)
|
||||
@@ -294,7 +294,7 @@ public final class Statement {
|
||||
|
||||
var valuesIterator = arguments.values.makeIterator()
|
||||
for (index, argumentName) in zip(CInt(1)..., sqliteArgumentNames) {
|
||||
if let argumentName = argumentName, let value = arguments.namedValues[argumentName] {
|
||||
if let argumentName, let value = arguments.namedValues[argumentName] {
|
||||
bind(value, at: index)
|
||||
} else if let value = valuesIterator.next() {
|
||||
bind(value, at: index)
|
||||
@@ -372,7 +372,7 @@ public final class Statement {
|
||||
func reset(withArguments arguments: StatementArguments?) throws {
|
||||
// Force arguments validity: it is a programmer error to provide
|
||||
// arguments that do not match the statement.
|
||||
if let arguments = arguments {
|
||||
if let arguments {
|
||||
try setArguments(arguments)
|
||||
} else if argumentsNeedValidation {
|
||||
try reset()
|
||||
@@ -1122,7 +1122,7 @@ public struct StatementArguments: Hashable {
|
||||
{
|
||||
let initialValuesCount = values.count
|
||||
let bindings = try statement.sqliteArgumentNames.map { argumentName -> DatabaseValue in
|
||||
if let argumentName = argumentName {
|
||||
if let argumentName {
|
||||
if let dbValue = namedValues[argumentName] {
|
||||
return dbValue
|
||||
} else if values.isEmpty {
|
||||
|
||||
@@ -107,7 +107,7 @@ final class StatementAuthorizer {
|
||||
|
||||
case SQLITE_DELETE:
|
||||
if isDropStatement { return SQLITE_OK }
|
||||
guard let cString1 = cString1 else { return SQLITE_OK }
|
||||
guard let cString1 else { return SQLITE_OK }
|
||||
|
||||
// Deletions from sqlite_master and sqlite_temp_master are not like
|
||||
// other deletions: `sqlite3_update_hook` does not notify them, and
|
||||
@@ -137,7 +137,7 @@ final class StatementAuthorizer {
|
||||
return SQLITE_OK
|
||||
|
||||
case SQLITE_TRANSACTION:
|
||||
guard let cString1 = cString1 else { return SQLITE_OK }
|
||||
guard let cString1 else { return SQLITE_OK }
|
||||
if strcmp(cString1, "BEGIN") == 0 {
|
||||
transactionEffect = .beginTransaction
|
||||
} else if strcmp(cString1, "COMMIT") == 0 {
|
||||
@@ -148,7 +148,7 @@ final class StatementAuthorizer {
|
||||
return SQLITE_OK
|
||||
|
||||
case SQLITE_SAVEPOINT:
|
||||
guard let cString1 = cString1 else { return SQLITE_OK }
|
||||
guard let cString1 else { return SQLITE_OK }
|
||||
guard let name = cString2.map(String.init) else { return SQLITE_OK }
|
||||
if strcmp(cString1, "BEGIN") == 0 {
|
||||
transactionEffect = .beginSavepoint(name)
|
||||
|
||||
@@ -215,7 +215,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: (any RowAdapter)? = nil) throws {
|
||||
self._statement = statement
|
||||
if let adapter = adapter {
|
||||
if let adapter {
|
||||
// adapter may redefine the index of the leftmost column
|
||||
columnIndex = try CInt(adapter.baseColumnIndex(atIndex: 0, layout: statement))
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import Foundation
|
||||
|
||||
/// A type that provides the moment of a transaction.
|
||||
///
|
||||
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Built-in Clocks
|
||||
///
|
||||
/// - ``DefaultTransactionClock``
|
||||
/// - ``CustomTransactionClock``
|
||||
public protocol TransactionClock {
|
||||
/// Returns the date of the current transaction.
|
||||
///
|
||||
/// This function 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.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/c3ref/get_autocommit.html>
|
||||
func now(_ db: Database) throws -> Date
|
||||
}
|
||||
|
||||
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 (Database) throws -> Date) -> Self {
|
||||
CustomTransactionClock(now)
|
||||
}
|
||||
}
|
||||
|
||||
/// The default clock.
|
||||
public struct DefaultTransactionClock: TransactionClock {
|
||||
public func now(_ db: Database) throws -> Date {
|
||||
// An opportunity to fetch transaction time from the database when
|
||||
// SQLite supports the feature.
|
||||
Date()
|
||||
}
|
||||
}
|
||||
|
||||
/// A custom transaction clock.
|
||||
public struct CustomTransactionClock: TransactionClock {
|
||||
let _now: (Database) throws -> Date
|
||||
|
||||
public init(_ now: @escaping (Database) throws -> Date) {
|
||||
self._now = now
|
||||
}
|
||||
|
||||
public func now(_ db: Database) throws -> Date {
|
||||
try _now(db)
|
||||
}
|
||||
}
|
||||
@@ -1125,7 +1125,7 @@ public protocol TransactionObserver: AnyObject {
|
||||
///
|
||||
/// Requires SQLite compiled with option SQLITE_ENABLE_PREUPDATE_HOOK.
|
||||
///
|
||||
/// As of OSX 10.11.5, and iOS 9.3.2, the built-in SQLite library
|
||||
/// As of macOS 10.11.5, and iOS 9.3.2, the built-in SQLite library
|
||||
/// does not have this enabled, so you'll need to compile your own
|
||||
/// version of SQLite:
|
||||
/// See <https://github.com/groue/GRDB.swift/blob/master/Documentation/CustomSQLiteBuilds.md>
|
||||
@@ -1482,7 +1482,7 @@ public struct DatabasePreUpdateEvent {
|
||||
/// The triggering depth of the row update
|
||||
/// Returns:
|
||||
/// 0 if the preupdate callback was invoked as a result of a direct insert,
|
||||
// update, or delete operation;
|
||||
/// update, or delete operation;
|
||||
/// 1 for inserts, updates, or deletes invoked by top-level triggers;
|
||||
/// 2 for changes resulting from triggers called by top-level triggers;
|
||||
/// ... and so forth
|
||||
@@ -1699,7 +1699,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
{
|
||||
var value: SQLiteValue? = nil
|
||||
guard sqlite_func(connection, column, &value) == SQLITE_OK else { return nil }
|
||||
if let value = value {
|
||||
if let value {
|
||||
return DatabaseValue(sqliteValue: value)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -65,7 +65,7 @@ final class WALSnapshot: Sendable {
|
||||
///
|
||||
/// See <https://www.sqlite.org/c3ref/snapshot_cmp.html>.
|
||||
func compare(_ other: WALSnapshot) -> CInt {
|
||||
return sqlite3_snapshot_cmp(sqliteSnapshot, other.sqliteSnapshot)
|
||||
sqlite3_snapshot_cmp(sqliteSnapshot, other.sqliteSnapshot)
|
||||
}
|
||||
#else
|
||||
static let available = false
|
||||
|
||||
@@ -32,6 +32,7 @@ Compared to [SQLite.swift](https://github.com/stephencelis/SQLite.swift) or [FMD
|
||||
### Records and the Query Interface
|
||||
|
||||
- <doc:QueryInterface>
|
||||
- <doc:RecordTimestamps>
|
||||
|
||||
### Responding to Database Changes
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ do {
|
||||
- ``observesSuspensionNotifications``
|
||||
- ``prepareDatabase(_:)``
|
||||
- ``publicStatementArguments``
|
||||
- ``transactionClock``
|
||||
- ``TransactionClock``
|
||||
|
||||
### Configuring the Quality of Service
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@ Please refer to the [Full-Text Search](https://github.com/groue/GRDB.swift/blob/
|
||||
|
||||
- ``FTS3``
|
||||
- ``FTS4``
|
||||
- ``FTS5``
|
||||
@@ -0,0 +1,187 @@
|
||||
# Record Timestamps and Transaction Date
|
||||
|
||||
Learn how applications can save creation and modification dates of records.
|
||||
|
||||
## Overview
|
||||
|
||||
Record timestamps are the responsibility of your application. This article provides some sample code that you can adapt for your specific needs.
|
||||
|
||||
> Note: Creation and modification timestamps can be automatically handled by [SQLite triggers](https://www.sqlite.org/lang_createtrigger.html). We'll explore a different technique.
|
||||
>
|
||||
> This is not an advice against triggers, and you won't feel hindered in any way if you prefer to use triggers. Still, consider:
|
||||
>
|
||||
> - A trigger does not suffer any exception, when some applications eventually want to fine-tune timestamps, or to perform migrations without touching timestamps.
|
||||
> - The "current time" according to SQLite can't be controlled in tests and previews.
|
||||
> - The "current time" according to SQLite is not guaranteed to be constant in a given transaction, and this may create undesired timestamp variations.
|
||||
|
||||
We'll start from this table and record type:
|
||||
|
||||
```swift
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("creationDate", .datetime).notNull()
|
||||
t.column("modificationDate", .datetime).notNull()
|
||||
t.column("name", .text).notNull()
|
||||
t.column("score", .integer).notNull()
|
||||
}
|
||||
|
||||
struct Player: Identifiable {
|
||||
var id: Int64?
|
||||
var creationDate: Date?
|
||||
var modificationDate: Date?
|
||||
var name: String
|
||||
var score: Int
|
||||
}
|
||||
```
|
||||
|
||||
Note that the table has non-null dates, while the record has optional dates.
|
||||
|
||||
This is because we intend, in this article, to timestamp actual database operations. The `creationDate` property is the date of database insertion, and `modificationDate` is the date of last modification in the database. A new `Player` instance has no meaningful timestamp until it is saved, and this absence of information is represented with `nil`:
|
||||
|
||||
```swift
|
||||
// A new player has no timestamps.
|
||||
var player = Player(id: nil, name: "Arthur", score: 1000)
|
||||
player.id // nil, because never saved
|
||||
player.creationDate // nil, because never saved
|
||||
player.modificationDate // nil, because never saved
|
||||
|
||||
// After insertion, the player has timestamps.
|
||||
try dbQueue.write { db in
|
||||
try player.insert(db)
|
||||
}
|
||||
player.id // not nil
|
||||
player.creationDate // not nil
|
||||
player.modificationDate // not nil
|
||||
```
|
||||
|
||||
In the rest of the article, we'll address insertion first, then updates, and finally we'll see a way to avoid those optional timestamps.
|
||||
|
||||
## Insertion Timestamp
|
||||
|
||||
On insertion, the record should get fresh `creationDate` and `modificationDate`. The ``MutablePersistableRecord`` protocol provides the necessary tooling:
|
||||
|
||||
```swift
|
||||
extension Player: Encodable, MutablePersistableRecord {
|
||||
// Update auto-incremented id upon successful insertion
|
||||
mutating func didInsert(_ inserted: InsertionSuccess) {
|
||||
id = inserted.rowID
|
||||
}
|
||||
|
||||
// Update timestamps before insertion
|
||||
mutating func willInsert(_ db: Database) throws {
|
||||
creationDate = try db.transactionDate
|
||||
modificationDate = try db.transactionDate
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that we are using the ``Database/transactionDate`` instead of `Date()`. This has two advantages:
|
||||
|
||||
- Within a write transaction, all inserted players get the same timestamp:
|
||||
|
||||
```swift
|
||||
// All players have the same timestamp.
|
||||
try dbQueue.write { db in
|
||||
for var player in players {
|
||||
try player.insert(db)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- The transaction date can be configured with ``Configuration/transactionClock``, so that your tests and previews can control the date.
|
||||
|
||||
## Modification Timestamp
|
||||
|
||||
Let's now deal with updates. The `update` persistence method won't automatically bump the timestamp as the `insert` method does. We have to explicitly deal with the modification date:
|
||||
|
||||
```swift
|
||||
// Increment the player score.
|
||||
try dbQueue.write { db in
|
||||
var player: Player
|
||||
try player.updateChanges(db) {
|
||||
$0.score += 1
|
||||
$0.modificationDate = try db.transactionDate
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Again, we use ``Database/transactionDate``, so that all modified players get the same timestamp within a given write transaction.
|
||||
|
||||
## Dealing with Optional Timestamps
|
||||
|
||||
When you fetch timestamped records from the database, it may be inconvenient to deal with optional dates, even though the database columns are guaranteed to be not null:
|
||||
|
||||
```swift
|
||||
let player = try dbQueue.read { db
|
||||
try Player.find(db, id: 1)
|
||||
}
|
||||
player.creationDate // optional 😕
|
||||
player.modificationDate // optional 😕
|
||||
```
|
||||
|
||||
A possible technique is to define two record types.
|
||||
|
||||
One record can deal with unsaved players:
|
||||
|
||||
```swift
|
||||
struct Player: Identifiable {
|
||||
var id: Int64?
|
||||
var creationDate: Date?
|
||||
var modificationDate: Date?
|
||||
var name: String
|
||||
var score: Int
|
||||
}
|
||||
|
||||
extension Player: Encodable, MutablePersistableRecord {
|
||||
// Update auto-incremented id upon successful insertion
|
||||
mutating func didInsert(_ inserted: InsertionSuccess) {
|
||||
id = inserted.rowID
|
||||
}
|
||||
|
||||
// Update timestamps before insertion
|
||||
mutating func willInsert(_ db: Database) throws {
|
||||
creationDate = try db.transactionDate
|
||||
modificationDate = try db.transactionDate
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The other record only deals with saved players:
|
||||
|
||||
```swift
|
||||
struct TimestampedPlayer: Identifiable {
|
||||
let id: Int64
|
||||
let creationDate: Date
|
||||
var modificationDate: Date
|
||||
var name: String
|
||||
var score: Int
|
||||
}
|
||||
|
||||
extension TimestampedPlayer: Codable, FetchableRecord, PersistableRecord {
|
||||
static var databaseTableName: String { Player.databaseTableName }
|
||||
}
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```swift
|
||||
// Fetch
|
||||
let timestampedPlayer = try dbQueue.read { db
|
||||
try TimestampedPlayer.find(db, id: 1)
|
||||
}
|
||||
timestampedPlayer.creationDate // not optional
|
||||
timestampedPlayer.modificationDate // not optional
|
||||
|
||||
// Insert
|
||||
try dbQueue.write { db in
|
||||
var player = Player(id: nil, name: "Arthur", score: 1000)
|
||||
|
||||
let timestampedPlayer = try player.insertAndFetch(db, as: TimestampedPlayer.self)
|
||||
|
||||
timestampedPlayer.id // not optional
|
||||
timestampedPlayer.creationDate // not optional
|
||||
timestampedPlayer.modificationDate // not optional
|
||||
}
|
||||
```
|
||||
|
||||
See ``MutablePersistableRecord/insertAndFetch(_:onConflict:as:)`` and related methods for more information.
|
||||
+18
-13
@@ -1,7 +1,14 @@
|
||||
/// The virtual table module for the FTS3 full-text engine.
|
||||
///
|
||||
/// To create FTS3 tables, use the ``Database`` method
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)``.
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)``:
|
||||
///
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE document USING fts3(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS3()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts3.html>
|
||||
///
|
||||
@@ -23,26 +30,24 @@
|
||||
public struct FTS3 {
|
||||
/// Options for Latin script characters.
|
||||
public enum Diacritics {
|
||||
/// Do not remove diacritics from Latin script characters.
|
||||
/// Do not remove diacritics from Latin script characters. This option
|
||||
/// matches the `remove_diacritics=0` tokenizer argument.
|
||||
///
|
||||
/// This option matches the `remove_diacritics=0` tokenizer argument.
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts3.html#tokenizer>
|
||||
case keep
|
||||
|
||||
/// Remove diacritics from Latin script characters.
|
||||
///
|
||||
/// This option matches the `remove_diacritics=1` tokenizer argument.
|
||||
/// Remove diacritics from Latin script characters. This option matches
|
||||
/// the `remove_diacritics=1` tokenizer argument.
|
||||
case removeLegacy
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
/// Remove diacritics from Latin script characters.
|
||||
///
|
||||
/// This option matches the `remove_diacritics=2` tokenizer argument.
|
||||
/// Remove diacritics from Latin script characters. This option matches
|
||||
/// the `remove_diacritics=2` tokenizer argument.
|
||||
case remove
|
||||
#elseif !GRDBCIPHER
|
||||
/// Remove diacritics from Latin script characters.
|
||||
///
|
||||
/// This option matches the `remove_diacritics=2` tokenizer argument.
|
||||
@available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) // SQLite 3.27+
|
||||
/// Remove diacritics from Latin script characters. This option matches
|
||||
/// the `remove_diacritics=2` tokenizer argument.
|
||||
@available(iOS 14, macOS 10.16, tvOS 14, watchOS 7, *) // SQLite 3.27+
|
||||
case remove
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/// An ``FTS3`` tokenizer.
|
||||
/// The descriptor for an ``FTS3`` tokenizer.
|
||||
///
|
||||
/// `FTS3TokenizerDescriptor` can be used in both ``FTS3`` and ``FTS4`` tables.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// try db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// t.tokenizer = .simple // FTS3TokenizerDescriptor
|
||||
/// }
|
||||
/// ```
|
||||
@@ -14,7 +14,7 @@
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Creating Tokenizers
|
||||
/// ### Creating Tokenizer Descriptors
|
||||
///
|
||||
/// - ``porter``
|
||||
/// - ``simple``
|
||||
@@ -34,7 +34,7 @@ public struct FTS3TokenizerDescriptor {
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// try db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// t.tokenizer = .simple
|
||||
/// }
|
||||
/// ```
|
||||
@@ -47,7 +47,7 @@ public struct FTS3TokenizerDescriptor {
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// try db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// t.tokenizer = .porter
|
||||
/// }
|
||||
/// ```
|
||||
@@ -60,7 +60,7 @@ public struct FTS3TokenizerDescriptor {
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// try db.create(virtualTable: "book", using: FTS4()) { t in
|
||||
/// t.tokenizer = .unicode61()
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
+11
-4
@@ -1,7 +1,14 @@
|
||||
/// The virtual table module for the FTS4 full-text engine.
|
||||
///
|
||||
/// To create FTS4 tables, use the ``Database`` method
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)``.
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)``:
|
||||
///
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE document USING fts4(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS4()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts3.html>
|
||||
///
|
||||
@@ -62,7 +69,7 @@ extension FTS4: VirtualTableModule {
|
||||
|
||||
switch definition.contentMode {
|
||||
case .raw(let content):
|
||||
if let content = content {
|
||||
if let content {
|
||||
arguments.append("content=\"\(content)\"")
|
||||
}
|
||||
case .synchronized(let contentTable):
|
||||
@@ -234,7 +241,7 @@ public final class FTS4TableDefinition {
|
||||
/// The FTS4 `prefix` option.
|
||||
///
|
||||
/// // CREATE VIRTUAL TABLE document USING FTS4(content, prefix='2 4');
|
||||
/// db.create(virtualTable: "document", using:FTS4()) { t in
|
||||
/// try db.create(virtualTable: "document", using:FTS4()) { t in
|
||||
/// t.prefixes = [2, 4]
|
||||
/// t.column("content")
|
||||
/// }
|
||||
@@ -300,7 +307,7 @@ public final class FTS4TableDefinition {
|
||||
/// try db.dropFTS4SynchronizationTriggers(forTable: "book_ft")
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://sqlite.org/fts5.html#external_content_tables>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts3.html#_external_content_fts4_tables_>
|
||||
public func synchronize(withTable tableName: String) {
|
||||
contentMode = .synchronized(contentTable: tableName)
|
||||
}
|
||||
|
||||
+218
-129
@@ -1,19 +1,45 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
import Foundation
|
||||
|
||||
/// FTS5 lets you define "fts5" virtual tables.
|
||||
/// The virtual table module for the FTS5 full-text engine.
|
||||
///
|
||||
/// // CREATE VIRTUAL TABLE document USING fts5(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// To create FTS5 tables, use the ``Database`` method
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)``:
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html>
|
||||
public struct FTS5: VirtualTableModule {
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE document USING fts5(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html>
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### The FTS5 Module
|
||||
///
|
||||
/// - ``init()``
|
||||
/// - ``FTS5TableDefinition``
|
||||
/// - ``FTS5ColumnDefinition``
|
||||
/// - ``FTS5TokenizerDescriptor``
|
||||
///
|
||||
/// ### Full-Text Search Pattern
|
||||
///
|
||||
/// - ``FTS5Pattern``
|
||||
///
|
||||
/// ### FTS5 Tokenizers
|
||||
///
|
||||
/// - ``FTS5Tokenizer``
|
||||
/// - ``FTS5CustomTokenizer``
|
||||
/// - ``FTS5WrapperTokenizer``
|
||||
/// - ``FTS5TokenFlags``
|
||||
/// - ``FTS5Tokenization``
|
||||
public struct FTS5 {
|
||||
/// Options for Latin script characters. Matches the raw "remove_diacritics"
|
||||
/// tokenizer argument.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#unicode61_tokenizer>
|
||||
public enum Diacritics {
|
||||
/// Do not remove diacritics from Latin script characters. This
|
||||
/// option matches the raw "remove_diacritics=0" tokenizer argument.
|
||||
@@ -30,20 +56,23 @@ public struct FTS5: VirtualTableModule {
|
||||
/// Remove diacritics from Latin script characters. This
|
||||
/// option matches the raw "remove_diacritics=2" tokenizer argument,
|
||||
/// available from SQLite 3.27.0
|
||||
@available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *)
|
||||
@available(iOS 14, macOS 10.16, tvOS 14, watchOS 7, *) // SQLite 3.27+
|
||||
case remove
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Creates a FTS5 module suitable for the Database
|
||||
/// `create(virtualTable:using:)` method.
|
||||
/// Creates an FTS5 module.
|
||||
///
|
||||
/// // CREATE VIRTUAL TABLE document USING fts5(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html>
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE document USING fts5(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See ``Database/create(virtualTable:ifNotExists:using:_:)``
|
||||
public init() { }
|
||||
|
||||
// Support for FTS5Pattern initializers. Don't make public. Users tokenize
|
||||
@@ -71,10 +100,70 @@ public struct FTS5: VirtualTableModule {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - VirtualTableModule Adoption
|
||||
static func api(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
// Access to FTS5 is one of the rare SQLite api which was broken in
|
||||
// SQLite 3.20.0+, for security reasons:
|
||||
//
|
||||
// Starting SQLite 3.20.0+, we need to use the new sqlite3_bind_pointer api.
|
||||
// The previous way to access FTS5 does not work any longer.
|
||||
//
|
||||
// So let's see which SQLite version we are linked against:
|
||||
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
// GRDB is linked against SQLCipher or a custom SQLite build: SQLite 3.20.0 or more.
|
||||
return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer)
|
||||
#else
|
||||
// GRDB is linked against the system SQLite.
|
||||
if #available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *) { // SQLite 3.20+
|
||||
return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer)
|
||||
} else {
|
||||
return api_v1(db)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static func api_v1(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
guard let data = try! Data.fetchOne(db, sql: "SELECT fts5()") else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
return data.withUnsafeBytes {
|
||||
$0.bindMemory(to: UnsafePointer<fts5_api>.self).first!
|
||||
}
|
||||
}
|
||||
|
||||
// Technique given by Jordan Rose:
|
||||
// https://forums.swift.org/t/c-interoperability-combinations-of-library-and-os-versions/14029/4
|
||||
private static func api_v2(
|
||||
_ db: Database,
|
||||
// swiftlint:disable:next line_length
|
||||
_ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer<Int8>?, CInt, CUnsignedInt, UnsafeMutablePointer<OpaquePointer?>?, UnsafeMutablePointer<UnsafePointer<Int8>?>?) -> CInt,
|
||||
// swiftlint:disable:next line_length
|
||||
_ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, CInt, UnsafeMutableRawPointer?, UnsafePointer<Int8>?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> CInt)
|
||||
-> UnsafePointer<fts5_api>
|
||||
{
|
||||
var statement: SQLiteStatement? = nil
|
||||
var api: UnsafePointer<fts5_api>? = nil
|
||||
let type: StaticString = "fts5_api_ptr"
|
||||
|
||||
let code = sqlite3_prepare_v3(db.sqliteConnection, "SELECT fts5(?)", -1, 0, &statement, nil)
|
||||
guard code == SQLITE_OK else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
defer { sqlite3_finalize(statement) }
|
||||
type.utf8Start.withMemoryRebound(to: Int8.self, capacity: type.utf8CodeUnitCount) { typePointer in
|
||||
_ = sqlite3_bind_pointer(statement, 1, &api, typePointer, nil)
|
||||
}
|
||||
sqlite3_step(statement)
|
||||
guard let api else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
return api
|
||||
}
|
||||
}
|
||||
|
||||
extension FTS5: VirtualTableModule {
|
||||
/// The virtual table module name
|
||||
public let moduleName = "fts5"
|
||||
public var moduleName: String { "fts5" }
|
||||
|
||||
/// Reserved; part of the VirtualTableModule protocol.
|
||||
///
|
||||
@@ -114,11 +203,11 @@ public struct FTS5: VirtualTableModule {
|
||||
|
||||
switch definition.contentMode {
|
||||
case let .raw(content, contentRowID):
|
||||
if let content = content {
|
||||
if let content {
|
||||
let quotedContent = try content.sqlExpression.quotedSQL(db)
|
||||
arguments.append("content=\(quotedContent)")
|
||||
}
|
||||
if let contentRowID = contentRowID {
|
||||
if let contentRowID {
|
||||
let quotedContentRowID = try contentRowID.sqlExpression.quotedSQL(db)
|
||||
arguments.append("content_rowid=\(quotedContentRowID)")
|
||||
}
|
||||
@@ -203,82 +292,38 @@ public struct FTS5: VirtualTableModule {
|
||||
try db.execute(sql: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')")
|
||||
}
|
||||
}
|
||||
|
||||
static func api(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
// Access to FTS5 is one of the rare SQLite api which was broken in
|
||||
// SQLite 3.20.0+, for security reasons:
|
||||
//
|
||||
// Starting SQLite 3.20.0+, we need to use the new sqlite3_bind_pointer api.
|
||||
// The previous way to access FTS5 does not work any longer.
|
||||
//
|
||||
// So let's see which SQLite version we are linked against:
|
||||
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
// GRDB is linked against SQLCipher or a custom SQLite build: SQLite 3.20.0 or more.
|
||||
return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer)
|
||||
#else
|
||||
// GRDB is linked against the system SQLite.
|
||||
//
|
||||
// Do we use SQLite 3.19.3 (iOS 11.4), or SQLite 3.24.0 (iOS 12.0)?
|
||||
if #available(iOS 12.0, OSX 10.14, tvOS 12.0, watchOS 5.0, *) {
|
||||
// SQLite 3.24.0 or more
|
||||
return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer)
|
||||
} else {
|
||||
// SQLite 3.19.3 or less
|
||||
return api_v1(db)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static func api_v1(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
guard let data = try! Data.fetchOne(db, sql: "SELECT fts5()") else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
return data.withUnsafeBytes {
|
||||
$0.bindMemory(to: UnsafePointer<fts5_api>.self).first!
|
||||
}
|
||||
}
|
||||
|
||||
// Technique given by Jordan Rose:
|
||||
// https://forums.swift.org/t/c-interoperability-combinations-of-library-and-os-versions/14029/4
|
||||
private static func api_v2(
|
||||
_ db: Database,
|
||||
// swiftlint:disable:next line_length
|
||||
_ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer<Int8>?, CInt, CUnsignedInt, UnsafeMutablePointer<OpaquePointer?>?, UnsafeMutablePointer<UnsafePointer<Int8>?>?) -> CInt,
|
||||
// swiftlint:disable:next line_length
|
||||
_ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, CInt, UnsafeMutableRawPointer?, UnsafePointer<Int8>?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> CInt)
|
||||
-> UnsafePointer<fts5_api>
|
||||
{
|
||||
var statement: SQLiteStatement? = nil
|
||||
var api: UnsafePointer<fts5_api>? = nil
|
||||
let type: StaticString = "fts5_api_ptr"
|
||||
|
||||
let code = sqlite3_prepare_v3(db.sqliteConnection, "SELECT fts5(?)", -1, 0, &statement, nil)
|
||||
guard code == SQLITE_OK else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
defer { sqlite3_finalize(statement) }
|
||||
type.utf8Start.withMemoryRebound(to: Int8.self, capacity: type.utf8CodeUnitCount) { typePointer in
|
||||
_ = sqlite3_bind_pointer(statement, 1, &api, typePointer, nil)
|
||||
}
|
||||
sqlite3_step(statement)
|
||||
guard let api else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
return api
|
||||
}
|
||||
}
|
||||
|
||||
/// The FTS5TableDefinition class lets you define columns of a FTS5 virtual table.
|
||||
/// A `FTS5TableDefinition` lets you define the components of an FTS5
|
||||
/// virtual table.
|
||||
///
|
||||
/// You don't create instances of this class. Instead, you use the Database
|
||||
/// `create(virtualTable:using:)` method:
|
||||
/// You don't create instances of this class. Instead, you use the `Database`
|
||||
/// ``Database/create(virtualTable:ifNotExists:using:_:)`` method:
|
||||
///
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html>
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Define Columns
|
||||
///
|
||||
/// - ``column(_:)``
|
||||
///
|
||||
/// ### External Content Tables
|
||||
///
|
||||
/// - ``synchronize(withTable:)``
|
||||
///
|
||||
/// ### FTS5 Options
|
||||
///
|
||||
/// - ``columnSize``
|
||||
/// - ``content``
|
||||
/// - ``contentRowID``
|
||||
/// - ``detail``
|
||||
/// - ``prefixes``
|
||||
/// - ``tokenizer``
|
||||
public final class FTS5TableDefinition {
|
||||
enum ContentMode {
|
||||
case raw(content: String?, contentRowID: String?)
|
||||
@@ -289,25 +334,30 @@ public final class FTS5TableDefinition {
|
||||
fileprivate var columns: [FTS5ColumnDefinition] = []
|
||||
fileprivate var contentMode: ContentMode = .raw(content: nil, contentRowID: nil)
|
||||
|
||||
/// The virtual table tokenizer
|
||||
/// The virtual table tokenizer.
|
||||
///
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.tokenizer = .porter()
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#fts5_table_creation_and_initialization>
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE "documents" USING fts5(tokenize=porter)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.tokenizer = .porter()
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#fts5_table_creation_and_initialization>
|
||||
public var tokenizer: FTS5TokenizerDescriptor?
|
||||
|
||||
/// The FTS5 `content` option
|
||||
/// The FTS5 `content` option.
|
||||
///
|
||||
/// When you want the full-text table to be synchronized with the
|
||||
/// content of an external table, prefer the `synchronize(withTable:)`
|
||||
/// method.
|
||||
/// content of an external table, prefer the
|
||||
/// ``synchronize(withTable:)`` method.
|
||||
///
|
||||
/// Setting this property invalidates any synchronization previously
|
||||
/// established with the `synchronize(withTable:)` method.
|
||||
/// established with the ``synchronize(withTable:)`` method.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#external_content_and_contentless_tables>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#external_content_and_contentless_tables>
|
||||
public var content: String? {
|
||||
get {
|
||||
switch contentMode {
|
||||
@@ -330,13 +380,13 @@ public final class FTS5TableDefinition {
|
||||
/// The FTS5 `content_rowid` option
|
||||
///
|
||||
/// When you want the full-text table to be synchronized with the
|
||||
/// content of an external table, prefer the `synchronize(withTable:)`
|
||||
/// method.
|
||||
/// content of an external table, prefer the
|
||||
/// ``synchronize(withTable:)`` method.
|
||||
///
|
||||
/// Setting this property invalidates any synchronization previously
|
||||
/// established with the `synchronize(withTable:)` method.
|
||||
/// established with the ``synchronize(withTable:)`` method.
|
||||
///
|
||||
/// See <https://sqlite.org/fts5.html#external_content_tables>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#external_content_tables>
|
||||
public var contentRowID: String? {
|
||||
get {
|
||||
switch contentMode {
|
||||
@@ -356,19 +406,19 @@ public final class FTS5TableDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
/// Support for the FTS5 `prefix` option
|
||||
/// The FTS5 `prefix` option.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#prefix_indexes>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#prefix_indexes>
|
||||
public var prefixes: Set<Int>?
|
||||
|
||||
/// Support for the FTS5 `columnsize` option
|
||||
/// The FTS5 `columnsize` option.
|
||||
///
|
||||
/// <https://www.sqlite.org/fts5.html#the_columnsize_option>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#the_columnsize_option>
|
||||
public var columnSize: Int?
|
||||
|
||||
/// Support for the FTS5 `detail` option
|
||||
/// The FTS5 `detail` option.
|
||||
///
|
||||
/// <https://www.sqlite.org/fts5.html#the_detail_option>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#the_detail_option>
|
||||
public var detail: String?
|
||||
|
||||
init(configuration: VirtualTableConfiguration) {
|
||||
@@ -377,11 +427,18 @@ public final class FTS5TableDefinition {
|
||||
|
||||
/// Appends a table column.
|
||||
///
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // CREATE VIRTUAL TABLE document USING fts5(content)
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// - parameter name: the column name.
|
||||
/// - returns: A ``FTS5ColumnDefinition`` that allows you to refine the
|
||||
/// column definition.
|
||||
@discardableResult
|
||||
public func column(_ name: String) -> FTS5ColumnDefinition {
|
||||
let column = FTS5ColumnDefinition(name: name)
|
||||
@@ -396,22 +453,50 @@ public final class FTS5TableDefinition {
|
||||
/// content in the external table. SQL triggers make sure that the
|
||||
/// full-text table is kept up to date with the external table.
|
||||
///
|
||||
/// See <https://sqlite.org/fts5.html#external_content_tables>
|
||||
/// SQLite automatically deletes those triggers when the content
|
||||
/// (not full-text) table is dropped.
|
||||
///
|
||||
/// However, those triggers remain after the full-text table has been
|
||||
/// dropped. Unless they are dropped too, they will prevent future
|
||||
/// insertion, updates, and deletions in the content table, and the creation
|
||||
/// of a new full-text table.
|
||||
///
|
||||
/// To drop those triggers, call the `Database`
|
||||
/// ``Database/dropFTS5SynchronizationTriggers(forTable:)`` method:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create tables
|
||||
/// try db.create(table: "book") { t in
|
||||
/// ...
|
||||
/// }
|
||||
/// try db.create(virtualTable: "book_ft", using: FTS5()) { t in
|
||||
/// t.synchronize(withTable: "book")
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// // Drop full-text table
|
||||
/// try db.drop(table: "book_ft")
|
||||
/// try db.dropFTS5SynchronizationTriggers(forTable: "book_ft")
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://sqlite.org/fts5.html#external_content_tables>
|
||||
public func synchronize(withTable tableName: String) {
|
||||
contentMode = .synchronized(contentTable: tableName)
|
||||
}
|
||||
}
|
||||
|
||||
/// The FTS5ColumnDefinition class lets you refine a column of an FTS5
|
||||
/// virtual table.
|
||||
/// Describes a column in an ``FTS5`` virtual table.
|
||||
///
|
||||
/// You get instances of this class when you create an FTS5 table:
|
||||
/// You get instances of `FTS5ColumnDefinition` when you create an ``FTS5``
|
||||
/// virtual table. For example:
|
||||
///
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content") // FTS5ColumnDefinition
|
||||
/// }
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("content") // FTS5ColumnDefinition
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html>
|
||||
public final class FTS5ColumnDefinition {
|
||||
fileprivate let name: String
|
||||
fileprivate var isIndexed: Bool
|
||||
@@ -423,14 +508,18 @@ public final class FTS5ColumnDefinition {
|
||||
|
||||
/// Excludes the column from the full-text index.
|
||||
///
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("a")
|
||||
/// t.column("b").notIndexed()
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#the_unindexed_column_option>
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "document", using: FTS5()) { t in
|
||||
/// t.column("a")
|
||||
/// t.column("b").notIndexed()
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#the_unindexed_column_option>
|
||||
///
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func notIndexed() -> Self {
|
||||
self.isIndexed = false
|
||||
@@ -439,7 +528,7 @@ public final class FTS5ColumnDefinition {
|
||||
}
|
||||
|
||||
extension Column {
|
||||
/// The FTS5 rank column
|
||||
/// The ``FTS5`` rank column.
|
||||
public static let rank = Column("rank")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
|
||||
/// The protocol for custom FTS5 tokenizers.
|
||||
/// A type that implements a custom tokenizer for the ``FTS5`` full-text engine.
|
||||
///
|
||||
/// See [FTS5 Tokenizers](https://github.com/groue/GRDB.swift/blob/master/Documentation/FTS5Tokenizers.md)
|
||||
/// for more information.
|
||||
public protocol FTS5CustomTokenizer: FTS5Tokenizer {
|
||||
/// The name of the tokenizer; should uniquely identify your custom
|
||||
/// tokenizer.
|
||||
/// The name of the tokenizer.
|
||||
///
|
||||
/// The name should uniquely identify the tokenizer: don't use a built-in
|
||||
/// name such as `ascii`, `porter` or `unicode61`.
|
||||
static var name: String { get }
|
||||
|
||||
/// Creates a custom tokenizer.
|
||||
@@ -27,7 +31,7 @@ extension FTS5CustomTokenizer {
|
||||
///
|
||||
/// class MyTokenizer : FTS5CustomTokenizer { ... }
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// let tokenizer = MyTokenizer.tokenizerDescriptor(arguments: ["unicode61", "remove_diacritics", "0"])
|
||||
/// t.tokenizer = tokenizer
|
||||
/// }
|
||||
@@ -108,7 +112,7 @@ extension Database {
|
||||
}
|
||||
let constructor = Unmanaged<FTS5TokenizerConstructor>.fromOpaque(constructorPointer).takeUnretainedValue()
|
||||
var arguments: [String] = []
|
||||
if let azArg = azArg {
|
||||
if let azArg {
|
||||
for i in 0..<Int(nArg) {
|
||||
if let cstr = azArg[i] {
|
||||
arguments.append(String(cString: cstr))
|
||||
|
||||
+90
-32
@@ -1,17 +1,40 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
/// A full text pattern for querying FTS5 virtual tables.
|
||||
/// A full text pattern for querying ``FTS5`` virtual tables.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#full_text_query_syntax>
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Creating Raw FTS5 Patterns
|
||||
///
|
||||
/// - ``Database/makeFTS5Pattern(rawPattern:forTable:)``
|
||||
///
|
||||
/// ### Creating FTS5 Patterns from User Input
|
||||
///
|
||||
/// - ``init(matchingAllPrefixesIn:)``
|
||||
/// - ``init(matchingAllTokensIn:)``
|
||||
/// - ``init(matchingAnyTokenIn:)``
|
||||
/// - ``init(matchingPhrase:)``
|
||||
/// - ``init(matchingPrefixPhrase:)``
|
||||
public struct FTS5Pattern {
|
||||
|
||||
/// The raw pattern string. Guaranteed to be a valid FTS5 pattern.
|
||||
/// The raw pattern string.
|
||||
///
|
||||
/// It is guaranteed to be a valid FTS5 pattern.
|
||||
public let rawPattern: String
|
||||
|
||||
/// Creates a pattern that matches any token found in the input string;
|
||||
/// returns nil if no pattern could be built.
|
||||
/// Creates a pattern that matches any token found in the input string.
|
||||
///
|
||||
/// FTS5Pattern(matchingAnyTokenIn: "") // nil
|
||||
/// FTS5Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar
|
||||
/// The result is nil if no pattern could be built.
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// FTS5Pattern(matchingAnyTokenIn: "") // nil
|
||||
/// FTS5Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern.
|
||||
public init?(matchingAnyTokenIn string: String) {
|
||||
guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else {
|
||||
return nil
|
||||
@@ -19,13 +42,18 @@ public struct FTS5Pattern {
|
||||
try? self.init(rawPattern: tokens.joined(separator: " OR "))
|
||||
}
|
||||
|
||||
/// Creates a pattern that matches all tokens found in the input string;
|
||||
/// returns nil if no pattern could be built.
|
||||
/// Creates a pattern that matches all tokens found in the input string.
|
||||
///
|
||||
/// FTS5Pattern(matchingAllTokensIn: "") // nil
|
||||
/// FTS5Pattern(matchingAllTokensIn: "foo bar") // foo bar
|
||||
/// The result is nil if no pattern could be built.
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// FTS5Pattern(matchingAllTokensIn: "") // nil
|
||||
/// FTS5Pattern(matchingAllTokensIn: "foo bar") // foo bar
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern.
|
||||
public init?(matchingAllTokensIn string: String) {
|
||||
guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else {
|
||||
return nil
|
||||
@@ -34,12 +62,18 @@ public struct FTS5Pattern {
|
||||
}
|
||||
|
||||
/// Creates a pattern that matches all token prefixes found in the input
|
||||
/// string; returns nil if no pattern could be built.
|
||||
/// string.
|
||||
///
|
||||
/// FTS3Pattern(matchingAllTokensIn: "") // nil
|
||||
/// FTS3Pattern(matchingAllTokensIn: "foo bar") // foo* bar*
|
||||
/// The result is nil if no pattern could be built.
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS3 pattern
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// FTS5Pattern(matchingAllTokensIn: "") // nil
|
||||
/// FTS5Pattern(matchingAllTokensIn: "foo bar") // foo* bar*
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern.
|
||||
public init?(matchingAllPrefixesIn string: String) {
|
||||
guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else {
|
||||
return nil
|
||||
@@ -47,13 +81,18 @@ public struct FTS5Pattern {
|
||||
try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " "))
|
||||
}
|
||||
|
||||
/// Creates a pattern that matches a contiguous string; returns nil if no
|
||||
/// pattern could be built.
|
||||
/// Creates a pattern that matches a contiguous string.
|
||||
///
|
||||
/// FTS5Pattern(matchingPhrase: "") // nil
|
||||
/// FTS5Pattern(matchingPhrase: "foo bar") // "foo bar"
|
||||
/// The result is nil if no pattern could be built.
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// FTS5Pattern(matchingPhrase: "") // nil
|
||||
/// FTS5Pattern(matchingPhrase: "foo bar") // "foo bar"
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern.
|
||||
public init?(matchingPhrase string: String) {
|
||||
guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else {
|
||||
return nil
|
||||
@@ -61,14 +100,20 @@ public struct FTS5Pattern {
|
||||
try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"")
|
||||
}
|
||||
|
||||
/// Creates a pattern that matches the prefix of an indexed document;
|
||||
/// returns nil if no pattern could be built.
|
||||
/// Creates a pattern that matches the prefix of an indexed document.
|
||||
///
|
||||
/// FTS5Pattern(matchingPrefixPhrase: "") // nil
|
||||
/// FTS5Pattern(matchingPrefixPhrase: "the word") // ^"the word"
|
||||
/// The result is nil if no pattern could be built.
|
||||
///
|
||||
/// This pattern matches a prefix made of full tokens: "the bat" matches
|
||||
/// "the bat is happy", but not "mind the bat", or "the batcave is dark".
|
||||
/// The returned pattern matches a prefix made of full tokens: "the bat"
|
||||
/// matches "the bat is happy", but not "mind the bat", or "the batcave
|
||||
/// is dark".
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// FTS5Pattern(matchingPrefixPhrase: "") // nil
|
||||
/// FTS5Pattern(matchingPrefixPhrase: "the word") // ^"the word"
|
||||
/// ```
|
||||
///
|
||||
/// - parameter string: The string to turn into an FTS5 pattern
|
||||
public init?(matchingPrefixPhrase string: String) {
|
||||
@@ -113,13 +158,26 @@ extension Database {
|
||||
|
||||
// MARK: - FTS5
|
||||
|
||||
/// Creates a pattern from a raw pattern string; throws DatabaseError on
|
||||
/// invalid syntax.
|
||||
/// Creates an FTS5 pattern from a raw pattern string.
|
||||
///
|
||||
/// The pattern syntax is documented at <https://www.sqlite.org/fts5.html#full_text_query_syntax>
|
||||
/// For example:
|
||||
///
|
||||
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK
|
||||
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND]
|
||||
/// ```swift
|
||||
/// try dbQueue.read { db in
|
||||
/// // OK
|
||||
/// let pattern = try db.makeFTS5Pattern(rawPattern: "and", forTable: "document")
|
||||
///
|
||||
/// // Throws error: malformed MATCH expression: [AND]
|
||||
/// let pattern = try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document")
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// - parameter rawPattern: A pattern that follows the
|
||||
/// [Full-text Query Syntax](https://www.sqlite.org/fts5.html#full_text_query_syntax).
|
||||
/// - parameter table: The full-text table that the pattern is intended to
|
||||
/// match against.
|
||||
/// - returns: A valid FTS5 pattern.
|
||||
/// - throws: A ``DatabaseError`` if the raw pattern is invalid.
|
||||
public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern {
|
||||
try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map(\.name))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import Foundation
|
||||
|
||||
/// A low-level SQLite function that lets FTS5Tokenizer notify tokens.
|
||||
///
|
||||
/// See FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:)
|
||||
/// See ``FTS5Tokenizer/tokenize(context:tokenization:pText:nText:tokenCallback:)``.
|
||||
public typealias FTS5TokenCallback = @convention(c) (
|
||||
_ context: UnsafeMutableRawPointer?,
|
||||
_ flags: CInt,
|
||||
@@ -15,7 +15,7 @@ public typealias FTS5TokenCallback = @convention(c) (
|
||||
|
||||
/// The reason why FTS5 is requesting tokenization.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#custom_tokenizers>
|
||||
/// See the `FTS5_TOKENIZE_*` constants in <https://www.sqlite.org/fts5.html#custom_tokenizers>.
|
||||
public struct FTS5Tokenization: OptionSet {
|
||||
public let rawValue: CInt
|
||||
|
||||
@@ -23,20 +23,42 @@ public struct FTS5Tokenization: OptionSet {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
/// FTS5_TOKENIZE_QUERY
|
||||
/// `FTS5_TOKENIZE_QUERY`
|
||||
public static let query = FTS5Tokenization(rawValue: FTS5_TOKENIZE_QUERY)
|
||||
|
||||
/// FTS5_TOKENIZE_PREFIX
|
||||
/// `FTS5_TOKENIZE_PREFIX`
|
||||
public static let prefix = FTS5Tokenization(rawValue: FTS5_TOKENIZE_PREFIX)
|
||||
|
||||
/// FTS5_TOKENIZE_DOCUMENT
|
||||
/// `FTS5_TOKENIZE_DOCUMENT`
|
||||
public static let document = FTS5Tokenization(rawValue: FTS5_TOKENIZE_DOCUMENT)
|
||||
|
||||
/// FTS5_TOKENIZE_AUX
|
||||
/// `FTS5_TOKENIZE_AUX`
|
||||
public static let aux = FTS5Tokenization(rawValue: FTS5_TOKENIZE_AUX)
|
||||
}
|
||||
|
||||
/// The protocol for FTS5 tokenizers
|
||||
/// A type that implements a tokenizer for the ``FTS5`` full-text engine.
|
||||
///
|
||||
/// You can instantiate tokenizers, including
|
||||
/// [built-in tokenizers](https://www.sqlite.org/fts5.html#tokenizers),
|
||||
/// with the ``Database/makeTokenizer(_:)`` method:
|
||||
///
|
||||
/// ```swift
|
||||
/// try dbQueue.read { db in
|
||||
/// let unicode61 = try db.makeTokenizer(.unicode61()) // FTS5Tokenizer
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See [FTS5 Tokenizers](https://github.com/groue/GRDB.swift/blob/master/Documentation/FTS5Tokenizers.md)
|
||||
/// for more information.
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Tokenizing Text
|
||||
///
|
||||
/// - ``tokenize(document:)``
|
||||
/// - ``tokenize(query:)``
|
||||
/// - ``tokenize(context:tokenization:pText:nText:tokenCallback:)``
|
||||
/// - ``FTS5TokenCallback``
|
||||
public protocol FTS5Tokenizer: AnyObject {
|
||||
/// Tokenizes the text described by `pText` and `nText`, and
|
||||
/// notifies found tokens to the `tokenCallback` function.
|
||||
@@ -72,8 +94,10 @@ extension FTS5Tokenizer {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// let tokenizer = try db.makeTokenizer(.ascii())
|
||||
/// try tokenizer.tokenize(document: "foo bar") // [("foo", flags), ("bar", flags)]
|
||||
/// ```swift
|
||||
/// let tokenizer = try db.makeTokenizer(.ascii())
|
||||
/// try tokenizer.tokenize(document: "foo bar") // [("foo", flags), ("bar", flags)]
|
||||
/// ```
|
||||
///
|
||||
/// See also `tokenize(query:)`.
|
||||
///
|
||||
@@ -88,8 +112,10 @@ extension FTS5Tokenizer {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// let tokenizer = try db.makeTokenizer(.ascii())
|
||||
/// try tokenizer.tokenize(query: "foo bar") // [("foo", flags), ("bar", flags)]
|
||||
/// ```swift
|
||||
/// let tokenizer = try db.makeTokenizer(.ascii())
|
||||
/// try tokenizer.tokenize(query: "foo bar") // [("foo", flags), ("bar", flags)]
|
||||
/// ```
|
||||
///
|
||||
/// See also `tokenize(document:)`.
|
||||
///
|
||||
@@ -210,7 +236,7 @@ extension Database {
|
||||
throw DatabaseError(resultCode: code, message: "failed fts5_tokenizer.xCreate")
|
||||
}
|
||||
|
||||
if let tokenizerPointer = tokenizerPointer {
|
||||
if let tokenizerPointer {
|
||||
self.tokenizerPointer = tokenizerPointer
|
||||
} else {
|
||||
throw DatabaseError(resultCode: code, message: "nil tokenizer")
|
||||
@@ -240,20 +266,27 @@ extension Database {
|
||||
|
||||
/// Creates an FTS5 tokenizer, given its descriptor.
|
||||
///
|
||||
/// let unicode61 = try db.makeTokenizer(.unicode61())
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// let unicode61 = try db.makeTokenizer(.unicode61())
|
||||
/// ```
|
||||
///
|
||||
/// You can use this method when you implement a custom wrapper tokenizer
|
||||
/// with ``FTS5WrapperTokenizer``:
|
||||
///
|
||||
/// ```swift
|
||||
/// final class MyTokenizer : FTS5WrapperTokenizer {
|
||||
/// var wrappedTokenizer: FTS5Tokenizer
|
||||
///
|
||||
/// init(db: Database, arguments: [String]) throws {
|
||||
/// wrappedTokenizer = try db.makeTokenizer(.unicode61())
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// It is a programmer error to use the tokenizer outside of a protected
|
||||
/// database queue, or after the database has been closed.
|
||||
///
|
||||
/// Use this method when you implement a custom wrapper tokenizer:
|
||||
///
|
||||
/// final class MyTokenizer : FTS5WrapperTokenizer {
|
||||
/// var wrappedTokenizer: FTS5Tokenizer
|
||||
///
|
||||
/// init(db: Database, arguments: [String]) throws {
|
||||
/// wrappedTokenizer = try db.makeTokenizer(.unicode61())
|
||||
/// }
|
||||
/// }
|
||||
public func makeTokenizer(_ descriptor: FTS5TokenizerDescriptor) throws -> any FTS5Tokenizer {
|
||||
let api = FTS5.api(self)
|
||||
|
||||
|
||||
@@ -1,61 +1,109 @@
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
/// An FTS5 tokenizer, suitable for FTS5 table definitions:
|
||||
/// The descriptor for an ``FTS5`` tokenizer.
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#tokenizers>
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#tokenizers>
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Creating Tokenizer Descriptors
|
||||
///
|
||||
/// - ``init(components:)``
|
||||
/// - ``ascii(separators:tokenCharacters:)``
|
||||
/// - ``porter(wrapping:)``
|
||||
/// - ``unicode61(diacritics:categories:separators:tokenCharacters:)``
|
||||
/// - ``FTS5/Diacritics``
|
||||
///
|
||||
/// ### Instantiating Tokenizers
|
||||
///
|
||||
/// - ``Database/makeTokenizer(_:)``
|
||||
public struct FTS5TokenizerDescriptor {
|
||||
/// The tokenizer components
|
||||
/// The tokenizer components.
|
||||
///
|
||||
/// // ["unicode61"]
|
||||
/// FTS5TokenizerDescriptor.unicode61().components
|
||||
/// For example:
|
||||
///
|
||||
/// // ["unicode61", "remove_diacritics", "0"]
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).components
|
||||
/// ```swift
|
||||
/// // ["unicode61"]
|
||||
/// FTS5TokenizerDescriptor.unicode61().components
|
||||
///
|
||||
/// // ["unicode61", "remove_diacritics", "0"]
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).components
|
||||
/// ```
|
||||
public let components: [String]
|
||||
|
||||
/// The tokenizer name
|
||||
/// The tokenizer name.
|
||||
///
|
||||
/// // "unicode61"
|
||||
/// FTS5TokenizerDescriptor.unicode61().name
|
||||
/// For example:
|
||||
///
|
||||
/// // "unicode61"
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).name
|
||||
/// ```swift
|
||||
/// // "unicode61"
|
||||
/// FTS5TokenizerDescriptor.unicode61().name
|
||||
///
|
||||
/// // "unicode61"
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).name
|
||||
/// ```
|
||||
var name: String { components[0] }
|
||||
|
||||
/// The tokenizer arguments.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // []
|
||||
/// FTS5TokenizerDescriptor.unicode61().components
|
||||
///
|
||||
/// // ["remove_diacritics", "0"]
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).components
|
||||
/// ```
|
||||
var arguments: [String] {
|
||||
Array(components.suffix(from: 1))
|
||||
}
|
||||
|
||||
/// Creates an FTS5 tokenizer descriptor.
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// let tokenizer = FTS5TokenizerDescriptor(components: ["porter", "unicode61", "remove_diacritics", "0"])
|
||||
/// t.tokenizer = tokenizer
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// - precondition: Components is not empty
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = FTS5TokenizerDescriptor(components: [
|
||||
/// "porter",
|
||||
/// "unicode61",
|
||||
/// "remove_diacritics",
|
||||
/// "0"])
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// - precondition: Components is not empty.
|
||||
public init(components: [String]) {
|
||||
GRDBPrecondition(!components.isEmpty, "FTS5TokenizerDescriptor requires at least one component")
|
||||
assert(!components.isEmpty)
|
||||
self.components = components
|
||||
}
|
||||
|
||||
/// The "ascii" tokenizer
|
||||
/// The "ascii" tokenizer.
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .ascii()
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .ascii()
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#ascii_tokenizer>
|
||||
///
|
||||
/// - parameters:
|
||||
/// - separators: Unless empty (the default), SQLite will consider
|
||||
/// these characters as token separators.
|
||||
/// - tokenCharacters: Unless empty (the default), SQLite will
|
||||
/// consider these characters as token characters.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#ascii_tokenizer>
|
||||
public static func ascii(
|
||||
separators: Set<Character> = [],
|
||||
tokenCharacters: Set<Character> = [])
|
||||
@@ -78,30 +126,39 @@ public struct FTS5TokenizerDescriptor {
|
||||
return FTS5TokenizerDescriptor(components: components)
|
||||
}
|
||||
|
||||
/// The "porter" tokenizer
|
||||
/// The "porter" tokenizer.
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .porter()
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// - parameters:
|
||||
/// - base: An eventual wrapping tokenizer which replaces the
|
||||
// default unicode61() base tokenizer.
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .porter()
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#porter_tokenizer>
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#porter_tokenizer>
|
||||
///
|
||||
/// - parameter base: An eventual wrapping tokenizer which replaces the
|
||||
/// default unicode61() base tokenizer.
|
||||
public static func porter(wrapping base: FTS5TokenizerDescriptor? = nil) -> FTS5TokenizerDescriptor {
|
||||
if let base = base {
|
||||
if let base {
|
||||
return FTS5TokenizerDescriptor(components: ["porter"] + base.components)
|
||||
} else {
|
||||
return FTS5TokenizerDescriptor(components: ["porter"])
|
||||
}
|
||||
}
|
||||
|
||||
/// An "unicode61" tokenizer
|
||||
/// The "unicode61" tokenizer.
|
||||
///
|
||||
/// db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .unicode61()
|
||||
/// }
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// try db.create(virtualTable: "book", using: FTS5()) { t in
|
||||
/// t.tokenizer = .unicode61()
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/fts5.html#unicode61_tokenizer>
|
||||
///
|
||||
/// - parameters:
|
||||
/// - diacritics: By default SQLite will strip diacritics from
|
||||
@@ -112,8 +169,6 @@ public struct FTS5TokenizerDescriptor {
|
||||
/// these characters as token separators.
|
||||
/// - tokenCharacters: Unless empty (the default), SQLite will
|
||||
/// consider these characters as token characters.
|
||||
///
|
||||
/// See <https://www.sqlite.org/fts5.html#unicode61_tokenizer>
|
||||
public static func unicode61(
|
||||
diacritics: FTS5.Diacritics = .removeLegacy,
|
||||
categories: String = "",
|
||||
|
||||
@@ -3,7 +3,7 @@ import Foundation
|
||||
|
||||
/// Flags that tell SQLite how to register a token.
|
||||
///
|
||||
/// See the `FTS5_TOKEN_*` flags in <https://www.sqlite.org/fts5.html#custom_tokenizers>.
|
||||
/// See the `FTS5_TOKEN_*` constants in <https://www.sqlite.org/fts5.html#custom_tokenizers>.
|
||||
public struct FTS5TokenFlags: OptionSet {
|
||||
public let rawValue: CInt
|
||||
|
||||
@@ -11,7 +11,7 @@ public struct FTS5TokenFlags: OptionSet {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
/// FTS5_TOKEN_COLOCATED
|
||||
/// `FTS5_TOKEN_COLOCATED`
|
||||
public static let colocated = FTS5TokenFlags(rawValue: FTS5_TOKEN_COLOCATED)
|
||||
}
|
||||
|
||||
@@ -20,34 +20,18 @@ public struct FTS5TokenFlags: OptionSet {
|
||||
/// See FTS5WrapperTokenizer.accept(token:flags:tokenCallback:)
|
||||
public typealias FTS5WrapperTokenCallback = (_ token: String, _ flags: FTS5TokenFlags) throws -> Void
|
||||
|
||||
/// The protocol for custom FTS5 tokenizers that wrap another tokenizer.
|
||||
/// A type that implements a custom tokenizer for the ``FTS5`` full-text engine
|
||||
/// by wrapping another tokenizer.
|
||||
///
|
||||
/// Types that adopt FTS5WrapperTokenizer don't have to implement the
|
||||
/// low-level FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:).
|
||||
/// See [FTS5 Tokenizers](https://github.com/groue/GRDB.swift/blob/master/Documentation/FTS5Tokenizers.md)
|
||||
/// for more information.
|
||||
///
|
||||
/// Instead, they process regular Swift strings.
|
||||
/// ## Topics
|
||||
///
|
||||
/// Here is the implementation for a trivial tokenizer that wraps the
|
||||
/// built-in ascii tokenizer without any custom processing:
|
||||
/// ### Tokenizing Text
|
||||
///
|
||||
/// class TrivialAsciiTokenizer : FTS5WrapperTokenizer {
|
||||
/// static let name = "trivial"
|
||||
/// let wrappedTokenizer: FTS5Tokenizer
|
||||
///
|
||||
/// init(db: Database, arguments: [String]) throws {
|
||||
/// wrappedTokenizer = try db.makeTokenizer(.ascii())
|
||||
/// }
|
||||
///
|
||||
/// func accept(
|
||||
/// token: String,
|
||||
/// flags: FTS5TokenFlags,
|
||||
/// for tokenization: FTS5Tokenization,
|
||||
/// tokenCallback: FTS5WrapperTokenCallback)
|
||||
/// throws
|
||||
/// {
|
||||
/// try tokenCallback(token, flags)
|
||||
/// }
|
||||
/// }
|
||||
/// - ``accept(token:flags:for:tokenCallback:)``
|
||||
/// - ``FTS5WrapperTokenCallback``
|
||||
public protocol FTS5WrapperTokenizer: FTS5CustomTokenizer {
|
||||
/// The wrapped tokenizer
|
||||
var wrappedTokenizer: any FTS5Tokenizer { get }
|
||||
@@ -57,16 +41,17 @@ public protocol FTS5WrapperTokenizer: FTS5CustomTokenizer {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// func accept(
|
||||
/// token: String,
|
||||
/// flags: FTS5TokenFlags,
|
||||
/// for tokenization: FTS5Tokenization,
|
||||
/// tokenCallback: FTS5WrapperTokenCallback)
|
||||
/// throws
|
||||
/// {
|
||||
/// // pass through:
|
||||
/// try tokenCallback(token, flags)
|
||||
/// }
|
||||
/// ```swift
|
||||
/// func accept(
|
||||
/// token: String,
|
||||
/// flags: FTS5TokenFlags,
|
||||
/// for tokenization: FTS5Tokenization,
|
||||
/// tokenCallback: FTS5WrapperTokenCallback
|
||||
/// ) throws {
|
||||
/// // pass through:
|
||||
/// try tokenCallback(token, flags)
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// When implementing the accept method, there are a two rules
|
||||
/// to observe:
|
||||
@@ -74,8 +59,8 @@ public protocol FTS5WrapperTokenizer: FTS5CustomTokenizer {
|
||||
/// 1. Errors thrown by the tokenCallback function must not be caught.
|
||||
///
|
||||
/// 2. The input `flags` should be given unmodified to the tokenCallback
|
||||
/// function, unless you union it with the .colocated flag when the
|
||||
/// tokenizer produces synonyms (see
|
||||
/// function, unless you union it with the ``FTS5TokenFlags/colocated`` flag
|
||||
/// when the tokenizer produces synonyms (see
|
||||
/// <https://www.sqlite.org/fts5.html#synonym_support>).
|
||||
///
|
||||
/// - parameters:
|
||||
@@ -99,7 +84,6 @@ private struct FTS5WrapperContext {
|
||||
}
|
||||
|
||||
extension FTS5WrapperTokenizer {
|
||||
/// Default implementation
|
||||
public func tokenize(
|
||||
context: UnsafeMutableRawPointer?,
|
||||
tokenization: FTS5Tokenization,
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ extension PersistableRecord {
|
||||
public func performSave(_ db: Database) throws { preconditionFailure() }
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension QueryInterfaceRequest where RowDecoder: Identifiable, RowDecoder.ID: DatabaseValueConvertible {
|
||||
@available(*, unavailable, message: "selectID() has been removed. You may use selectPrimaryKey(as:) instead.")
|
||||
public func selectID() -> QueryInterfaceRequest<RowDecoder.ID> { preconditionFailure() }
|
||||
@@ -144,13 +144,13 @@ extension SelectionRequest {
|
||||
@available(*, unavailable, renamed: "SQLExpression.AssociativeBinaryOperator")
|
||||
public typealias SQLAssociativeBinaryOperator = SQLExpression.AssociativeBinaryOperator
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Table where RowDecoder: Identifiable, RowDecoder.ID: DatabaseValueConvertible {
|
||||
@available(*, unavailable, message: "selectID() has been removed. You may use selectPrimaryKey(as:) instead.")
|
||||
public func selectID() -> QueryInterfaceRequest<RowDecoder.ID> { preconditionFailure() }
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
@available(*, unavailable, message: "selectID() has been removed. You may use selectPrimaryKey(as:) instead.")
|
||||
public static func selectID() -> QueryInterfaceRequest<ID> { preconditionFailure() }
|
||||
|
||||
@@ -490,7 +490,7 @@ extension DatabaseMigrator {
|
||||
/// - parameter writer: A DatabaseWriter.
|
||||
/// where migrations should apply.
|
||||
/// - parameter scheduler: A Combine Scheduler.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func migratePublisher(
|
||||
_ writer: some DatabaseWriter,
|
||||
receiveOn scheduler: some Scheduler = DispatchQueue.main)
|
||||
@@ -508,7 +508,7 @@ extension DatabaseMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabasePublishers {
|
||||
/// A publisher that migrates a database.
|
||||
///
|
||||
|
||||
@@ -77,7 +77,7 @@ public struct BelongsToAssociation<Origin, Destination> {
|
||||
originIsLeft: true)
|
||||
|
||||
let associationKey: SQLAssociationKey
|
||||
if let key = key {
|
||||
if let key {
|
||||
associationKey = .fixedSingular(key)
|
||||
} else {
|
||||
associationKey = .inflected(destinationTable)
|
||||
|
||||
@@ -77,7 +77,7 @@ public struct HasManyAssociation<Origin, Destination> {
|
||||
originIsLeft: false)
|
||||
|
||||
let associationKey: SQLAssociationKey
|
||||
if let key = key {
|
||||
if let key {
|
||||
associationKey = .fixedPlural(key)
|
||||
} else {
|
||||
associationKey = .inflected(destinationTable)
|
||||
|
||||
@@ -80,7 +80,7 @@ public struct HasOneAssociation<Origin, Destination> {
|
||||
originIsLeft: false)
|
||||
|
||||
let associationKey: SQLAssociationKey
|
||||
if let key = key {
|
||||
if let key {
|
||||
associationKey = .fixedSingular(key)
|
||||
} else {
|
||||
associationKey = .inflected(destinationTable)
|
||||
|
||||
@@ -334,7 +334,7 @@ struct SQLCTE {
|
||||
|
||||
/// The number of columns in the common table expression.
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
if let columns = columns {
|
||||
if let columns {
|
||||
// No need to hit the database
|
||||
return columns.count
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A prepared statement.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchStatement(
|
||||
_ db: Database,
|
||||
selection: [any SQLSelectable])
|
||||
@@ -668,7 +668,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A ``RecordCursor`` over deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchCursor(_ db: Database)
|
||||
throws -> RecordCursor<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -696,7 +696,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchAll(_ db: Database)
|
||||
throws -> [RowDecoder]
|
||||
where RowDecoder: FetchableRecord & TableRecord
|
||||
@@ -723,7 +723,7 @@ extension QueryInterfaceRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A set of deleted records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func deleteAndFetchSet(_ db: Database)
|
||||
throws -> Set<RowDecoder>
|
||||
where RowDecoder: FetchableRecord & TableRecord & Hashable
|
||||
@@ -995,7 +995,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A prepared statement.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `selection` and `assignments` are not empty.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchStatement(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -1043,7 +1043,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A cursor over the updated records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchCursor(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -1081,7 +1081,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: An array of updated records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchAll(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -1114,7 +1114,7 @@ extension QueryInterfaceRequest {
|
||||
/// - returns: A set of updated records.
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
|
||||
/// - precondition: `assignments` is not empty.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetchSet(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
|
||||
@@ -316,7 +316,8 @@ extension FilteredRequest {
|
||||
/// - ``filter(key:)-2te6v``
|
||||
/// - ``filter(keys:)-6ggt1``
|
||||
/// - ``filter(keys:)-8fbn9``
|
||||
/// - ``matching(_:)``
|
||||
/// - ``matching(_:)-3s3zr``
|
||||
/// - ``matching(_:)-7c1e8``
|
||||
///
|
||||
/// ### The GROUP BY and HAVING Clauses
|
||||
///
|
||||
@@ -570,7 +571,7 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRequest
|
||||
where Self: FilteredRequest,
|
||||
Self: TypedRequest,
|
||||
@@ -1337,7 +1338,8 @@ extension JoinableRequest where Self: SelectionRequest {
|
||||
/// - ``FilteredRequest/filter(literal:)``
|
||||
/// - ``FilteredRequest/filter(sql:arguments:)``
|
||||
/// - ``FilteredRequest/filterWhenConnected(_:)``
|
||||
/// - ``TableRequest/matching(_:)``
|
||||
/// - ``TableRequest/matching(_:)-3s3zr``
|
||||
/// - ``TableRequest/matching(_:)-7c1e8``
|
||||
/// - ``FilteredRequest/none()``
|
||||
///
|
||||
/// ### The GROUP BY and HAVING Clauses
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
/// ### Deriving SQL Expressions
|
||||
///
|
||||
/// - ``detached``
|
||||
/// - ``match(_:)``
|
||||
/// - ``match(_:)-727nk``
|
||||
/// - ``match(_:)-1vvo8``
|
||||
///
|
||||
/// ### Creating Column Assignments
|
||||
///
|
||||
|
||||
@@ -979,7 +979,7 @@ extension SQLExpression {
|
||||
\(op.sql) \
|
||||
\(rhs.sql(context, wrappedInParenthesis: true))
|
||||
"""
|
||||
if let escape = escape {
|
||||
if let escape {
|
||||
resultSQL += try " ESCAPE \(escape.sql(context, wrappedInParenthesis: true))"
|
||||
}
|
||||
if wrappedInParenthesis {
|
||||
@@ -1893,13 +1893,13 @@ extension SQLSpecificExpressible {
|
||||
}
|
||||
#elseif !GRDBCIPHER
|
||||
/// An ordering term for ascending order (nulls last).
|
||||
@available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *)
|
||||
@available(iOS 14, macOS 10.16, tvOS 14, watchOS 7, *) // SQLite 3.30+
|
||||
public var ascNullsLast: SQLOrdering {
|
||||
.ascNullsLast(sqlExpression)
|
||||
}
|
||||
|
||||
/// An ordering term for descending order (nulls first).
|
||||
@available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *)
|
||||
@available(iOS 14, macOS 10.16, tvOS 14, watchOS 7, *) // SQLite 3.30+
|
||||
public var descNullsFirst: SQLOrdering {
|
||||
.descNullsFirst(sqlExpression)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ struct SQLForeignKeyRequest {
|
||||
|
||||
/// The (origin, destination) column pairs that join a left table to a right table.
|
||||
func fetchForeignKeyMapping(_ db: Database) throws -> ForeignKeyMapping {
|
||||
if let originColumns = originColumns, let destinationColumns = destinationColumns {
|
||||
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")
|
||||
let mapping = zip(originColumns, destinationColumns).map {
|
||||
@@ -36,14 +36,14 @@ struct SQLForeignKeyRequest {
|
||||
if destinationTable.lowercased() != foreignKey.destinationTable.lowercased() {
|
||||
return false
|
||||
}
|
||||
if let originColumns = originColumns {
|
||||
if let originColumns {
|
||||
let originColumns = Set(originColumns.lazy.map { $0.lowercased() })
|
||||
let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.origin.lowercased() })
|
||||
if originColumns != foreignKeyColumns {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if let destinationColumns = destinationColumns {
|
||||
if let destinationColumns {
|
||||
// TODO: test
|
||||
let destinationColumns = Set(destinationColumns.lazy.map { $0.lowercased() })
|
||||
let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.destination.lowercased() })
|
||||
@@ -66,7 +66,7 @@ struct SQLForeignKeyRequest {
|
||||
}
|
||||
|
||||
// No matching foreign key found: use the destination primary key
|
||||
if let originColumns = originColumns {
|
||||
if let originColumns {
|
||||
let destinationColumns = try db.primaryKey(destinationTable).columns
|
||||
if originColumns.count == destinationColumns.count {
|
||||
let mapping = zip(originColumns, destinationColumns).map {
|
||||
|
||||
@@ -126,7 +126,7 @@ extension SQLSpecificExpressible {
|
||||
|
||||
/// The `IS` SQL operator.
|
||||
public static func === (lhs: (any SQLExpressible)?, rhs: Self) -> SQLExpression {
|
||||
if let lhs = lhs {
|
||||
if let lhs {
|
||||
return .compare(.is, lhs.sqlExpression, rhs.sqlExpression)
|
||||
} else {
|
||||
return .compare(.is, rhs.sqlExpression, .null)
|
||||
|
||||
@@ -635,7 +635,7 @@ struct SQLLimit {
|
||||
let offset: Int?
|
||||
|
||||
var sql: String {
|
||||
if let offset = offset {
|
||||
if let offset {
|
||||
return "\(limit) OFFSET \(offset)"
|
||||
} else {
|
||||
return "\(limit)"
|
||||
|
||||
@@ -723,7 +723,7 @@ extension Table {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Table where RowDecoder: Identifiable, RowDecoder.ID: DatabaseValueConvertible {
|
||||
/// Returns a request filtered by primary key.
|
||||
///
|
||||
@@ -1346,7 +1346,7 @@ extension Table {
|
||||
{
|
||||
let association = HasManyThroughAssociation(through: pivot, using: target)
|
||||
|
||||
if let key = key {
|
||||
if let key {
|
||||
return association.forKey(key)
|
||||
} else {
|
||||
return association
|
||||
@@ -1378,7 +1378,7 @@ extension Table {
|
||||
{
|
||||
let association = HasOneThroughAssociation(through: pivot, using: target)
|
||||
|
||||
if let key = key {
|
||||
if let key {
|
||||
return association.forKey(key)
|
||||
} else {
|
||||
return association
|
||||
@@ -1546,7 +1546,7 @@ extension Table {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Table
|
||||
where RowDecoder: Identifiable,
|
||||
RowDecoder.ID: DatabaseValueConvertible
|
||||
@@ -1688,7 +1688,7 @@ extension Table {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Table
|
||||
where RowDecoder: Identifiable,
|
||||
RowDecoder.ID: DatabaseValueConvertible
|
||||
|
||||
@@ -324,7 +324,7 @@ public class TableAlias {
|
||||
|
||||
switch impl {
|
||||
case let .undefined(userName):
|
||||
if let userName = userName {
|
||||
if let userName {
|
||||
// rename
|
||||
assert(base.userName == nil || base.userName == userName)
|
||||
base.setUserName(userName)
|
||||
@@ -332,7 +332,7 @@ public class TableAlias {
|
||||
self.impl = .proxy(base)
|
||||
case let .table(tableName: tableName, userName: userName):
|
||||
assert(tableName == base.tableName)
|
||||
if let userName = userName {
|
||||
if let userName {
|
||||
// rename
|
||||
assert(base.userName == nil || base.userName == userName)
|
||||
base.setUserName(userName)
|
||||
@@ -358,7 +358,7 @@ public class TableAlias {
|
||||
// can't merge
|
||||
return nil
|
||||
}
|
||||
if let userName = userName, let otherUserName = otherUserName, userName != otherUserName {
|
||||
if let userName, let otherUserName, userName != otherUserName {
|
||||
// can't merge
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
}
|
||||
|
||||
let filter = try relation.filterPromise?.resolve(context.db)
|
||||
if let filter = filter {
|
||||
if let filter {
|
||||
sql += " WHERE "
|
||||
sql += try filter.sql(context)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ struct SQLQueryGenerator: Refinable {
|
||||
limit = SQLLimit(limit: 1, offset: limit?.offset)
|
||||
}
|
||||
|
||||
if let limit = limit {
|
||||
if let limit {
|
||||
sql += " LIMIT "
|
||||
sql += limit.sql
|
||||
}
|
||||
|
||||
@@ -19,6 +19,16 @@ extension SQLInterpolation {
|
||||
appendLiteral(table.databaseTableName.quotedDatabaseIdentifier)
|
||||
}
|
||||
|
||||
/// Appends the table name.
|
||||
///
|
||||
/// // SELECT * FROM player
|
||||
/// let playerTable = Table("player")
|
||||
/// let request: SQLRequest<Player> = "SELECT * FROM \(playerTable)"
|
||||
@_disfavoredOverload
|
||||
public mutating func appendInterpolation<T>(_ table: Table<T>) {
|
||||
appendLiteral(table.tableName.quotedDatabaseIdentifier)
|
||||
}
|
||||
|
||||
/// Appends the table name of the record.
|
||||
///
|
||||
/// // INSERT INTO player ...
|
||||
@@ -74,7 +84,7 @@ extension SQLInterpolation {
|
||||
/// """
|
||||
@_disfavoredOverload
|
||||
public mutating func appendInterpolation(_ selection: (any SQLSelectable)?) {
|
||||
if let selection = selection {
|
||||
if let selection {
|
||||
elements.append(.selection(selection.sqlSelection))
|
||||
} else {
|
||||
appendLiteral("NULL")
|
||||
@@ -127,7 +137,7 @@ extension SQLInterpolation {
|
||||
/// """
|
||||
@_disfavoredOverload
|
||||
public mutating func appendInterpolation(_ expressible: (any SQLExpressible)?) {
|
||||
if let expressible = expressible {
|
||||
if let expressible {
|
||||
elements.append(.expression(expressible.sqlExpression))
|
||||
} else {
|
||||
appendLiteral("NULL")
|
||||
|
||||
@@ -160,22 +160,29 @@ extension Database {
|
||||
/// ```swift
|
||||
/// // a INTEGER NOT NULL,
|
||||
/// // b TEXT NOT NULL,
|
||||
/// // PRIMARY KEY (a, b),
|
||||
/// // PRIMARY KEY (a, b)
|
||||
/// t.primaryKey {
|
||||
/// t.column("a", .integer)
|
||||
/// t.column("b", .text)
|
||||
/// }
|
||||
///
|
||||
/// // a INTEGER NOT NULL,
|
||||
/// // b TEXT NOT NULL,
|
||||
/// // PRIMARY KEY (a, b)
|
||||
/// t.column("a", .integer).notNull()
|
||||
/// t.column("b", .text).notNull()
|
||||
/// t.primaryKey(["a", "b"])
|
||||
///
|
||||
/// // a INTEGER,
|
||||
/// // b TEXT,
|
||||
/// // UNIQUE (a, b) ON CONFLICT REPLACE,
|
||||
/// // UNIQUE (a, b) ON CONFLICT REPLACE
|
||||
/// t.column("a", .integer)
|
||||
/// t.column("b", .text)
|
||||
/// t.uniqueKey(["a", "b"], onConflict: .replace)
|
||||
///
|
||||
/// // a INTEGER,
|
||||
/// // b TEXT,
|
||||
/// // FOREIGN KEY (a, b) REFERENCES parents(c, d),
|
||||
/// // FOREIGN KEY (a, b) REFERENCES parents(c, d)
|
||||
/// t.column("a", .integer)
|
||||
/// t.column("b", .text)
|
||||
/// t.foreignKey(["a", "b"], references: "parents")
|
||||
@@ -469,8 +476,8 @@ public struct TableOptions: OptionSet {
|
||||
|
||||
/// A `TableDefinition` lets you define the components of a database table.
|
||||
///
|
||||
/// You don't create instances of this class. Instead, you use the `Database`
|
||||
/// ``Database/create(table:options:body:)`` method:
|
||||
/// See the documentation of the `Database`
|
||||
/// ``Database/create(table:options:body:)`` method for usage information:
|
||||
///
|
||||
/// ```swift
|
||||
/// try db.create(table: "player") { t in // t is TableDefinition
|
||||
@@ -493,6 +500,7 @@ public struct TableOptions: OptionSet {
|
||||
/// - ``autoIncrementedPrimaryKey(_:onConflict:)``
|
||||
/// - ``primaryKey(_:_:onConflict:)``
|
||||
/// - ``primaryKey(onConflict:body:)``
|
||||
/// - ``primaryKey(_:onConflict:)``
|
||||
///
|
||||
/// ### Define a Foreign Key
|
||||
///
|
||||
@@ -508,13 +516,6 @@ public struct TableOptions: OptionSet {
|
||||
/// - ``check(sql:)``
|
||||
/// - ``constraint(literal:)``
|
||||
/// - ``constraint(sql:)``
|
||||
///
|
||||
/// ### Sunsetted Methods
|
||||
///
|
||||
/// Those are legacy interfaces that are preserved for backwards compatibility.
|
||||
/// Their use is not recommended.
|
||||
///
|
||||
/// - ``primaryKey(_:onConflict:)``
|
||||
public final class TableDefinition {
|
||||
struct KeyConstraint {
|
||||
var columns: [String]
|
||||
@@ -567,7 +568,7 @@ public final class TableDefinition {
|
||||
self.options = options
|
||||
}
|
||||
|
||||
/// Defines the auto-incremented primary key.
|
||||
/// Appends an auto-incremented primary key column.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -601,7 +602,7 @@ public final class TableDefinition {
|
||||
column(name, .integer).primaryKey(onConflict: conflictResolution, autoincrement: true)
|
||||
}
|
||||
|
||||
/// Defines the primary key on a single column.
|
||||
/// Appends a primary key column.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -636,7 +637,7 @@ public final class TableDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
/// Defines the primary key on multiple columns.
|
||||
/// Defines the primary key on wrapped columns.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -656,7 +657,7 @@ public final class TableDefinition {
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// A NOT NULL constraint is always added to the primary key columns.
|
||||
/// A NOT NULL constraint is always added to the wrapped primary key columns.
|
||||
public func primaryKey(
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
body: () throws -> Void)
|
||||
@@ -744,7 +745,7 @@ public final class TableDefinition {
|
||||
columns.append(.literal(literal))
|
||||
}
|
||||
|
||||
/// Defines the primary key.
|
||||
/// Adds a primary key constraint.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -766,10 +767,6 @@ public final class TableDefinition {
|
||||
/// See <https://www.sqlite.org/quirks.html#primary_keys_can_sometimes_contain_nulls>
|
||||
/// for more information.
|
||||
///
|
||||
/// - warning: This is a legacy interface that is preserved for backwards
|
||||
/// compatibility. Use of this interface is not recommended: prefer
|
||||
/// ``TableDefinition/primaryKey(onConflict:body:)`` instead.
|
||||
///
|
||||
/// - parameter columns: The primary key columns.
|
||||
/// - parameter conflictResolution: An optional conflict resolution
|
||||
/// (see <https://www.sqlite.org/lang_conflict.html>).
|
||||
@@ -1109,7 +1106,7 @@ public final class TableDefinition {
|
||||
tableOptions.append("STRICT")
|
||||
}
|
||||
#else
|
||||
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) {
|
||||
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) { // SQLite 3.37+
|
||||
if options.contains(.strict) {
|
||||
tableOptions.append("STRICT")
|
||||
}
|
||||
@@ -1267,7 +1264,7 @@ public final class TableAlteration {
|
||||
///
|
||||
/// - parameter name: the old name of the column.
|
||||
/// - parameter newName: the new name of the column.
|
||||
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
|
||||
@available(iOS 13, tvOS 13, watchOS 6, *) // SQLite 3.25+
|
||||
public func rename(column name: String, to newName: String) {
|
||||
_rename(column: name, to: newName)
|
||||
}
|
||||
@@ -1285,7 +1282,7 @@ public final class TableAlteration {
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_altertable.html>
|
||||
///
|
||||
/// - Parameter name: the name of the column to drop.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func drop(column name: String) {
|
||||
_drop(column: name)
|
||||
}
|
||||
@@ -1810,7 +1807,7 @@ public final class ColumnDefinition {
|
||||
/// - qualification: The generated column's qualification, which
|
||||
/// defaults to ``GeneratedColumnQualification/virtual``.
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+ (3.31 actually)
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+ (3.31 actually)
|
||||
@discardableResult
|
||||
public func generatedAs(
|
||||
sql: String,
|
||||
@@ -1850,7 +1847,7 @@ public final class ColumnDefinition {
|
||||
/// - qualification: The generated column's qualification, which
|
||||
/// defaults to ``GeneratedColumnQualification/virtual``.
|
||||
/// - returns: `self` so that you can further refine the column definition.
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+ (3.31 actually)
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+ (3.31 actually)
|
||||
@discardableResult
|
||||
public func generatedAs(
|
||||
_ expression: some SQLExpressible,
|
||||
@@ -1909,13 +1906,13 @@ public final class ColumnDefinition {
|
||||
fileprivate func sql(_ db: Database, tableName: String, primaryKeyColumns: [String]?) throws -> String {
|
||||
var chunks: [String] = []
|
||||
chunks.append(name.quotedDatabaseIdentifier)
|
||||
if let type = type {
|
||||
if let type {
|
||||
chunks.append(type.rawValue)
|
||||
}
|
||||
|
||||
if let (conflictResolution, autoincrement) = primaryKey {
|
||||
chunks.append("PRIMARY KEY")
|
||||
if let conflictResolution = conflictResolution {
|
||||
if let conflictResolution {
|
||||
chunks.append("ON CONFLICT")
|
||||
chunks.append(conflictResolution.rawValue)
|
||||
}
|
||||
@@ -1927,7 +1924,7 @@ public final class ColumnDefinition {
|
||||
switch notNullConflictResolution {
|
||||
case .none:
|
||||
break
|
||||
case .abort?:
|
||||
case .abort:
|
||||
chunks.append("NOT NULL")
|
||||
case let conflictResolution?:
|
||||
chunks.append("NOT NULL ON CONFLICT")
|
||||
@@ -1953,11 +1950,11 @@ public final class ColumnDefinition {
|
||||
try chunks.append("CHECK (\(checkConstraint.quotedSQL(db)))")
|
||||
}
|
||||
|
||||
if let defaultExpression = defaultExpression {
|
||||
if let defaultExpression {
|
||||
try chunks.append("DEFAULT \(defaultExpression.quotedSQL(db))")
|
||||
}
|
||||
|
||||
if let collationName = collationName {
|
||||
if let collationName {
|
||||
chunks.append("COLLATE")
|
||||
chunks.append(collationName)
|
||||
}
|
||||
@@ -2064,7 +2061,7 @@ private struct IndexDefinition {
|
||||
\(columns.map(\.quotedDatabaseIdentifier).joined(separator: ", "))\
|
||||
)
|
||||
""")
|
||||
if let condition = condition {
|
||||
if let condition {
|
||||
try chunks.append("WHERE \(condition.quotedSQL(db))")
|
||||
}
|
||||
return chunks.joined(separator: " ")
|
||||
|
||||
@@ -130,7 +130,7 @@ extension Database {
|
||||
// Define virtual table
|
||||
let configuration = VirtualTableConfiguration(ifNotExists: ifNotExists)
|
||||
let definition = module.makeTableDefinition(configuration: configuration)
|
||||
if let body = body {
|
||||
if let body {
|
||||
try body(definition)
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ extension TableRecord {
|
||||
{
|
||||
let association = HasManyThroughAssociation(through: pivot, using: target)
|
||||
|
||||
if let key = key {
|
||||
if let key {
|
||||
return association.forKey(key)
|
||||
} else {
|
||||
return association
|
||||
@@ -529,7 +529,7 @@ extension TableRecord {
|
||||
{
|
||||
let association = HasOneThroughAssociation(through: pivot, using: target)
|
||||
|
||||
if let key = key {
|
||||
if let key {
|
||||
return association.forKey(key)
|
||||
} else {
|
||||
return association
|
||||
|
||||
@@ -605,7 +605,7 @@ extension TableRecord {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
/// Returns a request filtered by primary key.
|
||||
///
|
||||
|
||||
@@ -94,7 +94,7 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
|
||||
// swiftlint:enable comma
|
||||
|
||||
func encodeIfPresent<T>(_ value: T?, forKey key: Key) throws where T: Encodable {
|
||||
if let value = value {
|
||||
if let value {
|
||||
try recordEncoder.encode(value, forKey: key)
|
||||
} else {
|
||||
recordEncoder.persist(nil, forKey: key)
|
||||
|
||||
@@ -98,7 +98,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
|
||||
func contains(_ key: Key) -> Bool {
|
||||
let row = decoder.row
|
||||
if let _columnForKey = _columnForKey {
|
||||
if let _columnForKey {
|
||||
if let column = _columnForKey[key.stringValue] {
|
||||
assert(row.hasColumn(column))
|
||||
return true
|
||||
@@ -299,7 +299,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
// "book", which is not the name of a column, and not the name of a
|
||||
// scope) has to be decoded right from the base row. But this can
|
||||
// happen only once.
|
||||
if let decodedRootKey = decodedRootKey {
|
||||
if let decodedRootKey {
|
||||
let keys = [decodedRootKey.stringValue, key.stringValue].sorted()
|
||||
throw DecodingError.keyNotFound(key, DecodingError.Context(
|
||||
codingPath: codingPath,
|
||||
@@ -369,7 +369,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
} catch is JSONRequiredError {
|
||||
// Decode from JSON
|
||||
return try row.withUnsafeData(atIndex: index) { data in
|
||||
guard let data = data else {
|
||||
guard let data else {
|
||||
throw DecodingError.valueNotFound(Data.self, DecodingError.Context(
|
||||
codingPath: codingPath + [key],
|
||||
debugDescription: "Missing Data"))
|
||||
|
||||
@@ -217,7 +217,7 @@ extension FetchableRecord where Self: TableRecord {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension FetchableRecord where Self: TableRecord & Identifiable, ID: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching by Single-Column Primary Key
|
||||
@@ -359,7 +359,7 @@ extension FetchableRecord where Self: TableRecord & Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension FetchableRecord where Self: TableRecord & Hashable & Identifiable, ID: DatabaseValueConvertible {
|
||||
/// Returns a set of records identified by their primary keys.
|
||||
///
|
||||
|
||||
@@ -285,7 +285,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func insertAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil)
|
||||
@@ -351,7 +351,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func insertAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -412,7 +412,7 @@ extension MutablePersistableRecord {
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func insertAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
|
||||
@@ -233,7 +233,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func saveAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil)
|
||||
@@ -261,7 +261,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func saveAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -306,7 +306,7 @@ extension MutablePersistableRecord {
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func saveAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
|
||||
@@ -532,7 +532,7 @@ extension MutablePersistableRecord {
|
||||
/// or ``RecordError/recordNotFound(databaseTableName:key:)`` if the
|
||||
/// primary key does not match any row in the database.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil)
|
||||
@@ -557,7 +557,7 @@ extension MutablePersistableRecord {
|
||||
/// or ``RecordError/recordNotFound(databaseTableName:key:)`` if the
|
||||
/// primary key does not match any row in the database.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -586,7 +586,7 @@ extension MutablePersistableRecord {
|
||||
/// or ``RecordError/recordNotFound(databaseTableName:key:)`` if the
|
||||
/// primary key does not match any row in the database.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func updateChangesAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -616,7 +616,7 @@ extension MutablePersistableRecord {
|
||||
/// or ``RecordError/recordNotFound(databaseTableName:key:)`` if the
|
||||
/// primary key does not match any row in the database.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func updateChangesAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -662,7 +662,7 @@ extension MutablePersistableRecord {
|
||||
/// primary key does not match any row in the database.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetch<T, Columns>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -724,7 +724,7 @@ extension MutablePersistableRecord {
|
||||
/// primary key does not match any row in the database.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetch<T, Columns>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -768,7 +768,7 @@ extension MutablePersistableRecord {
|
||||
/// primary key does not match any row in the database.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func updateAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -804,7 +804,7 @@ extension MutablePersistableRecord {
|
||||
/// primary key does not match any row in the database.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func updateChangesAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -850,7 +850,7 @@ extension MutablePersistableRecord {
|
||||
}
|
||||
#else
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
func updateChangesAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution?,
|
||||
|
||||
@@ -207,7 +207,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func upsert(_ db: Database) throws {
|
||||
try willSave(db)
|
||||
|
||||
@@ -302,7 +302,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func upsertAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictTarget: [String] = [],
|
||||
@@ -330,7 +330,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public mutating func upsertAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
as returnedType: T.Type,
|
||||
@@ -442,7 +442,7 @@ extension MutablePersistableRecord {
|
||||
// to false in its `aroundInsert` callback.
|
||||
var persistenceContainer = dao.persistenceContainer
|
||||
let rowIDColumn = dao.primaryKey.rowIDColumn
|
||||
if let rowIDColumn = rowIDColumn {
|
||||
if let rowIDColumn {
|
||||
persistenceContainer[caseInsensitive: rowIDColumn] = rowid
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ extension PersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func insertAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -314,7 +314,7 @@ extension PersistableRecord {
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func insertAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
|
||||
@@ -144,7 +144,7 @@ extension PersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func saveAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
@@ -189,7 +189,7 @@ extension PersistableRecord {
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
/// - precondition: `selection` is not empty.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func saveAndFetch<T>(
|
||||
_ db: Database,
|
||||
onConflict conflictResolution: Database.ConflictResolution? = nil,
|
||||
|
||||
@@ -207,7 +207,7 @@ extension PersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func upsert(_ db: Database) throws {
|
||||
try willSave(db)
|
||||
|
||||
@@ -302,7 +302,7 @@ extension PersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func upsertAndFetch(
|
||||
_ db: Database,
|
||||
onConflict conflictTarget: [String] = [],
|
||||
@@ -330,7 +330,7 @@ extension PersistableRecord {
|
||||
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or any
|
||||
/// error thrown by the persistence callbacks defined by the record type.
|
||||
@inlinable // allow specialization so that empty callbacks are removed
|
||||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
|
||||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
|
||||
public func upsertAndFetch<T: FetchableRecord & TableRecord>(
|
||||
_ db: Database,
|
||||
as returnedType: T.Type,
|
||||
|
||||
@@ -203,7 +203,7 @@ open class Record {
|
||||
// Loop until we find a change, or exhaust columns:
|
||||
while let (column, newValue) = newValueIterator.next() {
|
||||
let newDbValue = newValue?.databaseValue ?? .null
|
||||
guard let oldRow = oldRow, let oldDbValue: DatabaseValue = oldRow[column] else {
|
||||
guard let oldRow, let oldDbValue: DatabaseValue = oldRow[column] else {
|
||||
return (column, nil)
|
||||
}
|
||||
if newDbValue != oldDbValue {
|
||||
|
||||
@@ -80,7 +80,8 @@ import Foundation
|
||||
/// - ``joining(optional:)``
|
||||
/// - ``joining(required:)``
|
||||
/// - ``limit(_:offset:)``
|
||||
/// - ``matching(_:)``
|
||||
/// - ``matching(_:)-22m4o``
|
||||
/// - ``matching(_:)-1t8ph``
|
||||
/// - ``none()``
|
||||
/// - ``order(_:)-9rc11``
|
||||
/// - ``order(_:)-2033k``
|
||||
@@ -309,7 +310,7 @@ extension TableRecord {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
/// Returns whether a record exists for this primary key.
|
||||
///
|
||||
@@ -445,7 +446,7 @@ extension TableRecord {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
/// Deletes records identified by their primary keys, and returns the number
|
||||
/// of deleted records.
|
||||
@@ -700,20 +701,20 @@ extension TableRecord {
|
||||
|
||||
/// Returns an error for a record that does not exist in the database.
|
||||
public static func recordNotFound(key: [String: (any DatabaseValueConvertible)?]) -> RecordError {
|
||||
return RecordError.recordNotFound(
|
||||
RecordError.recordNotFound(
|
||||
databaseTableName: databaseTableName,
|
||||
key: key.mapValues { $0?.databaseValue ?? .null })
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
/// Returns an error for a record that does not exist in the database.
|
||||
///
|
||||
/// - returns: ``RecordError/recordNotFound(databaseTableName:key:)``, or
|
||||
/// any error that prevented the `RecordError` from being constructed.
|
||||
public static func recordNotFound(_ db: Database, id: Self.ID) -> any Error {
|
||||
return recordNotFound(db, key: id)
|
||||
recordNotFound(db, key: id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import Foundation
|
||||
/// Both two extra scheduling guarantees are used by GRDB in order to be
|
||||
/// able to spawn concurrent database reads right from the database writer
|
||||
/// queue, and fulfill GRDB preconditions.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
struct OnDemandFuture<Output, Failure: Error>: Publisher {
|
||||
typealias Promise = (Result<Output, Failure>) -> Void
|
||||
typealias Output = Output
|
||||
@@ -33,7 +33,7 @@ struct OnDemandFuture<Output, Failure: Error>: Publisher {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
private class OnDemandFutureSubscription<Downstream: Subscriber>: Subscription {
|
||||
typealias Promise = (Result<Downstream.Input, Downstream.Failure>) -> Void
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import Foundation
|
||||
/// This scheduling guarantee is used by GRDB in order to be able
|
||||
/// to make promises on the scheduling of database values without surprising
|
||||
/// the users as in <https://forums.swift.org/t/28631>.
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
struct ReceiveValuesOn<Upstream: Publisher, Context: Scheduler>: Publisher {
|
||||
typealias Output = Upstream.Output
|
||||
typealias Failure = Upstream.Failure
|
||||
@@ -30,7 +30,7 @@ struct ReceiveValuesOn<Upstream: Publisher, Context: Scheduler>: Publisher {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
private class ReceiveValuesOnSubscription<Upstream, Context, Downstream>: Subscription, Subscriber
|
||||
where
|
||||
Upstream: Publisher,
|
||||
@@ -211,7 +211,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension Publisher {
|
||||
/// Specifies the scheduler on which to receive values from the publisher
|
||||
///
|
||||
|
||||
@@ -31,9 +31,9 @@ func GRDBPrecondition(
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line)
|
||||
{
|
||||
/// Custom precondition function which aims at solving
|
||||
/// <https://bugs.swift.org/browse/SR-905> and
|
||||
/// <https://github.com/groue/GRDB.swift/issues/37>
|
||||
// Custom precondition function which aims at solving
|
||||
// <https://bugs.swift.org/browse/SR-905> and
|
||||
// <https://github.com/groue/GRDB.swift/issues/37>
|
||||
if !condition() {
|
||||
fatalError(message(), file: file, line: line)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func throwingFirstError<T>(execute: () throws -> T, finally: () throws -> Void)
|
||||
firstError = error
|
||||
}
|
||||
}
|
||||
if let firstError = firstError {
|
||||
if let firstError {
|
||||
throw firstError
|
||||
}
|
||||
return result!
|
||||
|
||||
@@ -438,7 +438,7 @@ extension ValueConcurrentObserver {
|
||||
let value = try self.reducer._value(fetchedValue)
|
||||
|
||||
// Notify
|
||||
if let value = value {
|
||||
if let value {
|
||||
self.scheduler.schedule {
|
||||
let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange }
|
||||
guard let onChange else { return /* Cancelled */ }
|
||||
@@ -566,7 +566,7 @@ extension ValueConcurrentObserver: TransactionObserver {
|
||||
let value = try self.reducer._value(fetchedValue)
|
||||
|
||||
// Notify value
|
||||
if let value = value {
|
||||
if let value {
|
||||
self.scheduler.schedule {
|
||||
let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange }
|
||||
guard let onChange else { return /* Cancelled */ }
|
||||
|
||||
@@ -18,7 +18,11 @@ import Foundation
|
||||
/// reducing stage.
|
||||
///
|
||||
/// **Notify** is calling user callbacks, in case of database change or error.
|
||||
final class ValueWriteOnlyObserver<Writer: DatabaseWriter, Reducer: ValueReducer, Scheduler: ValueObservationScheduler> {
|
||||
final class ValueWriteOnlyObserver<
|
||||
Writer: DatabaseWriter,
|
||||
Reducer: ValueReducer,
|
||||
Scheduler: ValueObservationScheduler>
|
||||
{
|
||||
// MARK: - Configuration
|
||||
//
|
||||
// Configuration is not mutable.
|
||||
@@ -403,7 +407,7 @@ extension ValueWriteOnlyObserver: TransactionObserver {
|
||||
let value = try self.reducer._value(fetchedValue)
|
||||
|
||||
// Notify value
|
||||
if let value = value {
|
||||
if let value {
|
||||
self.scheduler.schedule {
|
||||
let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange }
|
||||
guard let onChange else { return /* Cancelled */ }
|
||||
|
||||
@@ -81,7 +81,7 @@ extension ValueReducers {
|
||||
guard let value = try base._value(fetched) else {
|
||||
return nil
|
||||
}
|
||||
if let previousValue = previousValue, predicate(previousValue, value) {
|
||||
if let previousValue, predicate(previousValue, value) {
|
||||
// Don't notify consecutive identical values
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ public final class SharedValueObservation<Element> {
|
||||
/// print("fresh players: \(players)")
|
||||
/// }
|
||||
/// ```
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func publisher() -> DatabasePublishers.Value<Element> {
|
||||
DatabasePublishers.Value { onError, onChange in
|
||||
self.start(onError: onError, onChange: onChange)
|
||||
@@ -368,7 +368,7 @@ extension SharedValueObservation {
|
||||
/// print("Fresh players: \(players)")
|
||||
/// }
|
||||
/// ```
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func values(bufferingPolicy: AsyncValueObservation<Element>.BufferingPolicy = .unbounded)
|
||||
-> AsyncValueObservation<Element>
|
||||
{
|
||||
|
||||
@@ -634,7 +634,7 @@ extension ValueObservation {
|
||||
/// - parameter reader: A DatabaseReader.
|
||||
/// - parameter scheduler: A ValueObservationScheduler. By default, fresh
|
||||
/// values are dispatched asynchronously on the main dispatch queue.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func values(
|
||||
in reader: some DatabaseReader,
|
||||
scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main),
|
||||
@@ -669,7 +669,7 @@ extension ValueObservation {
|
||||
///
|
||||
/// You build an `AsyncValueObservation` from ``ValueObservation`` or
|
||||
/// ``SharedValueObservation``.
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public struct AsyncValueObservation<Element>: AsyncSequence {
|
||||
public typealias BufferingPolicy = AsyncThrowingStream<Element, Error>.Continuation.BufferingPolicy
|
||||
public typealias AsyncIterator = Iterator
|
||||
@@ -704,7 +704,7 @@ public struct AsyncValueObservation<Element>: AsyncSequence {
|
||||
}
|
||||
|
||||
let iterator = stream.makeAsyncIterator()
|
||||
if let cancellable = cancellable {
|
||||
if let cancellable {
|
||||
return Iterator(
|
||||
iterator: iterator,
|
||||
cancellable: cancellable)
|
||||
@@ -771,7 +771,7 @@ extension ValueObservation {
|
||||
/// - parameter scheduler: A ValueObservationScheduler. By default, fresh
|
||||
/// values are dispatched asynchronously on the main dispatch queue.
|
||||
/// - returns: A Combine publisher
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
public func publisher(
|
||||
in reader: some DatabaseReader,
|
||||
scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main))
|
||||
@@ -788,7 +788,7 @@ extension ValueObservation {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension DatabasePublishers {
|
||||
/// A publisher that publishes the values of a ``ValueObservation``.
|
||||
///
|
||||
|
||||
@@ -240,6 +240,8 @@
|
||||
56A8C2461D1918EF0096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; };
|
||||
56AE6428222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */; };
|
||||
56AF746E1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; };
|
||||
56AFEF3229969F7E00CA1E51 /* TransactionClock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFEF3029969F7E00CA1E51 /* TransactionClock.swift */; };
|
||||
56AFEF3A2996B9EE00CA1E51 /* TransactionDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFEF382996B9EE00CA1E51 /* TransactionDateTests.swift */; };
|
||||
56B021CC1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; };
|
||||
56B14E821D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; };
|
||||
56B6EF60208CB746002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */; };
|
||||
@@ -722,6 +724,8 @@
|
||||
56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = "<group>"; };
|
||||
56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = "<group>"; };
|
||||
56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = "<group>"; };
|
||||
56AFEF3029969F7E00CA1E51 /* TransactionClock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionClock.swift; sourceTree = "<group>"; };
|
||||
56AFEF382996B9EE00CA1E51 /* TransactionDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionDateTests.swift; sourceTree = "<group>"; };
|
||||
56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = "<group>"; };
|
||||
56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = "<group>"; };
|
||||
56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1364,6 +1368,7 @@
|
||||
568068301EBBA26100EFB8AA /* SQLRequestTests.swift */,
|
||||
56A238201B9C74A90082EB20 /* Statement */,
|
||||
56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */,
|
||||
56AFEF382996B9EE00CA1E51 /* TransactionDateTests.swift */,
|
||||
5607EFD11BB8253300605DE3 /* TransactionObserver */,
|
||||
);
|
||||
name = Core;
|
||||
@@ -1463,6 +1468,7 @@
|
||||
56A238781B9C75030082EB20 /* Statement.swift */,
|
||||
566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */,
|
||||
560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */,
|
||||
56AFEF3029969F7E00CA1E51 /* TransactionClock.swift */,
|
||||
566B91321FA4D3810012D5B0 /* TransactionObserver.swift */,
|
||||
56564F3828637C9900A19E9F /* WALSnapshot.swift */,
|
||||
5605F1471C672E4000235C62 /* Support */,
|
||||
@@ -1923,6 +1929,7 @@
|
||||
5656A8852295BD56001FF3FF /* SQLOrdering.swift in Sources */,
|
||||
F3BA808D1CFB2E75003DC1BA /* Migration.swift in Sources */,
|
||||
F3BA80791CFB2E61003DC1BA /* DatabaseDateComponents.swift in Sources */,
|
||||
56AFEF3229969F7E00CA1E51 /* TransactionClock.swift in Sources */,
|
||||
5674A6EC1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
|
||||
568ECB0D25D904CA00B71526 /* SQLSelection.swift in Sources */,
|
||||
5657AB111D10899D006283EF /* URL.swift in Sources */,
|
||||
@@ -2190,6 +2197,7 @@
|
||||
568068341EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */,
|
||||
5657AB691D108BA9006283EF /* FoundationURLTests.swift in Sources */,
|
||||
56741EAB1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56AFEF3A2996B9EE00CA1E51 /* TransactionDateTests.swift in Sources */,
|
||||
56B964D61DA521450002DA19 /* FTS5TableBuilderTests.swift in Sources */,
|
||||
563F4CB4242F7F140052E96C /* ValueObservationTests.swift in Sources */,
|
||||
5674A71D1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */,
|
||||
|
||||
+7
-7
@@ -4,13 +4,14 @@
|
||||
import Foundation
|
||||
import PackageDescription
|
||||
|
||||
// Don't rely on those environment variables. They are ONLY testing conveniences:
|
||||
// $ SQLITE_ENABLE_FTS5=1 SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM
|
||||
var swiftSettings: [SwiftSetting] = []
|
||||
var swiftSettings: [SwiftSetting] = [
|
||||
.define("SQLITE_ENABLE_FTS5"),
|
||||
]
|
||||
var cSettings: [CSetting] = []
|
||||
if ProcessInfo.processInfo.environment["SQLITE_ENABLE_FTS5"] == "1" {
|
||||
swiftSettings.append(.define("SQLITE_ENABLE_FTS5"))
|
||||
}
|
||||
var dependencies: [PackageDescription.Package.Dependency] = []
|
||||
|
||||
// Don't rely on those environment variables. They are ONLY testing conveniences:
|
||||
// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM
|
||||
if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" {
|
||||
swiftSettings.append(.define("SQLITE_ENABLE_PREUPDATE_HOOK"))
|
||||
cSettings.append(.define("GRDB_SQLITE_ENABLE_PREUPDATE_HOOK"))
|
||||
@@ -22,7 +23,6 @@ if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" {
|
||||
// for more information.
|
||||
//
|
||||
// SPI_BUILDER also enables the `make docs-localhost` command.
|
||||
var dependencies: [PackageDescription.Package.Dependency] = []
|
||||
if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" {
|
||||
dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
---
|
||||
|
||||
**Latest release**: January 15, 2023 • [version 6.6.1](https://github.com/groue/GRDB.swift/tree/v6.6.1) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
|
||||
**Latest release**: February 19, 2023 • [version 6.7.0](https://github.com/groue/GRDB.swift/tree/v6.7.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
|
||||
|
||||
**Requirements**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+ • SQLite 3.19.3+ • Swift 5.7+ / Xcode 14+
|
||||
|
||||
| Swift version | GRDB version |
|
||||
| -------------- | ----------------------------------------------------------- |
|
||||
| **Swift 5.7+** | **v6.6.1** |
|
||||
| **Swift 5.7+** | **v6.7.0** |
|
||||
| Swift 5.3 | [v5.26.1](https://github.com/groue/GRDB.swift/tree/v5.26.1) |
|
||||
| Swift 5.2 | [v5.12.0](https://github.com/groue/GRDB.swift/tree/v5.12.0) |
|
||||
| Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) |
|
||||
@@ -2080,13 +2080,14 @@ Extending structs with record protocols is more "swifty". Subclassing the Record
|
||||
- [TableRecord Protocol](#tablerecord-protocol)
|
||||
- [PersistableRecord Protocol](#persistablerecord-protocol)
|
||||
- [Persistence Methods]
|
||||
- [Persistence Methods and the `RETURNING` clause](#persistence-methods-and-the-returning-clause)
|
||||
- [Persistence Methods and the `RETURNING` clause]
|
||||
- [Persistence Callbacks]
|
||||
- [Identifiable Records]
|
||||
- [Codable Records]
|
||||
- [Record Class](#record-class)
|
||||
- [Record Comparison]
|
||||
- [Record Customization Options]
|
||||
- [Record Timestamps and Transaction Date]
|
||||
|
||||
**Records in a Glance**
|
||||
|
||||
@@ -5684,11 +5685,11 @@ For even better control over the lifetime of the passphrase in memory, use a Dat
|
||||
// RECOMMENDED: only load the passphrase when it is needed and reset its content immediately after use
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in
|
||||
let passphrase = try getPassphraseData() // Data
|
||||
var passphraseData = try getPassphraseData() // Data
|
||||
defer {
|
||||
passphrase.resetBytes(in: 0..<data.count)
|
||||
passphraseData.resetBytes(in: 0..<passphraseData.count)
|
||||
}
|
||||
try db.usePassphrase(passphrase)
|
||||
try db.usePassphrase(passphraseData)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -7029,6 +7030,7 @@ This chapter has been superseded by [ValueObservation] and [DatabaseRegionObserv
|
||||
[Record Customization Options]: #record-customization-options
|
||||
[Persistence Callbacks]: #persistence-callbacks
|
||||
[persistence callbacks]: #persistence-callbacks
|
||||
[Record Timestamps and Transaction Date]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/recordtimestamps
|
||||
[TableRecord]: #tablerecord-protocol
|
||||
[ValueObservation]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/valueobservation
|
||||
[DatabaseRegionObservation]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databaseregionobservation
|
||||
@@ -7050,6 +7052,7 @@ This chapter has been superseded by [ValueObservation] and [DatabaseRegionObserv
|
||||
[Database Configuration]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/configuration
|
||||
[Persistence Methods]: #persistence-methods
|
||||
[persistence methods]: #persistence-methods
|
||||
[Persistence Methods and the `RETURNING` clause]: #persistence-methods-and-the-returning-clause
|
||||
[RecordError]: #recorderror
|
||||
[Transactions and Savepoints]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/transactions
|
||||
[`DatabaseQueue`]: https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasequeue
|
||||
|
||||
@@ -8,7 +8,9 @@ if test -d "/opt/homebrew/bin/"; then
|
||||
fi
|
||||
|
||||
if which swiftlint >/dev/null; then
|
||||
swiftlint --config "${SRCROOT}/Scripts/swiftlint.yml"
|
||||
# Ignore swiftlint error, because GRBD has no dependency on any Swiftlint version.
|
||||
# See https://github.com/groue/GRDB.swift/issues/1327
|
||||
swiftlint --config "${SRCROOT}/Scripts/swiftlint.yml" || true
|
||||
else
|
||||
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
|
||||
fi
|
||||
+13
-4
@@ -6,13 +6,14 @@ disabled_rules:
|
||||
- cyclomatic_complexity
|
||||
- duplicate_enum_cases
|
||||
- file_length
|
||||
- for_where
|
||||
- force_cast
|
||||
- force_try
|
||||
- for_where
|
||||
- function_body_length
|
||||
- function_parameter_count
|
||||
- identifier_name
|
||||
- is_disjoint
|
||||
- large_tuple
|
||||
- nesting
|
||||
- opening_brace
|
||||
- redundant_optional_initialization
|
||||
@@ -25,11 +26,10 @@ disabled_rules:
|
||||
- unused_setter_value
|
||||
|
||||
opt_in_rules:
|
||||
- anyobject_protocol
|
||||
- array_init
|
||||
- capture_variable
|
||||
- closure_spacing
|
||||
- collection_alignment
|
||||
- comma_inheritance
|
||||
- contains_over_filter_count
|
||||
- contains_over_filter_is_empty
|
||||
- contains_over_first_not_nil
|
||||
@@ -48,20 +48,29 @@ opt_in_rules:
|
||||
- last_where
|
||||
- legacy_multiple
|
||||
- legacy_random
|
||||
- local_doc_comment
|
||||
- lower_acl_than_parent
|
||||
- modifier_order
|
||||
- no_extension_access_modifier
|
||||
- optional_enum_case_matching
|
||||
- overridden_super_call
|
||||
- pattern_matching_keywords
|
||||
- prohibited_super_call
|
||||
- reduce_into
|
||||
- redundant_type_annotation
|
||||
- shorthand_optional_binding
|
||||
- sorted_first_last
|
||||
- sorted_imports
|
||||
- toggle_bool
|
||||
- unused_capture_list
|
||||
- vertical_parameter_alignment_on_call
|
||||
- yoda_condition
|
||||
|
||||
analyzer_rules:
|
||||
- capture_variable
|
||||
- typesafe_array_init
|
||||
- unused_declaration
|
||||
- unused_import
|
||||
- yoda_condition
|
||||
|
||||
vertical_whitespace:
|
||||
max_empty_lines: 2
|
||||
|
||||
@@ -2,10 +2,11 @@ IPHONEOS_DEPLOYMENT_TARGET = 11.0
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13
|
||||
TVOS_DEPLOYMENT_TARGET = 11.0
|
||||
WATCHOS_DEPLOYMENT_TARGET = 4.0
|
||||
OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5
|
||||
|
||||
//// Compile with all opt-in APIs
|
||||
//GCC_PREPROCESSOR_DEFINITIONS = $(inherited) GRDB_SQLITE_ENABLE_PREUPDATE_HOOK=1
|
||||
//OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5 -D SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
//OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
|
||||
// Enable concurrency warning in Swift 5.5
|
||||
// https://twitter.com/olebegemann/status/1421144304127463427?lang=en
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>6.6.1</string>
|
||||
<string>6.7.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -7,7 +7,7 @@ post_install do |installer|
|
||||
installer.pods_project.targets.select { |target| target.name == "GRDB.swift" }.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
# Enable extra GRDB APIs
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] = "$(inherited) -D SQLITE_ENABLE_FTS5 -D SQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] = "$(inherited) -D SQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
# Enable extra SQLite APIs
|
||||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = "$(inherited) GRDB_SQLITE_ENABLE_PREUPDATE_HOOK=1"
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ post_install do |installer|
|
||||
installer.pods_project.targets.select { |target| target.name == "GRDB.swift" }.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
# Enable extra GRDB APIs
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] = "$(inherited) -D SQLITE_ENABLE_FTS5 -D SQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] = "$(inherited) -D SQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
# Enable extra SQLite APIs
|
||||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = "$(inherited) GRDB_SQLITE_ENABLE_PREUPDATE_HOOK=1"
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if canImport(Combine)
|
||||
import XCTest
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension PublisherExpectations {
|
||||
/// A publisher expectation which waits for the timeout to expire, or
|
||||
/// the recorded publisher to complete.
|
||||
|
||||
@@ -17,7 +17,7 @@ import XCTest
|
||||
// try wait(for: recorder.finished.inverted, timeout: 1)
|
||||
// }
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension PublisherExpectations {
|
||||
/// A publisher expectation which waits for the recorded publisher
|
||||
/// to complete.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if canImport(Combine)
|
||||
import XCTest
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension PublisherExpectations {
|
||||
/// A publisher expectation that fails if the base expectation is fulfilled.
|
||||
///
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if canImport(Combine)
|
||||
import XCTest
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension PublisherExpectations {
|
||||
/// A publisher expectation that transforms the value of a base expectation.
|
||||
///
|
||||
@@ -20,7 +20,7 @@ extension PublisherExpectations {
|
||||
}
|
||||
}
|
||||
|
||||
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
extension PublisherExpectation {
|
||||
/// Returns a publisher expectation that transforms the value of the
|
||||
/// base expectation.
|
||||
|
||||
Loaded 100 of 148 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user