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]
-
Returns a logically negated aggregate.
For example:
Author.having(!Author.books.isEmpty) -
Groups two aggregates with the
ANDSQL operator.For example:
Author.having(Author.books.isEmpty && Author.paintings.isEmpty) -
Groups two aggregates with the
ORSQL operator.For example:
Author.having(!Author.books.isEmpty || !Author.paintings.isEmpty)
-
Returns an aggregate that compares two aggregates with the
=SQL operator.For example:
Author.having(Author.books.count == Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
<>SQL operator.For example:
Author.having(Author.books.count != Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
ISSQL operator.For example:
Author.having(Author.books.count === Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
IS NOTSQL operator.For example:
Author.having(Author.books.count !== Author.paintings.count)
-
Returns an aggregate that compares two aggregates with the
<=SQL operator.For example:
Author.having(Author.books.count <= Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
<SQL operator.For example:
Author.having(Author.books.count < Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
>SQL operator.For example:
Author.having(Author.books.count > Author.paintings.count) -
Returns an aggregate that compares two aggregates with the
>=SQL operator.For example:
Author.having(Author.books.count >= Author.paintings.count)
-
Returns an arithmetically negated aggregate.
For example:
Author.annotated(with: -Author.books.count) -
Returns an aggregate that sums two aggregates with the
+SQL operator.For example:
Author.annotated(with: Author.books.count + Author.paintings.count) -
Returns an aggregate that substracts two aggregates with the
-SQL operator.For example:
Author.annotated(with: Author.books.count - Author.paintings.count) -
Returns an aggregate that multiplies two aggregates with the
*SQL operator.For example:
Author.annotated(with: Author.books.count * Author.paintings.count) -
Returns an aggregate that multiplies two aggregates with the
/SQL operator.For example:
Author.annotated(with: Author.books.count / Author.paintings.count)
-
Returns an aggregate that evaluates the
IFNULLSQL function.Team.annotated(with: Team.players.min(Column("score")) ?? 0)
-
Returns an aggregate that evaluates to the absolute value of the input aggregate.
-
Returns an aggregate that evaluates the
LENGTHSQL function on the input aggregate.
-
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) } -
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) } -
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) } -
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) }
-
Returns an expression that evaluates the
AVGSQL function.// AVG(length) average(Column("length"))
-
Returns an expression that evaluates the
COUNTSQL function.// COUNT(email) count(Column("email"))
-
Returns an expression that evaluates the
COUNT(DISTINCT)SQL function.// COUNT(DISTINCT email) count(distinct: Column("email"))
-
Returns an expression that evaluates the
MAXSQL function.// MAX(score) max(Column("score"))
-
Returns an expression that evaluates the
MINSQL function.// MIN(score) min(Column("score"))
-
Returns an expression that evaluates the
SUMSQL function.See https://www.sqlite.org/lang_aggfunc.html#sumunc.
See also
total(_:).// SUM(amount) sum(Column("amount"))
-
Returns an expression that evaluates the
TOTALSQL function.See https://www.sqlite.org/lang_aggfunc.html#sumunc.
See also
sum(_:).// TOTAL(amount) total(Column("amount"))
-
Returns an expression that evaluates the
JULIANDAYSQL function.// JULIANDAY(date) julianDay(Column("date")) // JULIANDAY(date, '1 days') julianDay(Column("date"), .day(1))For more information, see https://www.sqlite.org/lang_datefunc.html
-
Returns an expression that evaluates the
DATETIMESQL function.// DATETIME(date) dateTime(Column("date")) // DATETIME(date, '1 days') dateTime(Column("date"), .day(1))For more information, see https://www.sqlite.org/lang_datefunc.html
-
Return as many question marks separated with commas as the count argument.
databaseQuestionMarks(count: 3) // "?,?,?"
View on GitHub
Install in Dash
Functions Reference