OxL Reference

error query-not-sql

error Standard: [§5.9, §12.8]

What it means#

A query over a table (from u in db.User where … order by …) is compiled to SQL when the program is built. The expressions in where and order by MUST be translatable: fields of the row (u.email), literals, parameters (any expression that does not mention the row, evaluated by the program and bound when the query runs), arithmetic, comparisons, &&, ||, !, x in [a, b], startsWith, endsWith, contains, lower, upper, len, isEmpty and == none / != none. Calls of your own functions on the row, nested fields (nested data is stored serialized), the whole row, closures and collections cannot be expressed in SQL.

The same code also reports a query parameter whose type is not a column type (a list, a data type, …).

Example#

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

@table("users")
data User { @pk id: i64; name: str; age: u32 }

fn adult(age: u32) -> bool => age >= 18

fn grown(db: &Db) -> List<User> db {
  from u in db.User where adult(u.age)      // <- query-not-sql
}
error
query-not-sql

How to fix#

Write the condition with translatable operators, or load the rows and filter them in memory (db.all(User) and the list methods).

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

@table("users")
data User { @pk id: i64; name: str; age: u32 }

fn grown(db: &Db) -> List<User> db {
  from u in db.User where u.age >= 18
}

See also#

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides