From bfb2a08a8d464f175ed4d6906f9103c6ecfa0066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sun, 17 Nov 2024 17:28:57 +0100 Subject: [PATCH] Add a few public initializers ... --- Sources/ZeeQL/Control/Expression.swift | 30 ++++++++++++++----- Sources/ZeeQL/Control/QualifierVariable.swift | 10 +++++-- Sources/ZeeQL/Control/SQLQualifier.swift | 22 +++++++++++--- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Sources/ZeeQL/Control/Expression.swift b/Sources/ZeeQL/Control/Expression.swift index 2f1d809..56f0acf 100644 --- a/Sources/ZeeQL/Control/Expression.swift +++ b/Sources/ZeeQL/Control/Expression.swift @@ -3,17 +3,18 @@ // ZeeQL // // Created by Helge Hess on 15/02/2017. -// Copyright © 2017-2019 ZeeZide GmbH. All rights reserved. +// Copyright © 2017-2024 ZeeZide GmbH. All rights reserved. // /** - * Expressions are: - * - Qualifier - * - SortOrdering - * - Constant - * - Key + * ``Expression``'s are: + * - ``Qualifier`` + * - ``SortOrdering`` + * - ``Constant`` + * - ``Key`` */ public protocol Expression { + // TBD: Collides w/ Swift 6 `Expression` in Foundation? func addReferencedKeys(to set: inout Set) @@ -23,13 +24,21 @@ public protocol Expression { } -public struct QualifierBindingNotFound : Swift.Error { - let binding : String +public struct QualifierBindingNotFound : Swift.Error, Hashable { + public let binding : String + + @inlinable + init(binding: String) { self.binding = binding } } +#if swift(>=5.5) +extension QualifierBindingNotFound : Sendable {} +#endif + public extension Expression { + @inlinable var allReferencedKeys : [ String ] { var keys = Set() addReferencedKeys(to: &keys) @@ -39,6 +48,7 @@ public extension Expression { // MARK: - Bindings + @inlinable var bindingKeys : [ String ] { var keys = Set() addBindingKeys(to: &keys) @@ -48,9 +58,13 @@ public extension Expression { public extension Expression { // default implementations + @inlinable func addReferencedKeys(to set: inout Set) {} + @inlinable var hasUnresolvedBindings : Bool { return !bindingKeys.isEmpty } + @inlinable func addBindingKeys(to set: inout Set) { } // noop + @inlinable func keyPathForBindingKey(_ variable: String) -> String? { return nil } } diff --git a/Sources/ZeeQL/Control/QualifierVariable.swift b/Sources/ZeeQL/Control/QualifierVariable.swift index dfa8426..7fdf62c 100644 --- a/Sources/ZeeQL/Control/QualifierVariable.swift +++ b/Sources/ZeeQL/Control/QualifierVariable.swift @@ -3,13 +3,15 @@ // ZeeQL // // Created by Helge Hess on 16/02/2017. -// Copyright © 2017 ZeeZide GmbH. All rights reserved. +// Copyright © 2017-2024 ZeeZide GmbH. All rights reserved. // -public struct QualifierVariable { +public struct QualifierVariable: Hashable { public let key : String + @inlinable + public init(key: String) { self.key = key } } extension QualifierVariable : CustomStringConvertible { @@ -17,3 +19,7 @@ extension QualifierVariable : CustomStringConvertible { return "" } } + +#if swift(>=5.5) +extension QualifierVariable : Sendable {} +#endif diff --git a/Sources/ZeeQL/Control/SQLQualifier.swift b/Sources/ZeeQL/Control/SQLQualifier.swift index 6456f62..2fc9cdd 100644 --- a/Sources/ZeeQL/Control/SQLQualifier.swift +++ b/Sources/ZeeQL/Control/SQLQualifier.swift @@ -3,16 +3,19 @@ // ZeeQL // // Created by Helge Hess on 28/02/17. -// Copyright © 2017 ZeeZide GmbH. All rights reserved. +// Copyright © 2017-2024 ZeeZide GmbH. All rights reserved. // -public struct SQLQualifier : Qualifier, Equatable { +public struct SQLQualifier : Qualifier, Hashable { // TBD: maybe rename to 'RawQualifier'? - public enum Part: Equatable { + public enum Part: Hashable { + // TODO: lowercase cases for modern Swift + case RawSQLValue(String) case QualifierVariable(String) + @inlinable public static func ==(lhs: Part, rhs: Part) -> Bool { switch ( lhs, rhs ) { case ( RawSQLValue(let a), RawSQLValue(let b) ): @@ -28,12 +31,14 @@ public struct SQLQualifier : Qualifier, Equatable { public let parts : [ Part ] + @inlinable public init(parts: [ Part ]) { self.parts = parts // TODO: compact? } // MARK: - Bindings + @inlinable public func addBindingKeys(to set: inout Set) { for part in parts { if case .QualifierVariable(let key) = part { @@ -42,6 +47,7 @@ public struct SQLQualifier : Qualifier, Equatable { } } + @inlinable public var hasUnresolvedBindings : Bool { for part in parts { if case .QualifierVariable = part { return true } @@ -49,6 +55,7 @@ public struct SQLQualifier : Qualifier, Equatable { return false } + @inlinable public func qualifierWith(bindings: Any?, requiresAll: Bool) throws -> Qualifier? { @@ -74,10 +81,12 @@ public struct SQLQualifier : Qualifier, Equatable { // MARK: - Equality + @inlinable public static func ==(lhs: SQLQualifier, rhs: SQLQualifier) -> Bool { return lhs.parts == rhs.parts } - + + @inlinable public func isEqual(to object: Any?) -> Bool { guard let other = object as? SQLQualifier else { return false } return self == other @@ -104,3 +113,8 @@ public struct SQLQualifier : Qualifier, Equatable { ms += "]" } } + +#if swift(>=5.5) +extension SQLQualifier : Sendable {} +extension SQLQualifier.Part : Sendable {} +#endif