mirror of
https://github.com/groue/GRDB.swift
synced 2026-12-06 05:28:44 +00:00
Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7205b172f | ||
|
|
49d14e6b66 | ||
|
|
54ed7ec611 | ||
|
|
68e17351ff | ||
|
|
494e697e94 | ||
|
|
87b236dfe0 | ||
|
|
ea6d8e0123 | ||
|
|
073209f1dc | ||
|
|
430530f5f1 | ||
|
|
a716915280 | ||
|
|
ef36727d9a | ||
|
|
78b2796f46 | ||
|
|
3535a42c53 | ||
|
|
5a4d9b5cb9 | ||
|
|
a64b09d121 |
No files matched your search
@@ -46,7 +46,7 @@ jobs:
|
||||
name: "macOS"
|
||||
- xcode: "Xcode_16.1.app"
|
||||
runsOn: macOS-14
|
||||
destination: "OS=18.1,name=iPhone 15 Pro"
|
||||
destination: "OS=18.1,name=iPhone 16 Pro"
|
||||
name: "iOS"
|
||||
- xcode: "Xcode_16.1.app"
|
||||
runsOn: macOS-14
|
||||
|
||||
@@ -7,6 +7,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
#### 7.x Releases
|
||||
|
||||
- `7.2.x` Releases - [7.2.0](#720)
|
||||
- `7.1.x` Releases - [7.1.0](#710)
|
||||
- `7.0.x` Releases - [7.0.0](#700)
|
||||
- `7.0.0` Betas - [7.0.0-beta](#700-beta) - [7.0.0-beta.2](#700-beta2) - [7.0.0-beta.3](#700-beta3) - [7.0.0-beta.4](#700-beta4) - [7.0.0-beta.5](#700-beta5) - [7.0.0-beta.6](#700-beta6) - [7.0.0-beta.7](#700-beta7)
|
||||
|
||||
@@ -132,6 +134,20 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
---
|
||||
|
||||
## 7.2.0
|
||||
|
||||
Released February 12, 2025
|
||||
|
||||
- **New**: Select ids with selectID() by [@groue](https://github.com/groue) in [#1719](https://github.com/groue/GRDB.swift/pull/1719)
|
||||
|
||||
## 7.1.0
|
||||
|
||||
Released February 5, 2025
|
||||
|
||||
- **New**: Expose `sqlite3_libversion_number` as `Database.sqliteLibVersionNumber` by [@groue](https://github.com/groue) in [#1713](https://github.com/groue/GRDB.swift/pull/1713)
|
||||
- **Fixed**: DatabaseQueue restores its read/write abilities when an async read-only database access is cancelled by [@groue](https://github.com/groue) in [#1716](https://github.com/groue/GRDB.swift/pull/1716)
|
||||
- **New**: Allow RxGRDB to compile without warning by [@groue](https://github.com/groue) in [#1717](https://github.com/groue/GRDB.swift/pull/1717)
|
||||
|
||||
## 7.0.0
|
||||
|
||||
Released January 26, 2025
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDB.swift'
|
||||
s.version = '7.0.0'
|
||||
s.version = '7.2.0'
|
||||
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
|
||||
|
||||
@@ -1288,6 +1288,12 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
return
|
||||
}
|
||||
|
||||
// Suspension should not prevent adjusting the read-only mode.
|
||||
// See <https://github.com/groue/GRDB.swift/issues/1715>.
|
||||
if statement.isQueryOnlyPragma {
|
||||
return
|
||||
}
|
||||
|
||||
// How should we interrupt the statement?
|
||||
enum Interrupt {
|
||||
case abort // Rollback and throw SQLITE_ABORT
|
||||
|
||||
@@ -83,6 +83,7 @@ extension DatabaseRegionObservation {
|
||||
/// - parameter onChange: The closure to execute when a transaction has
|
||||
/// modified the observed region.
|
||||
/// - returns: A DatabaseCancellable that can stop the observation.
|
||||
@preconcurrency // For RxGRDB, see <https://github.com/RxSwiftCommunity/RxGRDB/issues/72#issuecomment-2631125658>
|
||||
public func start(
|
||||
in writer: any DatabaseWriter,
|
||||
onError: @escaping @Sendable (Error) -> Void,
|
||||
|
||||
@@ -92,6 +92,9 @@ public final class Statement {
|
||||
/// The effects on the database (reported by `sqlite3_set_authorizer`).
|
||||
private(set) var authorizerEventKinds: [DatabaseEventKind] = []
|
||||
|
||||
/// If true, the statement executes is a `PRAGMA QUERY_ONLY` statement.
|
||||
private(set) var isQueryOnlyPragma = false
|
||||
|
||||
/// A boolean value indicating if the prepared statement makes no direct
|
||||
/// changes to the content of the database file.
|
||||
///
|
||||
@@ -160,6 +163,7 @@ public final class Statement {
|
||||
self.invalidatesDatabaseSchemaCache = authorizer.invalidatesDatabaseSchemaCache
|
||||
self.transactionEffect = authorizer.transactionEffect
|
||||
self.authorizerEventKinds = authorizer.databaseEventKinds
|
||||
self.isQueryOnlyPragma = authorizer.isQueryOnlyPragma
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -41,6 +41,9 @@ final class StatementAuthorizer {
|
||||
/// savepoint statement.
|
||||
var transactionEffect: Statement.TransactionEffect?
|
||||
|
||||
/// If true, the statement executes is a `PRAGMA QUERY_ONLY` statement.
|
||||
var isQueryOnlyPragma = false
|
||||
|
||||
private var isDropStatement = false
|
||||
|
||||
init(_ database: Database) {
|
||||
@@ -67,6 +70,7 @@ final class StatementAuthorizer {
|
||||
databaseEventKinds = []
|
||||
invalidatesDatabaseSchemaCache = false
|
||||
transactionEffect = nil
|
||||
isQueryOnlyPragma = false
|
||||
isDropStatement = false
|
||||
}
|
||||
|
||||
@@ -192,6 +196,11 @@ final class StatementAuthorizer {
|
||||
}
|
||||
return SQLITE_OK
|
||||
|
||||
case SQLITE_PRAGMA:
|
||||
if let cString1 {
|
||||
isQueryOnlyPragma = sqlite3_stricmp(cString1, "query_only") == 0
|
||||
}
|
||||
return SQLITE_OK
|
||||
default:
|
||||
return SQLITE_OK
|
||||
}
|
||||
|
||||
@@ -393,16 +393,16 @@ Extensions to the `DerivableRequest` protocol can not change the type of request
|
||||
|
||||
```swift
|
||||
extension QueryInterfaceRequest<Author> {
|
||||
// Selects author ids
|
||||
func selectId() -> QueryInterfaceRequest<Int64> {
|
||||
selectPrimaryKey(as: Int64.self)
|
||||
// Selects authors' name
|
||||
func selectName() -> QueryInterfaceRequest<String> {
|
||||
select(Author.Columns.name)
|
||||
}
|
||||
}
|
||||
|
||||
// The ids of Japanese authors
|
||||
let ids: Set<Int64> = try Author.all()
|
||||
// The names of Japanese authors
|
||||
let names: Set<String> = try Author.all()
|
||||
.filter(countryCode: "JP")
|
||||
.selectId()
|
||||
.selectName()
|
||||
.fetchSet(db)
|
||||
```
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
/// - ``select(_:as:)-3o8qw``
|
||||
/// - ``select(literal:as:)``
|
||||
/// - ``select(sql:arguments:as:)``
|
||||
/// - ``selectID()``
|
||||
/// - ``selectPrimaryKey(as:)``
|
||||
///
|
||||
/// ### Batch Delete
|
||||
@@ -237,7 +238,7 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
select(sqlLiteral, as: type)
|
||||
}
|
||||
|
||||
/// Selects the primary key.
|
||||
/// Returns a request that selects the primary key.
|
||||
///
|
||||
/// All primary keys are supported:
|
||||
///
|
||||
@@ -281,6 +282,46 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
.asRequest(of: PrimaryKey.self)
|
||||
}
|
||||
|
||||
/// Returns a request that selects the primary key.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // SELECT id FROM player WHERE ...
|
||||
/// let request = try Player.filter(...).selectID()
|
||||
/// ```
|
||||
///
|
||||
/// **Important**: if the record type has an `ID` type that is an
|
||||
/// optional, such as `Int64?`, it is recommended to prefer
|
||||
/// ``selectPrimaryKey(as:)`` instead:
|
||||
///
|
||||
/// ```swift
|
||||
/// struct Player: Identifiable {
|
||||
/// var id: Int64?
|
||||
/// }
|
||||
///
|
||||
/// // NOT RECOMMENDED: Set<Int64?>
|
||||
/// let ids = try Player.filter(...)
|
||||
/// .selectID()
|
||||
/// .fetchSet(db)
|
||||
///
|
||||
/// // BETTER: Set<Int64>
|
||||
/// let ids = try Player.filter(...)
|
||||
/// .selectPrimaryKey(as: Int64.self)
|
||||
/// .fetchSet(db)
|
||||
/// ```
|
||||
public func selectID() -> QueryInterfaceRequest<RowDecoder.ID>
|
||||
where RowDecoder: Identifiable
|
||||
{
|
||||
selectWhenConnected { db in
|
||||
let primaryKey = try db.primaryKey(self.databaseTableName)
|
||||
GRDBPrecondition(
|
||||
primaryKey.columns.count == 1,
|
||||
"selectID requires a single-column primary key in the table \(self.databaseTableName)")
|
||||
return [Column(primaryKey.columns[0])]
|
||||
}.asRequest(of: RowDecoder.ID.self)
|
||||
}
|
||||
|
||||
public func annotatedWhenConnected(
|
||||
with selection: @escaping @Sendable (Database) throws -> [any SQLSelectable])
|
||||
-> Self
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
/// - ``select(literal:as:)``
|
||||
/// - ``select(sql:arguments:)``
|
||||
/// - ``select(sql:arguments:as:)``
|
||||
/// - ``selectID()``
|
||||
/// - ``selectPrimaryKey(as:)``
|
||||
/// - ``with(_:)``
|
||||
///
|
||||
@@ -424,6 +425,40 @@ extension Table {
|
||||
all().selectPrimaryKey(as: type)
|
||||
}
|
||||
|
||||
/// Returns a request that selects the primary key.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// let table = Table<Player>("player")
|
||||
///
|
||||
/// // SELECT id FROM player
|
||||
/// let request = try table.selectID()
|
||||
/// ```
|
||||
///
|
||||
/// **Important**: if the record type has an `ID` type that is an
|
||||
/// optional, such as `Int64?`, it is recommended to prefer
|
||||
/// ``selectPrimaryKey(as:)`` instead:
|
||||
///
|
||||
/// ```swift
|
||||
/// struct Player: Identifiable {
|
||||
/// var id: Int64?
|
||||
/// }
|
||||
///
|
||||
/// let table = Table<Player>("player")
|
||||
///
|
||||
/// // NOT RECOMMENDED: Set<Int64?>
|
||||
/// let ids = try table.selectID().fetchSet(db)
|
||||
///
|
||||
/// // BETTER: Set<Int64>
|
||||
/// let ids = try table.selectPrimaryKey(as: Int64.self).fetchSet(db)
|
||||
/// ```
|
||||
public func selectID() -> QueryInterfaceRequest<RowDecoder.ID>
|
||||
where RowDecoder: Identifiable
|
||||
{
|
||||
all().selectID()
|
||||
}
|
||||
|
||||
/// Returns a request with the provided result columns appended to the
|
||||
/// table columns.
|
||||
///
|
||||
|
||||
@@ -251,6 +251,36 @@ extension TableRecord {
|
||||
all().selectPrimaryKey(as: type)
|
||||
}
|
||||
|
||||
/// Returns a request that selects the primary key.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // SELECT id FROM player
|
||||
/// let request = try Player.selectID()
|
||||
/// ```
|
||||
///
|
||||
/// **Important**: if the record type has an `ID` type that is an
|
||||
/// optional, such as `Int64?`, it is recommended to prefer
|
||||
/// ``selectPrimaryKey(as:)`` instead:
|
||||
///
|
||||
/// ```swift
|
||||
/// struct Player: Identifiable {
|
||||
/// var id: Int64?
|
||||
/// }
|
||||
///
|
||||
/// // NOT RECOMMENDED: Set<Int64?>
|
||||
/// let ids = try Player.selectID().fetchSet(db)
|
||||
///
|
||||
/// // BETTER: Set<Int64>
|
||||
/// let ids = try Player.selectPrimaryKey(as: Int64.self).fetchSet(db)
|
||||
/// ```
|
||||
public static func selectID() -> QueryInterfaceRequest<Self.ID>
|
||||
where Self: Identifiable
|
||||
{
|
||||
all().selectID()
|
||||
}
|
||||
|
||||
/// Returns a request with the provided result columns appended to the
|
||||
/// record selection.
|
||||
///
|
||||
|
||||
@@ -98,6 +98,7 @@ import Foundation
|
||||
/// - ``select(literal:as:)``
|
||||
/// - ``select(sql:arguments:)``
|
||||
/// - ``select(sql:arguments:as:)``
|
||||
/// - ``selectID()``
|
||||
/// - ``selectPrimaryKey(as:)``
|
||||
/// - ``with(_:)``
|
||||
///
|
||||
|
||||
@@ -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**: January 26, 2025 • [version 7.0.0](https://github.com/groue/GRDB.swift/tree/v7.0.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
|
||||
**Latest release**: February 12, 2025 • [version 7.2.0](https://github.com/groue/GRDB.swift/tree/v7.2.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
|
||||
|
||||
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ • SQLite 3.20.0+ • Swift 6+ / Xcode 16+
|
||||
|
||||
@@ -3341,6 +3341,16 @@ You can now build requests with the following methods: `all`, `none`, `select`,
|
||||
Player.select(nameColumn, as: String.self)
|
||||
```
|
||||
|
||||
- [`selectID()`](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/queryinterfacerequest/selectID()) is available on [Identifiable Records]. It supports all tables that have a single-column primary key:
|
||||
|
||||
```swift
|
||||
// SELECT id FROM player
|
||||
Player.selectID()
|
||||
|
||||
// SELECT id FROM player WHERE name IS NOT NULL
|
||||
Player.filter(nameColumn != nil).selectID()
|
||||
```
|
||||
|
||||
- [`annotated(with: expression...)`](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/selectionrequest/annotated(with:)-6ehs4) extends the selection.
|
||||
|
||||
```swift
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>7.0.0</string>
|
||||
<string>7.2.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -415,6 +415,57 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
|
||||
// MARK: - Task Cancellation
|
||||
|
||||
// Regression test for <https://github.com/groue/GRDB.swift/issues/1715>.
|
||||
func test_write_is_possible_after_read_cancelled_after_database_access() async throws {
|
||||
// When a read access is cancelled, DatabaseQueue needs to execute
|
||||
// `PRAGMA query_only=0` in order to restore the read/write access.
|
||||
//
|
||||
// Here we test that this pragma can run from a cancelled read.
|
||||
//
|
||||
// Small difficulty: some SQLite versions (seen with 3.43.2) execute
|
||||
// the `query_only` pragma at compile time, not only at execution
|
||||
// time (yeah, that's an SQLite bug). The problem of this bug is
|
||||
// that even if the `PRAGMA query_only=0` is not executed due to
|
||||
// Task cancellation, its side effect is still executed when it is
|
||||
// compiled, unintentionally. A cancelled `PRAGMA query_only=0`
|
||||
// still works!
|
||||
//
|
||||
// To avoid this SQLite bug from messing with our test, we perform
|
||||
// two reads: one that compiles and cache `PRAGMA query_only`
|
||||
// statements, and a second read that we cancel. This time the
|
||||
// `PRAGMA query_only=0` triggers its side effect if and only if it
|
||||
// is actually executed (the behavior we are testing).
|
||||
func test(_ dbWriter: some DatabaseWriter) async throws {
|
||||
let semaphore = AsyncSemaphore(value: 0)
|
||||
let cancelledTaskMutex = Mutex<Task<Void, any Error>?>(nil)
|
||||
let task = Task {
|
||||
await semaphore.wait()
|
||||
|
||||
// First read, not cancelled, so that all `query_only`
|
||||
// pragma statements are compiled (see above).
|
||||
try await dbWriter.read { db in }
|
||||
|
||||
// Second read, cancelled.
|
||||
try await dbWriter.read { db in
|
||||
try XCTUnwrap(cancelledTaskMutex.load()).cancel()
|
||||
}
|
||||
}
|
||||
cancelledTaskMutex.store(task)
|
||||
semaphore.signal()
|
||||
// Wait until reads are completed
|
||||
try? await task.value
|
||||
|
||||
// Write access is restored after read cancellation (no error is thrown)
|
||||
try await dbWriter.write { db in
|
||||
try db.execute(sql: "CREATE TABLE test(a)")
|
||||
}
|
||||
}
|
||||
|
||||
try await test(makeDatabaseQueue())
|
||||
try await test(makeDatabasePool())
|
||||
try await test(AnyDatabaseWriter(makeDatabaseQueue()))
|
||||
}
|
||||
|
||||
func test_writeWithoutTransaction_is_cancelled_by_Task_cancellation_performed_before_database_access() async throws {
|
||||
func test(_ dbWriter: some DatabaseWriter) async throws {
|
||||
let semaphore = AsyncSemaphore(value: 0)
|
||||
|
||||
@@ -800,6 +800,16 @@ class RecordMinimalNonOptionalPrimaryKeySingleTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func test_static_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalNonOptionalPrimaryKeySingle(id: "theUUID")
|
||||
try record.insert(db)
|
||||
let ids: [String] = try MinimalSingle.selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, ["theUUID"])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectPrimaryKey() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -811,4 +821,14 @@ class RecordMinimalNonOptionalPrimaryKeySingleTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows, [["id": "theUUID"]])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalNonOptionalPrimaryKeySingle(id: "theUUID")
|
||||
try record.insert(db)
|
||||
let ids: [String] = try MinimalSingle.all().selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, ["theUUID"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -844,6 +844,16 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func test_static_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalRowID()
|
||||
try record.insert(db)
|
||||
let ids: [Int64?] = try MinimalRowID.selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, [1])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectPrimaryKey() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -855,4 +865,14 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
XCTAssertEqual(rows, [["id": 1]])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalRowID()
|
||||
try record.insert(db)
|
||||
let ids: [Int64?] = try MinimalRowID.all().selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, [1])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE \"UUID\" = '\(record.UUID!)'")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Fetch With Key Request
|
||||
|
||||
@@ -661,7 +661,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
_ = try MinimalSingle.find(db, key: id)
|
||||
XCTFail("Expected RecordError")
|
||||
} catch RecordError.recordNotFound(databaseTableName: "minimalSingles", key: ["UUID": .null]) { }
|
||||
|
||||
|
||||
do {
|
||||
let fetchedRecord = try MinimalSingle.find(db, key: record.UUID)
|
||||
XCTAssertTrue(fetchedRecord.UUID == record.UUID)
|
||||
@@ -680,7 +680,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Fetch With Primary Key Request
|
||||
|
||||
@@ -861,7 +861,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
// MARK: Select PrimaryKey
|
||||
|
||||
|
||||
func test_static_selectPrimaryKey() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -875,6 +875,17 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func test_static_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalSingle()
|
||||
record.UUID = "theUUID"
|
||||
try record.insert(db)
|
||||
let ids: [String] = try MinimalSingle.selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, ["theUUID"])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectPrimaryKey() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -887,4 +898,15 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows, [["UUID": "theUUID"]])
|
||||
}
|
||||
}
|
||||
|
||||
func test_request_selectID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let record = MinimalSingle()
|
||||
record.UUID = "theUUID"
|
||||
try record.insert(db)
|
||||
let ids: [String] = try MinimalSingle.all().selectID().fetchAll(db)
|
||||
XCTAssertEqual(ids, ["theUUID"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,8 @@ class TableTests: GRDBTestCase {
|
||||
try assertEqualSQL(db, t.filter(ids: [1, 2, 3]), """
|
||||
SELECT * FROM "player" WHERE "id" IN (1, 2, 3)
|
||||
""")
|
||||
|
||||
try XCTAssertEqual(t.selectID().fetchOne(db), 1)
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -148,6 +150,8 @@ class TableTests: GRDBTestCase {
|
||||
try assertEqualSQL(db, t.filter(ids: [1, 2, 3]), """
|
||||
SELECT * FROM "player" WHERE "id" IN (1, 2, 3)
|
||||
""")
|
||||
|
||||
try XCTAssertEqual(t.selectID().fetchOne(db), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user