Refactor entire codebase and rewrite documentation
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
import Foundation
|
||||
|
||||
public extension SQLiteRawBindable where Self: BinaryFloatingPoint {
|
||||
/// Provides the `SQLiteRawValue` representation for floating-point types.
|
||||
public extension SQLiteBindable where Self: BinaryFloatingPoint {
|
||||
/// Converts a floating-point value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the floating-point value to a `real` SQLite raw value.
|
||||
/// Floating-point numbers are stored in SQLite as `REAL` values. This property wraps the
|
||||
/// current value into an ``SQLiteValue/real(_:)`` case, suitable for parameter binding.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.real`, containing the floating-point value.
|
||||
var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.real` containing the numeric value.
|
||||
var sqliteValue: SQLiteValue {
|
||||
.real(.init(self))
|
||||
}
|
||||
}
|
||||
|
||||
public extension SQLiteRawRepresentable where Self: BinaryFloatingPoint {
|
||||
/// Initializes an instance of the conforming type from an `SQLiteRawValue`.
|
||||
public extension SQLiteRepresentable where Self: BinaryFloatingPoint {
|
||||
/// Creates a floating-point value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.real`, converting it to the floating-point value.
|
||||
/// It also handles `SQLiteRawValue` of type `.int`, converting it to the floating-point value.
|
||||
/// This initializer supports both ``SQLiteValue/real(_:)`` and ``SQLiteValue/int(_:)`` cases,
|
||||
/// converting the stored number to the corresponding floating-point type.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A new instance if the conversion succeeds, or `nil` if the value is incompatible.
|
||||
init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .int(let value):
|
||||
self.init(Double(value))
|
||||
case .real(let value):
|
||||
@@ -30,5 +32,5 @@ public extension SQLiteRawRepresentable where Self: BinaryFloatingPoint {
|
||||
}
|
||||
}
|
||||
|
||||
extension Float: SQLiteRawRepresentable {}
|
||||
extension Double: SQLiteRawRepresentable {}
|
||||
extension Float: SQLiteRepresentable {}
|
||||
extension Double: SQLiteRepresentable {}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
import Foundation
|
||||
|
||||
public extension SQLiteRawBindable where Self: BinaryInteger {
|
||||
/// Provides the `SQLiteRawValue` representation for integer types.
|
||||
public extension SQLiteBindable where Self: BinaryInteger {
|
||||
/// Converts an integer value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the integer value to an `SQLiteRawValue` of type `.int`.
|
||||
/// Integer values are stored in SQLite as `INTEGER` values. This property wraps the current
|
||||
/// value into an ``SQLiteValue/int(_:)`` case, suitable for use in parameter binding.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.int`, containing the integer value.
|
||||
var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.int` containing the integer value.
|
||||
var sqliteValue: SQLiteValue {
|
||||
.int(Int64(self))
|
||||
}
|
||||
}
|
||||
|
||||
public extension SQLiteRawRepresentable where Self: BinaryInteger {
|
||||
/// Initializes an instance of the conforming type from an `SQLiteRawValue`.
|
||||
public extension SQLiteRepresentable where Self: BinaryInteger {
|
||||
/// Creates an integer value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.int`, converting it to the integer value.
|
||||
/// It uses the `init(exactly:)` initializer to ensure that the value fits within the range of the
|
||||
/// integer type. If the value cannot be exactly represented by the integer type, the initializer
|
||||
/// will return `nil`.
|
||||
/// This initializer supports the ``SQLiteValue/int(_:)`` case and uses `init(exactly:)` to
|
||||
/// ensure that the value fits within the bounds of the integer type. If the value cannot be
|
||||
/// exactly represented, the initializer returns `nil`.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A new instance if the conversion succeeds, or `nil` otherwise.
|
||||
init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .int(let value):
|
||||
self.init(exactly: value)
|
||||
default:
|
||||
@@ -30,14 +31,14 @@ public extension SQLiteRawRepresentable where Self: BinaryInteger {
|
||||
}
|
||||
}
|
||||
|
||||
extension Int: SQLiteRawRepresentable {}
|
||||
extension Int8: SQLiteRawRepresentable {}
|
||||
extension Int16: SQLiteRawRepresentable {}
|
||||
extension Int32: SQLiteRawRepresentable {}
|
||||
extension Int64: SQLiteRawRepresentable {}
|
||||
extension Int: SQLiteRepresentable {}
|
||||
extension Int8: SQLiteRepresentable {}
|
||||
extension Int16: SQLiteRepresentable {}
|
||||
extension Int32: SQLiteRepresentable {}
|
||||
extension Int64: SQLiteRepresentable {}
|
||||
|
||||
extension UInt: SQLiteRawRepresentable {}
|
||||
extension UInt8: SQLiteRawRepresentable {}
|
||||
extension UInt16: SQLiteRawRepresentable {}
|
||||
extension UInt32: SQLiteRawRepresentable {}
|
||||
extension UInt64: SQLiteRawRepresentable {}
|
||||
extension UInt: SQLiteRepresentable {}
|
||||
extension UInt8: SQLiteRepresentable {}
|
||||
extension UInt16: SQLiteRepresentable {}
|
||||
extension UInt32: SQLiteRepresentable {}
|
||||
extension UInt64: SQLiteRepresentable {}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
import Foundation
|
||||
|
||||
extension Bool: SQLiteRawRepresentable {
|
||||
/// Provides the `SQLiteRawValue` representation for boolean types.
|
||||
extension Bool: SQLiteRepresentable {
|
||||
/// Converts a Boolean value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the boolean value to an `SQLiteRawValue` of type `.int`.
|
||||
/// - `true` is represented as `1`.
|
||||
/// - `false` is represented as `0`.
|
||||
/// Boolean values are stored in SQLite as integers (`INTEGER` type). The value `true` is
|
||||
/// represented as `1`, and `false` as `0`.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.int`, containing `1` for `true` and `0` for `false`.
|
||||
public var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.int`, containing `1` for `true`
|
||||
/// and `0` for `false`.
|
||||
public var sqliteValue: SQLiteValue {
|
||||
.int(self ? 1 : 0)
|
||||
}
|
||||
|
||||
/// Initializes an instance of the conforming type from an `SQLiteRawValue`.
|
||||
/// Creates a Boolean value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.int`, converting it to a boolean value.
|
||||
/// - `1` is converted to `true`.
|
||||
/// - `0` is converted to `false`.
|
||||
/// This initializer supports the ``SQLiteValue/int(_:)`` case and converts the integer value to
|
||||
/// a Boolean. `1` is interpreted as `true`, `0` as `false`. If the integer is not `0` or `1`,
|
||||
/// the initializer returns `nil`.
|
||||
///
|
||||
/// If the integer value is not `0` or `1`, the initializer returns `nil`.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
public init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A Boolean value if the conversion succeeds, or `nil` otherwise.
|
||||
public init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .int(let value) where value == 0 || value == 1:
|
||||
self = value == 1
|
||||
default:
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
import Foundation
|
||||
|
||||
extension Data: SQLiteRawRepresentable {
|
||||
/// Provides the `SQLiteRawValue` representation for `Data` types.
|
||||
extension Data: SQLiteRepresentable {
|
||||
/// Converts a `Data` value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the `Data` value to an `SQLiteRawValue` of type `.blob`.
|
||||
/// Binary data is stored in SQLite as a BLOB (`BLOB` type). This property wraps the current
|
||||
/// value into an ``SQLiteValue/blob(_:)`` case, suitable for parameter binding.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.blob`, containing the data.
|
||||
public var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.blob` containing the binary data.
|
||||
public var sqliteValue: SQLiteValue {
|
||||
.blob(self)
|
||||
}
|
||||
|
||||
/// Initializes an instance of the conforming type from an `SQLiteRawValue`.
|
||||
/// Creates a `Data` value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.blob`, converting it to `Data`.
|
||||
/// This initializer supports the ``SQLiteValue/blob(_:)`` case and converts the binary content
|
||||
/// to a `Data` instance.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
public init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A `Data` instance if the conversion succeeds, or `nil` otherwise.
|
||||
public init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .blob(let data):
|
||||
self = data
|
||||
default:
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
import Foundation
|
||||
|
||||
extension Date: SQLiteRawRepresentable {
|
||||
/// Provides the `SQLiteRawValue` representation for `Date` types.
|
||||
extension Date: SQLiteRepresentable {
|
||||
/// Converts a `Date` value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the `Date` value to an `SQLiteRawValue` of type `.text`.
|
||||
/// The date is formatted as an ISO 8601 string.
|
||||
/// Dates are stored in SQLite as text using the ISO 8601 format. This property converts the
|
||||
/// current date into an ISO 8601 string and wraps it in an ``SQLiteValue/text(_:)`` case,
|
||||
/// suitable for parameter binding.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.text`, containing the ISO 8601 string representation of the date.
|
||||
public var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.text`, containing the ISO 8601 string.
|
||||
public var sqliteValue: SQLiteValue {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
let dateString = formatter.string(from: self)
|
||||
return .text(dateString)
|
||||
}
|
||||
|
||||
/// Initializes an instance of `Date` from an `SQLiteRawValue`.
|
||||
/// Creates a `Date` value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.text`, converting it from an ISO 8601 string.
|
||||
/// It also supports `.int` and `.real` types representing time intervals since 1970.
|
||||
/// This initializer supports the following ``SQLiteValue`` cases:
|
||||
/// - ``SQLiteValue/text(_:)`` — parses an ISO 8601 date string.
|
||||
/// - ``SQLiteValue/int(_:)`` or ``SQLiteValue/real(_:)`` — interprets the number as a time
|
||||
/// interval since 1970 (UNIX timestamp).
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
public init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A `Date` instance if the conversion succeeds, or `nil` otherwise.
|
||||
public init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .int(let value):
|
||||
self.init(timeIntervalSince1970: TimeInterval(value))
|
||||
case .real(let value):
|
||||
self.init(timeIntervalSince1970: value)
|
||||
case .text(let value):
|
||||
let formatter = ISO8601DateFormatter()
|
||||
if let date = formatter.date(from: value) {
|
||||
self = date
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
guard let date = formatter.date(from: value) else { return nil }
|
||||
self = date
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import Foundation
|
||||
|
||||
public extension SQLiteRawBindable where Self: RawRepresentable, RawValue: SQLiteRawBindable {
|
||||
/// Provides the `SQLiteRawValue` representation for `RawRepresentable` types.
|
||||
public extension SQLiteBindable where Self: RawRepresentable, RawValue: SQLiteBindable {
|
||||
/// Converts a `RawRepresentable` value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the `RawRepresentable` type's `rawValue` to its corresponding
|
||||
/// `SQLiteRawValue` representation. The `rawValue` itself must conform to `SQLiteRawBindable`.
|
||||
/// The `rawValue` of the conforming type must itself conform to ``SQLiteBindable``. This
|
||||
/// property delegates the conversion to the underlying ``rawValue``.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` representation of the `RawRepresentable` type.
|
||||
var sqliteRawValue: SQLiteRawValue {
|
||||
rawValue.sqliteRawValue
|
||||
/// - Returns: The ``SQLiteValue`` representation of the underlying ``rawValue``.
|
||||
var sqliteValue: SQLiteValue {
|
||||
rawValue.sqliteValue
|
||||
}
|
||||
}
|
||||
|
||||
public extension SQLiteRawRepresentable where Self: RawRepresentable, RawValue: SQLiteRawRepresentable {
|
||||
/// Initializes an instance of the conforming type from an `SQLiteRawValue`.
|
||||
public extension SQLiteRepresentable where Self: RawRepresentable, RawValue: SQLiteRepresentable {
|
||||
/// Creates a `RawRepresentable` value from an SQLite representation.
|
||||
///
|
||||
/// This initializer converts the `SQLiteRawValue` to the `RawRepresentable` type's `rawValue`.
|
||||
/// It first attempts to create a `RawValue` from the `SQLiteRawValue`, then uses that to initialize
|
||||
/// the `RawRepresentable` instance. If the `SQLiteRawValue` cannot be converted to the `RawValue`, the
|
||||
/// initializer returns `nil`.
|
||||
/// This initializer first attempts to create the underlying ``RawValue`` from the provided
|
||||
/// ``SQLiteValue``. If successful, it uses that raw value to initialize the `RawRepresentable`
|
||||
/// type. If the conversion fails, the initializer returns `nil`.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
if let value = RawValue(sqliteRawValue) {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A new instance if the conversion succeeds, or `nil` otherwise.
|
||||
init?(_ value: SQLiteValue) {
|
||||
if let value = RawValue(value) {
|
||||
self.init(rawValue: value)
|
||||
} else {
|
||||
return nil
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
import Foundation
|
||||
|
||||
extension String: SQLiteRawRepresentable {
|
||||
/// Provides the `SQLiteRawValue` representation for `String` type.
|
||||
extension String: SQLiteRepresentable {
|
||||
/// Converts a `String` value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the `String` value to an `SQLiteRawValue` of type `.text`.
|
||||
/// Strings are stored in SQLite as text (`TEXT` type). This property wraps the current value
|
||||
/// into an ``SQLiteValue/text(_:)`` case, suitable for parameter binding.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.text`, containing the string value.
|
||||
public var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.text` containing the string value.
|
||||
public var sqliteValue: SQLiteValue {
|
||||
.text(self)
|
||||
}
|
||||
|
||||
/// Initializes an instance of `String` from an `SQLiteRawValue`.
|
||||
/// Creates a `String` value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.text`, converting it to a `String` value.
|
||||
/// This initializer supports the ``SQLiteValue/text(_:)`` case and converts the text content
|
||||
/// to a `String` instance.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
public init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A `String` instance if the conversion succeeds, or `nil` otherwise.
|
||||
public init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .text(let value):
|
||||
self = value
|
||||
default:
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import Foundation
|
||||
|
||||
extension UUID: SQLiteRawRepresentable {
|
||||
/// Provides the `SQLiteRawValue` representation for `UUID`.
|
||||
extension UUID: SQLiteRepresentable {
|
||||
/// Converts a `UUID` value to its SQLite representation.
|
||||
///
|
||||
/// This implementation converts the `UUID` value to an `SQLiteRawValue` of type `.text`.
|
||||
/// UUIDs are stored in SQLite as text (`TEXT` type) using their canonical string form
|
||||
/// (e.g. `"550E8400-E29B-41D4-A716-446655440000"`). This property wraps the current value into
|
||||
/// an ``SQLiteValue/text(_:)`` case.
|
||||
///
|
||||
/// - Returns: An `SQLiteRawValue` of type `.text`, containing the UUID string.
|
||||
public var sqliteRawValue: SQLiteRawValue {
|
||||
/// - Returns: An ``SQLiteValue`` of type `.text` containing the UUID string.
|
||||
public var sqliteValue: SQLiteValue {
|
||||
.text(self.uuidString)
|
||||
}
|
||||
|
||||
/// Initializes an instance of `UUID` from an `SQLiteRawValue`.
|
||||
/// Creates a `UUID` value from an SQLite representation.
|
||||
///
|
||||
/// This initializer handles `SQLiteRawValue` of type `.text`, converting it to a `UUID`.
|
||||
/// This initializer supports the ``SQLiteValue/text(_:)`` case and attempts to parse the stored
|
||||
/// text as a valid UUID string.
|
||||
///
|
||||
/// - Parameter sqliteRawValue: The raw SQLite value used to initialize the instance.
|
||||
public init?(_ sqliteRawValue: SQLiteRawValue) {
|
||||
switch sqliteRawValue {
|
||||
/// - Parameter value: The SQLite value to convert from.
|
||||
/// - Returns: A `UUID` instance if the string is valid, or `nil` otherwise.
|
||||
public init?(_ value: SQLiteValue) {
|
||||
switch value {
|
||||
case .text(let value):
|
||||
self.init(uuidString: value)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user