diff --git a/Sources/StructuredQueriesCore/QueryBindable.swift b/Sources/StructuredQueriesCore/QueryBindable.swift index 863e7594..761ff305 100644 --- a/Sources/StructuredQueriesCore/QueryBindable.swift +++ b/Sources/StructuredQueriesCore/QueryBindable.swift @@ -20,7 +20,7 @@ extension [UInt8]: QueryBindable, QueryExpression { } extension Bool: QueryBindable { - public var queryBinding: QueryBinding { .int(self ? 1 : 0) } + public var queryBinding: QueryBinding { .bool(self) } } extension Double: QueryBindable { diff --git a/Sources/StructuredQueriesCore/QueryBinding.swift b/Sources/StructuredQueriesCore/QueryBinding.swift index cfd2befd..f6df0af6 100644 --- a/Sources/StructuredQueriesCore/QueryBinding.swift +++ b/Sources/StructuredQueriesCore/QueryBinding.swift @@ -5,6 +5,9 @@ public enum QueryBinding: Hashable, Sendable { /// A value that should be bound to a statement as bytes. case blob([UInt8]) + /// A value that should be bound to a statement as a boolean. + case bool(Bool) + /// A value that should be bound to a statement as a double. case double(Double) @@ -65,6 +68,8 @@ extension QueryBinding: CustomDebugStringConvertible { return uuid.uuidString.lowercased().quoted(.text) case .invalid(let error): return "" + case .bool(let bool): + return bool ? "1" : "0" } } } diff --git a/Sources/StructuredQueriesCore/Triggers.swift b/Sources/StructuredQueriesCore/Triggers.swift index 9fc539c0..37de86ef 100644 --- a/Sources/StructuredQueriesCore/Triggers.swift +++ b/Sources/StructuredQueriesCore/Triggers.swift @@ -436,6 +436,8 @@ public struct TemporaryTrigger: Sendable, Statement { $0.append(hex) } $0.append("unhex(\(quote: hex, delimiter: .text))") + case .bool(let bool): + $0.append(bool ? "1" : "0") case .double(let double): $0.append("\(raw: double)") case .date(let date): diff --git a/Sources/StructuredQueriesSQLite/Database.swift b/Sources/StructuredQueriesSQLite/Database.swift index e3dced2c..53c04534 100644 --- a/Sources/StructuredQueriesSQLite/Database.swift +++ b/Sources/StructuredQueriesSQLite/Database.swift @@ -138,6 +138,8 @@ public struct Database { switch binding { case .blob(let blob): sqlite3_bind_blob(statement, index, Array(blob), Int32(blob.count), SQLITE_TRANSIENT) + case .bool(let bool): + sqlite3_bind_int64(statement, index, bool ? 1 : 0) case .date(let date): sqlite3_bind_text(statement, index, date.iso8601String, -1, SQLITE_TRANSIENT) case .double(let double):