DatabaseValue

public struct DatabaseValue : Hashable, CustomStringConvertible, DatabaseValueConvertible, SQLExpression

DatabaseValue is the intermediate type between SQLite and your values.

See https://www.sqlite.org/datatype3.html

  • Returns true if databaseValue is NULL.

    Declaration

    Swift

    public var isNull: Bool { get }
  • Returns whether two DatabaseValues are equal.

    1.databaseValue == "foo".databaseValue // false
    1.databaseValue == 1.databaseValue     // true
    

    When comparing integers and doubles, the result is true if and only values are equal, and if converting one type to the other does not lose information:

    1.databaseValue == 1.0.databaseValue   // true
    

    For a comparison that distinguishes integer and doubles, compare storages instead:

    1.databaseValue.storage == 1.0.databaseValue.storage // false
    

    Declaration

    Swift

    public static func == (lhs: DatabaseValue, rhs: DatabaseValue) -> Bool
  • Converts the database value to the type T.

    let dbValue = "foo".databaseValue
    let string = dbValue.losslessConvert() as String // "foo"
    

    Conversion is successful if and only if T.fromDatabaseValue returns a non-nil value.

    This method crashes with a fatal error when conversion fails.

    let dbValue = "foo".databaseValue
    let int = dbValue.losslessConvert() as Int // fatalError
    

    Declaration

    Swift

    public func losslessConvert<T>(sql: String? = nil, arguments: StatementArguments? = nil) -> T where T : DatabaseValueConvertible

    Parameters

    sql

    Optional SQL statement that enhances the eventual conversion error

    arguments

    Optional statement arguments that enhances the eventual conversion error

  • Converts the database value to the type Optional.

    let dbValue = "foo".databaseValue
    let string = dbValue.losslessConvert() as String? // "foo"
    let null = DatabaseValue.null.losslessConvert() as String? // nil
    

    Conversion is successful if and only if T.fromDatabaseValue returns a non-nil value.

    This method crashes with a fatal error when conversion fails.

    let dbValue = "foo".databaseValue
    let int = dbValue.losslessConvert() as Int? // fatalError
    

    Declaration

    Swift

    public func losslessConvert<T>(sql: String? = nil, arguments: StatementArguments? = nil) -> T? where T : DatabaseValueConvertible

    Parameters

    sql

    Optional SQL statement that enhances the eventual conversion error

    arguments

    Optional statement arguments that enhances the eventual conversion error