Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesCore/QueryBindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions Sources/StructuredQueriesCore/QueryBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -65,6 +68,8 @@ extension QueryBinding: CustomDebugStringConvertible {
return uuid.uuidString.lowercased().quoted(.text)
case .invalid(let error):
return "<invalid: \(error.underlyingError.localizedDescription)>"
case .bool(let bool):
return bool ? "1" : "0"
Comment on lines +71 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the minor nit, but we like to alphabetize for the most part (invalid is an outlier which is why it comes last).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that and originally put it there, too. Was thinking it might signal 'this is not an sql type' to put it at the bottom.

}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension Date {
package var iso8601String: String {
public var iso8601String: String {
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
return formatted(.iso8601.currentTimestamp(includingFractionalSeconds: true))
} else {
Expand Down
2 changes: 2 additions & 0 deletions Sources/StructuredQueriesCore/Triggers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ public struct TemporaryTrigger<On: Table>: 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):
Expand Down
2 changes: 2 additions & 0 deletions Sources/StructuredQueriesSQLite/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesSupport/Quoting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public enum QuoteDelimiter: String {
}

extension StringProtocol {
package func quoted(_ delimiter: QuoteDelimiter = .identifier) -> String {
public func quoted(_ delimiter: QuoteDelimiter = .identifier) -> String {
let delimiter = delimiter.rawValue
return delimiter + replacingOccurrences(of: delimiter, with: delimiter + delimiter) + delimiter
}
Expand Down