DatabaseFunction

public final class DatabaseFunction

An SQL function.

  • Undocumented

    Declaration

    Swift

    public final class DatabaseFunction
  • Returns an SQL function.

    let fn = DatabaseFunction("succ", argumentCount: 1) { databaseValues in
        let dbv = databaseValues.first!
        guard let int = dbv.value() as Int? else {
            return nil
        }
        return int + 1
    }
    db.add(function: fn)
    try Int.fetchOne(db, "SELECT succ(1)")! // 2
    

    Declaration

    Swift

    public init(_ name: String, argumentCount: Int32? = nil, pure: Bool = false, function: @escaping ([DatabaseValue]) throws -> DatabaseValueConvertible?)

    Parameters

    name

    The function name.

    argumentCount

    The number of arguments of the function. If omitted, or nil, the function accepts any number of arguments.

    pure

    Whether the function is “pure”, which means that its results only depends on its inputs. When a function is pure, SQLite has the opportunity to perform additional optimizations. Default value is false.

    function

    A function that takes an array of DatabaseValue arguments, and returns an optional DatabaseValueConvertible such as Int, String, NSDate, etc. The array is guaranteed to have exactly elements, provided is not nil.

  • The hash value.

    Declaration

    Swift

    public var hashValue: Int
  • Two functions are equal if they share the same name and argumentCount.

    Declaration

    Swift

    public static func ==(lhs: DatabaseFunction, rhs: DatabaseFunction) -> Bool
  • An SQL function that returns the Swift built-in capitalized String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s capitalized:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.capitalized)
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let capitalize = DatabaseFunction("swiftCapitalizedString", argumentCount: 1, pure: true) { databaseValues in
  • An SQL function that returns the Swift built-in lowercased String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s lowercased:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.lowercased())
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let lowercase = DatabaseFunction("swiftLowercaseString", argumentCount: 1, pure: true) { databaseValues in
  • An SQL function that returns the Swift built-in uppercased String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s uppercased:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.uppercased())
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let uppercase = DatabaseFunction("swiftUppercaseString", argumentCount: 1, pure: true) { databaseValues in
  • An SQL function that returns the Swift built-in localizedCapitalized String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s localizedCapitalized:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.localizedCapitalized)
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let localizedCapitalize = DatabaseFunction("swiftLocalizedCapitalizedString", argumentCount: 1, pure: true) { databaseValues in
  • An SQL function that returns the Swift built-in localizedLowercased String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s localizedLowercased:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.localizedLowercased)
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let localizedLowercase = DatabaseFunction("swiftLocalizedLowercaseString", argumentCount: 1, pure: true) { databaseValues in
  • An SQL function that returns the Swift built-in localizedUppercased String property.

    The function returns NULL for non-strings values.

    This function is automatically added by GRDB to your database connections. It is the function used by the query interface’s localizedUppercased:

    let nameColumn = Column("name")
    let request = Person.select(nameColumn.localizedUppercased)
    let names = try String.fetchAll(dbQueue, request)   // [String]
    

    Declaration

    Swift

    public static let localizedUppercase = DatabaseFunction("swiftLocalizedUppercaseString", argumentCount: 1, pure: true) { databaseValues in