Skip to content

Arguments

Bind Args

.sq files use the exact same syntax as H2, including bound arguments. If a statement contains bind args, the associated method will require corresponding arguments.

Type Inference

SQLDelight will infer the correct type and nullability of runtime parameters, including custom column types.

selectByNumber:
SELECT *
FROM hockeyPlayer
WHERE player_number = ?;
val selectNumber10 = playerQueries.selectByNumber(player_number = 10)
println(selectNumber10.executeAsOne())
// Prints "Corey Perry"

Named Arguments

Named parameters or indexed parameters can be used.

firstOrLastName:
SELECT *
FROM hockeyPlayer
WHERE full_name LIKE ('% ' || :name)
OR full_name LIKE (:name || ' %');
playerQueries.firstOrLastName(name = "Ryan")

Variable Arguments

Sets of values can also be passed as an argument.

selectByNames:
SELECT *
FROM hockeyPlayer
WHERE full_name IN ?;
playerQueries.selectByNames(listOf("Alec", "Jake", "Matt"))

Inserts

INSERT VALUES arguments can be bound to with the table's data class.

insertPlayer:
INSERT INTO hockeyPlayer
VALUES ?;
val rickardRakell = HockeyPlayer(
  full_name = "Rickard Rakell",
  number = 67
)
playerQueries.insertPlayer(rickardRakell)

Input Sanitization

SQLDelight uses query placeholders to pass arguments into queries. The actual sanitization of argument inputs is done by the underlying driver implementation on each respective platform and dialect.