mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Sendable annotations for DAO
This commit is contained in:
1 parent
1af8a2256f
commit
fc7ca13c04
2 files changed
+14
-12
No files matched your search
@@ -1852,7 +1852,7 @@ extension Database {
|
||||
/// The available checkpoint modes.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/c3ref/wal_checkpoint_v2.html>
|
||||
public enum CheckpointMode: CInt {
|
||||
public enum CheckpointMode: CInt, Sendable {
|
||||
/// The `SQLITE_CHECKPOINT_PASSIVE` mode.
|
||||
case passive = 0
|
||||
|
||||
@@ -1959,7 +1959,7 @@ extension Database {
|
||||
/// An SQLite conflict resolution.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_conflict.html>
|
||||
public enum ConflictResolution: String {
|
||||
public enum ConflictResolution: String, Sendable {
|
||||
/// The `ROLLBACK` conflict resolution.
|
||||
case rollback = "ROLLBACK"
|
||||
|
||||
@@ -1979,7 +1979,7 @@ extension Database {
|
||||
/// A foreign key action.
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/foreignkeys.html>
|
||||
public enum ForeignKeyAction: String {
|
||||
public enum ForeignKeyAction: String, Sendable {
|
||||
/// The `CASCADE` foreign key action.
|
||||
case cascade = "CASCADE"
|
||||
|
||||
@@ -2135,7 +2135,7 @@ extension Database {
|
||||
///
|
||||
/// Related SQLite documentation: <https://www.sqlite.org/lang_transaction.html>.
|
||||
@frozen
|
||||
public enum TransactionCompletion {
|
||||
public enum TransactionCompletion: Sendable {
|
||||
case commit
|
||||
case rollback
|
||||
}
|
||||
@@ -2159,7 +2159,7 @@ extension Database {
|
||||
/// - Note: Only the multi-thread mode (`SQLITE_OPEN_NOMUTEX`) is currently
|
||||
/// supported, since all <doc:DatabaseConnections> access SQLite connections
|
||||
/// through a `SerializedDatabase`.
|
||||
enum ThreadingMode {
|
||||
enum ThreadingMode: Sendable {
|
||||
case `default`
|
||||
case multiThread
|
||||
case serialized
|
||||
|
||||
@@ -266,16 +266,17 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
|
||||
// MARK: - InsertQuery
|
||||
|
||||
private struct InsertQuery: Hashable {
|
||||
private struct InsertQuery: Hashable, Sendable {
|
||||
let onConflict: Database.ConflictResolution
|
||||
let tableName: String
|
||||
let insertedColumns: [String]
|
||||
}
|
||||
|
||||
extension InsertQuery {
|
||||
@ReadWriteBox private static var sqlCache: [InsertQuery: String] = [:]
|
||||
private static let cache: ReadWriteBox<[InsertQuery: String]> = ReadWriteBox(wrappedValue: [:])
|
||||
|
||||
var sql: String {
|
||||
if let sql = Self.sqlCache[self] {
|
||||
if let sql = Self.cache.wrappedValue[self] {
|
||||
return sql
|
||||
}
|
||||
let columnsSQL = insertedColumns.map(\.quotedDatabaseIdentifier).joined(separator: ", ")
|
||||
@@ -294,7 +295,7 @@ extension InsertQuery {
|
||||
VALUES (\(valuesSQL))
|
||||
"""
|
||||
}
|
||||
Self.sqlCache[self] = sql
|
||||
Self.cache.update { $0[self] = sql }
|
||||
return sql
|
||||
}
|
||||
}
|
||||
@@ -309,9 +310,10 @@ private struct UpdateQuery: Hashable {
|
||||
}
|
||||
|
||||
extension UpdateQuery {
|
||||
@ReadWriteBox private static var sqlCache: [UpdateQuery: String] = [:]
|
||||
private static let cache: ReadWriteBox<[UpdateQuery: String]> = ReadWriteBox(wrappedValue: [:])
|
||||
|
||||
var sql: String {
|
||||
if let sql = Self.sqlCache[self] {
|
||||
if let sql = Self.cache.wrappedValue[self] {
|
||||
return sql
|
||||
}
|
||||
let updateSQL = updatedColumns.map { "\($0.quotedDatabaseIdentifier)=?" }.joined(separator: ", ")
|
||||
@@ -331,7 +333,7 @@ extension UpdateQuery {
|
||||
WHERE \(whereSQL)
|
||||
"""
|
||||
}
|
||||
Self.sqlCache[self] = sql
|
||||
Self.cache.update { $0[self] = sql }
|
||||
return sql
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user