mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Merge branch 'development'
This commit is contained in:
commit
284a4ee1ac
15 files changed
+102
-48
No files matched your search
+9
-1
@@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
#### 6.x Releases
|
||||
|
||||
- `6.15.x` Releases - [6.15.0](#6150)
|
||||
- `6.15.x` Releases - [6.15.0](#6150) - [6.15.1](#6151)
|
||||
- `6.14.x` Releases - [6.14.0](#6140)
|
||||
- `6.13.x` Releases - [6.13.0](#6130)
|
||||
- `6.12.x` Releases - [6.12.0](#6120)
|
||||
@@ -113,6 +113,14 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
---
|
||||
|
||||
## 6.15.1
|
||||
|
||||
Released June 17, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.15.0...v6.15.1)
|
||||
|
||||
- **Fixed**: Fixed Xcode 15 warnings
|
||||
- **Fixed**: [#1391](https://github.com/groue/GRDB.swift/pull/1391) Fix upsert in FTS5-synchronized tables
|
||||
|
||||
|
||||
## 6.15.0
|
||||
|
||||
Released June 2, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.14.0...v6.15.0)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDB.swift'
|
||||
s.version = '6.15.0'
|
||||
s.version = '6.15.1'
|
||||
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
|
||||
|
||||
@@ -468,7 +468,7 @@ extension DatabaseWriter {
|
||||
|
||||
// MARK: - Erasing the content of the database
|
||||
|
||||
/// Erases the content of the database.
|
||||
/// Erase the database: delete all content, drop all tables, etc.
|
||||
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
|
||||
public func erase() throws {
|
||||
try barrierWriteWithoutTransaction { try $0.erase() }
|
||||
@@ -687,7 +687,7 @@ extension DatabaseWriter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Erases the content of the database.
|
||||
/// Erase the database: delete all content, drop all tables, etc.
|
||||
///
|
||||
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
|
||||
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
|
||||
|
||||
@@ -58,10 +58,6 @@
|
||||
/// - ``makePreparedRequest(_:forSingleResult:)``
|
||||
/// - ``PreparedRequest``
|
||||
///
|
||||
/// ### Database Observation Support
|
||||
///
|
||||
/// - ``databaseRegion(_:)``
|
||||
///
|
||||
/// ### Adapting the Fetched Rows
|
||||
///
|
||||
/// - ``adapted(_:)``
|
||||
@@ -217,8 +213,8 @@ public struct AnyFetchRequest<RowDecoder> {
|
||||
///
|
||||
/// // AnyFetchRequest<Row>
|
||||
/// let rowRequest = playerRequest.asRequest(of: Row.self)
|
||||
public func asRequest<RowDecoder>(of type: RowDecoder.Type) -> AnyFetchRequest<RowDecoder> {
|
||||
AnyFetchRequest<RowDecoder>(request: request)
|
||||
public func asRequest<T>(of type: T.Type) -> AnyFetchRequest<T> {
|
||||
AnyFetchRequest<T>(request: request)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public protocol StatementColumnConvertible {
|
||||
///
|
||||
/// Do not check for `NULL` in your implementation of this method. Null
|
||||
/// database values are handled
|
||||
/// in ``fromStatement(_:atUncheckedIndex:)-2i8y6``.
|
||||
/// in ``StatementColumnConvertible/fromStatement(_:atUncheckedIndex:)-2i8y6``.
|
||||
///
|
||||
/// For example, here is the how Int64 adopts StatementColumnConvertible:
|
||||
///
|
||||
|
||||
@@ -159,7 +159,7 @@ let cancellable = try sharedObservation
|
||||
|
||||
While the standard ``tracking(_:)`` method lets you track changes to a fetched value and receive any changes to it, sometimes your use case might require more granular control.
|
||||
|
||||
Consider a scenario where you'd like to get a specific Player's row, but only when their `score` column changes. You can use ``tracking(region:fetch:)`` to do just that:
|
||||
Consider a scenario where you'd like to get a specific Player's row, but only when their `score` column changes. You can use ``tracking(region:_:fetch:)`` to do just that:
|
||||
|
||||
```swift
|
||||
let observation = ValueObservation.tracking(
|
||||
@@ -172,7 +172,7 @@ let observation = ValueObservation.tracking(
|
||||
)
|
||||
```
|
||||
|
||||
This ``tracking(region:fetch:)`` method lets you entirely separate the **observed region** from the **fetched value** itself, for maximum flexibility. See ``DatabaseRegionConvertible`` for more information about the regions that can be tracked.
|
||||
This ``tracking(region:_:fetch:)`` method lets you entirely separate the **observed region(s)** from the **fetched value** itself, for maximum flexibility. See ``DatabaseRegionConvertible`` for more information about the regions that can be tracked.
|
||||
|
||||
## ValueObservation Performance
|
||||
|
||||
@@ -228,7 +228,7 @@ When needed, you can help GRDB optimize observations and reduce database content
|
||||
|
||||
- ``tracking(_:)``
|
||||
- ``trackingConstantRegion(_:)``
|
||||
- ``tracking(region:fetch:)``
|
||||
- ``tracking(region:_:fetch:)``
|
||||
- ``tracking(regions:fetch:)``
|
||||
|
||||
### Creating a Shared Observation
|
||||
|
||||
@@ -436,7 +436,7 @@ extension QueryInterfaceRequest: DerivableRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public func with<RowDecoder>(_ cte: CommonTableExpression<RowDecoder>) -> Self {
|
||||
public func with<T>(_ cte: CommonTableExpression<T>) -> Self {
|
||||
with {
|
||||
$0.relation.ctes[cte.tableName] = cte.cte
|
||||
}
|
||||
|
||||
@@ -1965,7 +1965,7 @@ extension SQLSpecificExpressible {
|
||||
|
||||
/// Returns an aliased column with the same name as the coding key.
|
||||
///
|
||||
/// See ``forKey(_:)-3xk0``.
|
||||
/// See <doc:SQLSpecificExpressible/forKey(_:)-3xk0>.
|
||||
public func forKey(_ key: some CodingKey) -> SQLSelection {
|
||||
forKey(key.stringValue)
|
||||
}
|
||||
|
||||
@@ -298,10 +298,10 @@ extension Table {
|
||||
/// let maxScore: Int = row[1]
|
||||
/// }
|
||||
/// ```
|
||||
public func select<RowDecoder>(
|
||||
public func select<T>(
|
||||
_ selection: [any SQLSelectable],
|
||||
as type: RowDecoder.Type = RowDecoder.self)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
as type: T.Type = T.self)
|
||||
-> QueryInterfaceRequest<T>
|
||||
{
|
||||
all().select(selection, as: type)
|
||||
}
|
||||
@@ -328,10 +328,10 @@ extension Table {
|
||||
/// let maxScore: Int = row[1]
|
||||
/// }
|
||||
/// ```
|
||||
public func select<RowDecoder>(
|
||||
public func select<T>(
|
||||
_ selection: any SQLSelectable...,
|
||||
as type: RowDecoder.Type = RowDecoder.self)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
as type: T.Type = T.self)
|
||||
-> QueryInterfaceRequest<T>
|
||||
{
|
||||
all().select(selection, as: type)
|
||||
}
|
||||
@@ -353,11 +353,11 @@ extension Table {
|
||||
/// let request = playerTable.select(sql: "IFNULL(name, ?)", arguments: [defaultName], as: String.self)
|
||||
/// let names = try request.fetchAll(db) // [String]
|
||||
/// ```
|
||||
public func select<RowDecoder>(
|
||||
public func select<T>(
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
as type: RowDecoder.Type = RowDecoder.self)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
as type: T.Type = T.self)
|
||||
-> QueryInterfaceRequest<T>
|
||||
{
|
||||
all().select(SQL(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
@@ -376,10 +376,10 @@ extension Table {
|
||||
/// let request = playerTable.select(literal: "IFNULL(name, \(defaultName))", as: String.self)
|
||||
/// let names = try request.fetchAll(db) // [String]
|
||||
/// ```
|
||||
public func select<RowDecoder>(
|
||||
public func select<T>(
|
||||
literal sqlLiteral: SQL,
|
||||
as type: RowDecoder.Type = RowDecoder.self)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
as type: T.Type = T.self)
|
||||
-> QueryInterfaceRequest<T>
|
||||
{
|
||||
all().select(sqlLiteral, as: type)
|
||||
}
|
||||
|
||||
@@ -434,6 +434,15 @@ extension MutablePersistableRecord {
|
||||
// Rowid is the last column
|
||||
let rowid: Int64 = row[row.count - 1]
|
||||
let returned = try decode(row)
|
||||
|
||||
// Now that we have fetched the values we need, we could stop
|
||||
// there. But let's make sure we fully consume the cursor
|
||||
// anyway, until SQLITE_DONE. This is necessary, for example,
|
||||
// for upserts in tables that are synchronized with an
|
||||
// FTS5 table.
|
||||
// See <https://github.com/groue/GRDB.swift/issues/1390>
|
||||
while try cursor.next() != nil { }
|
||||
|
||||
return (rowid, returned)
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ final class Pool<T> {
|
||||
|
||||
/// Blocks until no element is used, and runs the `barrier` function before
|
||||
/// any other element is dequeued.
|
||||
func barrier<T>(execute barrier: () throws -> T) rethrows -> T {
|
||||
func barrier<R>(execute barrier: () throws -> R) rethrows -> R {
|
||||
try barrierQueue.sync(flags: [.barrier]) {
|
||||
itemsGroup.wait()
|
||||
return try barrier()
|
||||
|
||||
@@ -722,50 +722,53 @@ extension ValueObservation {
|
||||
///
|
||||
/// ```swift
|
||||
/// // Tracks the full database
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: .fullDatabase,
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the full 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: Player.all(),
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the full 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: Table("player"),
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the row with id 42 in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: Player.filter(id: 42),
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the 'score' column in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: Player.select(Column("score"),
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the 'score' column in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: SQLRequest("SELECT score FROM player"),
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks both the 'player' and 'team' tables
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// region: Player.all(), Team.all(),
|
||||
/// fetch: { db in ... })
|
||||
/// ```
|
||||
///
|
||||
/// - parameter region: A list of observed regions.
|
||||
/// - parameter region: A region to observe.
|
||||
/// - parameter otherRegions: A list of supplementary regions
|
||||
/// to observe.
|
||||
/// - parameter fetch: The closure that fetches the observed value.
|
||||
public static func tracking<Value>(
|
||||
region: any DatabaseRegionConvertible...,
|
||||
region: any DatabaseRegionConvertible,
|
||||
_ otherRegions: any DatabaseRegionConvertible...,
|
||||
fetch: @escaping (Database) throws -> Value)
|
||||
-> Self
|
||||
where Reducer == ValueReducers.Fetch<Value>
|
||||
{
|
||||
tracking(regions: region, fetch: fetch)
|
||||
tracking(regions: [region] + otherRegions, fetch: fetch)
|
||||
}
|
||||
|
||||
/// Creates a `ValueObservation` that notifies the fetched value whenever
|
||||
@@ -778,37 +781,37 @@ extension ValueObservation {
|
||||
///
|
||||
/// ```swift
|
||||
/// // Tracks the full database
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [.fullDatabase],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the full 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [Player.all()],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the full 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [Table("player")],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the row with id 42 in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [Player.filter(id: 42)],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the 'score' column in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [Player.select(Column("score")],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks the 'score' column in the 'player' table
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [SQLRequest("SELECT score FROM player")],
|
||||
/// fetch: { db in ... })
|
||||
///
|
||||
/// // Tracks both the 'player' and 'team' tables
|
||||
/// let observation = ValueObservation.tracking
|
||||
/// let observation = ValueObservation.tracking(
|
||||
/// regions: [Player.all(), Team.all()],
|
||||
/// fetch: { db in ... })
|
||||
/// ```
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<a href="https://github.com/groue/GRDB.swift/actions/workflows/CI.yml"><img alt="CI Status" src="https://github.com/groue/GRDB.swift/actions/workflows/CI.yml/badge.svg?branch=master"></a>
|
||||
</p>
|
||||
|
||||
**Latest release**: June 2, 2023 • [version 6.15.0](https://github.com/groue/GRDB.swift/tree/v6.15.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
|
||||
**Latest release**: June 17, 2023 • [version 6.15.1](https://github.com/groue/GRDB.swift/tree/v6.15.1) • [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+
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>6.15.0</string>
|
||||
<string>6.15.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -334,5 +334,43 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Regression test for <https://github.com/groue/GRDB.swift/issues/1390>
|
||||
func testIssue1390() throws {
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
guard sqlite3_libversion_number() >= 3035000 else {
|
||||
throw XCTSkip("UPSERT is not available")
|
||||
}
|
||||
#else
|
||||
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else {
|
||||
throw XCTSkip("UPSERT is not available")
|
||||
}
|
||||
#endif
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
struct Content: Codable, Hashable, PersistableRecord {
|
||||
var id: String
|
||||
var text: String
|
||||
}
|
||||
|
||||
try db.create(table: "content") { t in
|
||||
t.primaryKey("id", .text)
|
||||
t.column("text", .text)
|
||||
}
|
||||
|
||||
try db.create(virtualTable: "fts", using: FTS5()) { t in
|
||||
t.tokenizer = .porter()
|
||||
t.synchronize(withTable: "content")
|
||||
t.column("id").notIndexed()
|
||||
t.column("text")
|
||||
}
|
||||
|
||||
try db.inTransaction {
|
||||
try Content(id: "foobar", text: "baz").upsert(db)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user