Functions

The following functions are available globally.

  • Returns an array of row adapters that split a row according to the input number of columns.

    For example:

    let sql = "SELECT 1, 2,3,4, 5,6, 7,8"
    //               <.><. . .><. .><. .>
    let adapters = splittingRowAdapters([1, 3, 2])
    let adapter = ScopeAdapter([
        "a": adapters[0],
        "b": adapters[1],
        "c": adapters[2],
        "d": adapters[3]])
    let row = try Row.fetchOne(db, sql: sql, adapter: adapter)
    row.scopes["a"] // [1]
    row.scopes["b"] // [2, 3, 4]
    row.scopes["c"] // [5, 6]
    row.scopes["d"] // [7, 8]
    

    Declaration

    Swift

    public func splittingRowAdapters(columnCounts: [Int]) -> [RowAdapter]

Logical Operators (AND, OR, NOT)

Egality and Identity Operators (=, <>, IS, IS NOT)

Comparison Operators (<, >, <=, >=)

Arithmetic Operators (+, -, *, /)

IFNULL(…)

ABS(…)

LENGTH(…)

ColumnAssignment

  • Creates an assignment that adds a value

    Column("score") += 1
    Column("score") += Column("bonus")
    
    try dbQueue.write { db in
        // UPDATE player SET score = score + 1
        try Player.updateAll(db, Column("score") += 1)
    }
    

    Declaration

    Swift

    public func += (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment
  • Creates an assignment that subtracts a value

    Column("score") -= 1
    Column("score") -= Column("bonus")
    
    try dbQueue.write { db in
        // UPDATE player SET score = score - 1
        try Player.updateAll(db, Column("score") -= 1)
    }
    

    Declaration

    Swift

    public func -= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment
  • Creates an assignment that multiplies by a value

    Column("score") *= 2
    Column("score") *= Column("factor")
    
    try dbQueue.write { db in
        // UPDATE player SET score = score * 2
        try Player.updateAll(db, Column("score") *= 2)
    }
    

    Declaration

    Swift

    public func *= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment
  • Creates an assignment that divides by a value

    Column("score") /= 2
    Column("score") /= Column("factor")
    
    try dbQueue.write { db in
        // UPDATE player SET score = score / 2
        try Player.updateAll(db, Column("score") /= 2)
    }
    

    Declaration

    Swift

    public func /= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment

ABS(…)

AVG(…)

COUNT(…)

COUNT(DISTINCT …)

IFNULL(…)

LENGTH(…)

MAX(…)

MIN(…)

SUM(…)

TOTAL(…)

JULIANDAY(…)

DATETIME(…)

Egality and Identity Operators (=, <>, IS, IS NOT)

Comparison Operators (<, >, <=, >=)

Arithmetic Operators (+, -, *, /)

Logical Operators (AND, OR, NOT)

Public

  • Return as many question marks separated with commas as the count argument.

    databaseQuestionMarks(count: 3) // "?,?,?"
    

    Declaration

    Swift

    public func databaseQuestionMarks(count: Int) -> String