OxL Reference

data Query

A query being built from from x in db.T … (the compiler's lowering target; see checkTableQuery).

Example:

oxl✓ checked in CI
use std.orm { Db }

@table("items")
data Item {
  @pk id: i64
  name: str
  price: i64
}

fn main() io, db {
  let db = Db.open("sqlite::memory:")!
  db.insert(Item{ id: 1, name: "tea", price: 3 })
  db.insert(Item{ id: 2, name: "cake", price: 9 })
  let cheap = db.Item.query().sqlWhere("price < 5").run()
  print("{cheap.len()} {cheap[0].name}")
  db.close()
}
Output
1 tea
pub(api) data Query<T>

Since. 1.0.0-beta

Methods

sqlWhere(sql: str) -> Query<T>
Adds a raw SQL condition (use bind for values).
sqlOrder(sql: str) -> Query<T>
Adds a raw SQL ORDER BY expression.
load(field: str) -> Query<T>
load(field) of a query
bind(v: P) -> Query<T>
Binds the next ?
skip(n: N) -> Query<T>
Skips the first n rows (any integer type; a negative count is 0).
take(n: N) -> Query<T>
Returns at most n rows (any integer type).
run() -> List<T> db
Executes the query; panics on a database failure.
count() -> i64 db
Number of matching rows, ignoring skip and take.

Defined in: std/orm/orm.oxl:740

See also