error query-not-sql
Выражение в запросе к таблице не транслируется в SQL.
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#
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
}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).
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
}