Sendable annotations

This commit is contained in:
Gwendal Roué committed 2023-11-03 10:53:49 +01:00
1 parent 61e0e97b39
commit e7eac0d500
88 files changed
+957 -711

No files matched your search

@@ -21,9 +21,9 @@
///
/// Such late computations are backed by DatabasePromise. In our example,
/// see SQLRelation.filterPromise.
struct DatabasePromise<T> {
struct DatabasePromise<T: Sendable> {
/// Returns the resolved value.
let resolve: (Database) throws -> T
let resolve: @Sendable (Database) throws -> T
/// Creates a promise that resolves to a value.
init(value: T) {
@@ -31,12 +31,12 @@ struct DatabasePromise<T> {
}
/// Creates a promise from a closure.
init(_ resolve: @escaping (Database) throws -> T) {
init(_ resolve: @escaping @Sendable (Database) throws -> T) {
self.resolve = resolve
}
/// Returns a promise whose value is transformed by the given closure.
func map<U>(_ transform: @escaping (T) throws -> U) -> DatabasePromise<U> {
func map<U>(_ transform: @escaping @Sendable (T) throws -> U) -> DatabasePromise<U> {
DatabasePromise<U> { db in
try transform(resolve(db))
}
+3 -3
View File
@@ -57,7 +57,7 @@ public struct SQLExpression {
var preferredJSONInterpretation = JSONInterpretation.deferredToSQLite
/// The private implementation of the public `SQLExpression`.
private enum Impl {
private enum Impl: Sendable {
/// A column.
///
/// id
@@ -315,7 +315,7 @@ public struct SQLExpression {
/// 1000.databaseValue]
/// let request = Player.select(values.joined(operator: .add))
/// ```
public struct AssociativeBinaryOperator: Hashable {
public struct AssociativeBinaryOperator: Hashable, Sendable {
/// The SQL operator
let sql: String
@@ -2109,7 +2109,7 @@ extension SQLExpression {
/// A type that can be used as an SQL expression.
///
/// Related SQLite documentation <https://www.sqlite.org/syntax/expr.html>
public protocol SQLExpressible {
public protocol SQLExpressible: Sendable {
/// Returns an SQL expression.
var sqlExpression: SQLExpression { get }
}
+1 -1
View File
@@ -138,7 +138,7 @@ extension SQLOrdering {
/// ### Supporting Type
///
/// - ``SQLOrdering``
public protocol SQLOrderingTerm {
public protocol SQLOrderingTerm: Sendable {
/// Returns an SQL ordering.
var sqlOrdering: SQLOrdering { get }
}
+15 -15
View File
@@ -90,8 +90,8 @@
/// // JOIN passport ON passport.citizenId = citizens.id
/// // AND passport.countryCode IN ('BE', 'DE', 'FR', ...);
/// Country.including(all: Country.citizens)
struct SQLRelation {
struct Child: Refinable {
struct SQLRelation: Sendable {
struct Child: Refinable, Sendable {
enum Kind {
// Record.including(optional: association)
case oneOptional
@@ -187,7 +187,7 @@ extension SQLRelation {
/// Convenience factory methods which selects all rows from a table.
static func all(
fromTable tableName: String,
selection: @escaping (Database) -> [SQLSelection] = { _ in [.allColumns] })
selection: @escaping @Sendable (Database) -> [SQLSelection] = { _ in [.allColumns] })
-> Self
{
SQLRelation(
@@ -197,7 +197,7 @@ extension SQLRelation {
}
extension SQLRelation: Refinable {
func selectWhenConnected(_ selection: @escaping (Database) throws -> [SQLSelection]) -> Self {
func selectWhenConnected(_ selection: @escaping @Sendable (Database) throws -> [SQLSelection]) -> Self {
with {
$0.selectionPromise = DatabasePromise(selection)
}
@@ -228,7 +228,7 @@ extension SQLRelation: Refinable {
}
}
func annotatedWhenConnected(with selection: @escaping (Database) throws -> [SQLSelection]) -> Self {
func annotatedWhenConnected(with selection: @escaping @Sendable (Database) throws -> [SQLSelection]) -> Self {
with {
let old = $0.selectionPromise
$0.selectionPromise = DatabasePromise { db in
@@ -242,7 +242,7 @@ extension SQLRelation: Refinable {
annotatedWhenConnected(with: { _ in selection })
}
func filterWhenConnected(_ predicate: @escaping (Database) throws -> SQLExpression) -> Self {
func filterWhenConnected(_ predicate: @escaping @Sendable (Database) throws -> SQLExpression) -> Self {
with {
if let old = $0.filterPromise {
$0.filterPromise = DatabasePromise { db in
@@ -259,7 +259,7 @@ extension SQLRelation: Refinable {
filterWhenConnected { _ in predicate }
}
func orderWhenConnected(_ orderings: @escaping (Database) throws -> [SQLOrdering]) -> Self {
func orderWhenConnected(_ orderings: @escaping @Sendable (Database) throws -> [SQLOrdering]) -> Self {
with {
$0.ordering = SQLRelation.Ordering(orderings: orderings)
}
@@ -313,13 +313,13 @@ extension SQLRelation: Refinable {
}
}
func groupWhenConnected(_ expressions: @escaping (Database) throws -> [SQLExpression]) -> Self {
func groupWhenConnected(_ expressions: @escaping @Sendable (Database) throws -> [SQLExpression]) -> Self {
with {
$0.groupPromise = DatabasePromise(expressions)
}
}
func havingWhenConnected(_ predicate: @escaping (Database) throws -> SQLExpression) -> Self {
func havingWhenConnected(_ predicate: @escaping @Sendable (Database) throws -> SQLExpression) -> Self {
with {
if let old = $0.havingExpressionPromise {
$0.havingExpressionPromise = DatabasePromise { db in
@@ -672,7 +672,7 @@ struct SQLLimit {
// MARK: - SQLSource
struct SQLSource {
struct SQLSource: Sendable {
var tableName: String
var alias: TableAlias?
@@ -691,7 +691,7 @@ struct SQLSource {
extension SQLRelation {
/// SQLRelation.Ordering provides the order clause to SQLRelation.
struct Ordering {
struct Ordering: Sendable {
private enum Element {
case terms(DatabasePromise<[SQLOrdering]>)
case ordering(SQLRelation.Ordering)
@@ -740,7 +740,7 @@ extension SQLRelation {
isReversed: false)
}
init(orderings: @escaping (Database) throws -> [SQLOrdering]) {
init(orderings: @escaping @Sendable (Database) throws -> [SQLOrdering]) {
self.init(
elements: [.terms(DatabasePromise(orderings))],
isReversed: false)
@@ -796,7 +796,7 @@ extension SQLRelation {
/// // SELECT * FROM book WHERE author.id = 1
/// // ~~~~~~~~~~~~~
/// author.request(for: Author.books)
enum SQLAssociationCondition {
enum SQLAssociationCondition: Sendable {
/// A condition based on a foreign key.
case foreignKey(SQLForeignKeyCondition)
@@ -814,7 +814,7 @@ enum SQLAssociationCondition {
/// player[Column("id")] == bonus[Column("playerID")]
/// })
/// Player.with(bonus).joining(required: association)
case expression((_ left: TableAlias, _ right: TableAlias) -> SQLExpression?)
case expression(@Sendable (_ left: TableAlias, _ right: TableAlias) -> SQLExpression?)
/// The condition that does not constrain the two associated tables
/// in any way.
@@ -847,7 +847,7 @@ enum SQLAssociationCondition {
}
/// An association condition based on a foreign key.
struct SQLForeignKeyCondition: Equatable {
struct SQLForeignKeyCondition: Equatable, Sendable {
/// The destination table of an association.
///
/// In `Author.hasMany(Book.self)`, the destination is `book`.
+2 -2
View File
@@ -19,7 +19,7 @@ public struct SQLSelection {
private var impl: Impl
/// The private implementation of the public `SQLSelection`.
private enum Impl {
private enum Impl: Sendable {
/// All columns: `*`
case allColumns
@@ -301,7 +301,7 @@ enum SQLCount {
///
/// - ``AllColumns``
/// - ``SQLSelection``
public protocol SQLSelectable {
public protocol SQLSelectable: Sendable {
/// Returns an SQL selection.
var sqlSelection: SQLSelection { get }
}
+15 -15
View File
@@ -138,7 +138,7 @@
/// ### Database Observation Support
///
/// - ``databaseRegion(_:)``
public struct Table<RowDecoder> {
public struct Table<RowDecoder>: Sendable {
/// The table name.
public var tableName: String
@@ -800,7 +800,7 @@ extension Table {
/// ```
///
/// - parameter db: A database connection.
public func fetchCount(_ db: Database) throws -> Int {
@Sendable public func fetchCount(_ db: Database) throws -> Int {
try all().fetchCount(db)
}
}
@@ -860,7 +860,7 @@ extension Table where RowDecoder: FetchableRecord {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
@Sendable public func fetchAll(_ db: Database) throws -> [RowDecoder] {
try all().fetchAll(db)
}
@@ -880,7 +880,7 @@ extension Table where RowDecoder: FetchableRecord {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchOne(_ db: Database) throws -> RowDecoder? {
@Sendable public func fetchOne(_ db: Database) throws -> RowDecoder? {
try all().fetchOne(db)
}
}
@@ -902,7 +902,7 @@ extension Table where RowDecoder: FetchableRecord & Hashable {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
@Sendable public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
try all().fetchSet(db)
}
}
@@ -961,7 +961,7 @@ extension Table where RowDecoder == Row {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchAll(_ db: Database) throws -> [Row] {
@Sendable public func fetchAll(_ db: Database) throws -> [Row] {
try all().fetchAll(db)
}
@@ -980,7 +980,7 @@ extension Table where RowDecoder == Row {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchOne(_ db: Database) throws -> Row? {
@Sendable public func fetchOne(_ db: Database) throws -> Row? {
try all().fetchOne(db)
}
@@ -999,7 +999,7 @@ extension Table where RowDecoder == Row {
///
/// - parameter db: A database connection.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchSet(_ db: Database) throws -> Set<Row> {
@Sendable public func fetchSet(_ db: Database) throws -> Set<Row> {
try all().fetchSet(db)
}
}
@@ -1034,7 +1034,7 @@ extension Table where RowDecoder: DatabaseValueConvertible {
/// - parameter db: A database connection.
/// - returns: An array of values.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
@Sendable public func fetchAll(_ db: Database) throws -> [RowDecoder] {
try all().fetchAll(db)
}
@@ -1048,7 +1048,7 @@ extension Table where RowDecoder: DatabaseValueConvertible {
/// - parameter db: A database connection.
/// - returns: An optional value.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchOne(_ db: Database) throws -> RowDecoder? {
@Sendable public func fetchOne(_ db: Database) throws -> RowDecoder? {
try all().fetchOne(db)
}
}
@@ -1061,7 +1061,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & Hashable {
/// - parameter db: A database connection.
/// - returns: A set of values.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
@Sendable public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
try all().fetchSet(db)
}
}
@@ -1096,7 +1096,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
/// - parameter db: A database connection.
/// - returns: An array of values.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
@Sendable public func fetchAll(_ db: Database) throws -> [RowDecoder] {
try all().fetchAll(db)
}
@@ -1110,7 +1110,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
/// - parameter db: A database connection.
/// - returns: An optional value.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchOne(_ db: Database) throws -> RowDecoder? {
@Sendable public func fetchOne(_ db: Database) throws -> RowDecoder? {
try all().fetchOne(db)
}
}
@@ -1123,7 +1123,7 @@ extension Table where RowDecoder: DatabaseValueConvertible & StatementColumnConv
/// - parameter db: A database connection.
/// - returns: A set of values.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
@Sendable public func fetchSet(_ db: Database) throws -> Set<RowDecoder> {
try all().fetchSet(db)
}
}
@@ -1297,7 +1297,7 @@ extension Table {
/// - returns: An association to the common table expression.
public func association<Destination>(
to cte: CommonTableExpression<Destination>,
on condition: @escaping (_ left: TableAlias, _ right: TableAlias) -> any SQLExpressible)
on condition: @escaping @Sendable (_ left: TableAlias, _ right: TableAlias) -> any SQLExpressible)
-> JoinAssociation<RowDecoder, Destination>
{
JoinAssociation(