DatabaseCollation

public final class DatabaseCollation

A Collation is a string comparison function used by SQLite.

  • Undocumented

    Declaration

    Swift

    public let name: String
  • Creates a collation.

    let collation = DatabaseCollation("localized_standard") { (string1, string2) in
        return (string1 as NSString).localizedStandardCompare(string2)
    }
    db.add(collation: collation)
    try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE localized_standard")
    

    Declaration

    Swift

    public init(_ name: String, function: @escaping (String, String) -> ComparisonResult)

    Parameters

    name

    The function name.

    function

    A function that compares two strings.

  • A collation, or SQL string comparison function, that compares strings according to the the Swift built-in == and <= operators.

    This collation is automatically added by GRDB to your database connections.

    You can use it when creating database tables:

    let collationName = DatabaseCollation.caseInsensitiveCompare.name
    dbQueue.execute(sql: """
        CREATE TABLE players (
          name TEXT COLLATE \(collationName)
        )
        """)
    

    Declaration

    Swift

    public static let unicodeCompare: DatabaseCollation
  • A collation, or SQL string comparison function, that compares strings according to the the Swift built-in caseInsensitiveCompare(_:) method.

    This collation is automatically added by GRDB to your database connections.

    You can use it when creating database tables:

    let collationName = DatabaseCollation.caseInsensitiveCompare.name
    dbQueue.execute(sql: """
        CREATE TABLE players (
          name TEXT COLLATE \(collationName)
        )
        """)
    

    Declaration

    Swift

    public static let caseInsensitiveCompare: DatabaseCollation
  • A collation, or SQL string comparison function, that compares strings according to the the Swift built-in localizedCaseInsensitiveCompare(_:) method.

    This collation is automatically added by GRDB to your database connections.

    You can use it when creating database tables:

    let collationName = DatabaseCollation.localizedCaseInsensitiveCompare.name
    dbQueue.execute(sql: """
        CREATE TABLE players (
          name TEXT COLLATE \(collationName)
        )
        """)
    

    Declaration

    Swift

    public static let localizedCaseInsensitiveCompare: DatabaseCollation
  • A collation, or SQL string comparison function, that compares strings according to the the Swift built-in localizedCompare(_:) method.

    This collation is automatically added by GRDB to your database connections.

    You can use it when creating database tables:

    let collationName = DatabaseCollation.localizedCompare.name
    dbQueue.execute(sql: """
        CREATE TABLE players (
          name TEXT COLLATE \(collationName)
        )
        """)
    

    Declaration

    Swift

    public static let localizedCompare: DatabaseCollation
  • A collation, or SQL string comparison function, that compares strings according to the the Swift built-in localizedStandardCompare(_:) method.

    This collation is automatically added by GRDB to your database connections.

    You can use it when creating database tables:

    let collationName = DatabaseCollation.localizedStandardCompare.name
    dbQueue.execute(sql: """
        CREATE TABLE players (
          name TEXT COLLATE \(collationName)
        )
        """)
    

    Declaration

    Swift

    public static let localizedStandardCompare: DatabaseCollation