kw where
Contextual keyword — generic constraints, refinements, the for filter, queries
The list of words: §1.4
Syntax
Where = "where" WClause { "," WClause } ;TypeAlias = "type" Ident [ Generics ] "=" ( [ "distinct" ] Type [ "where" Expr ] ) ;For = [ Label ":" ] [ "inline" ] "for" [ "await" ] Pattern "in" Expr [ "where" Expr ] Block ;Query = "from" Pattern "in" Expr { "where" Expr } [ "order" "by" Ord { "," Ord } ]
[ "group" "by" Expr "into" Ident ] [ "skip" Expr ] [ "take" Expr ]
[ "load" "(" IdentList ")" ] [ "select" Expr ] ;Grammar: App. A
Defined in
- 5.9 Query expressions — Form: from x in source (where e)\* (order by e (asc|desc)?, …)?
- 1.4 Keywords — Reserved (cannot be used as names)
- 3.6 Aliases, new types and refined types — distinct T creates a new nominal type with the representation of T.
- 4.8 Generics — Parameters: type parameters T, constant parameters const N
- 5.6 Loops — for accepts Iterable<T> (including iter<T>, collections, ranges); for await accepts Streamable<T>.
- 6.1 Function declaration — Without -> T the return type is () (for private functions with a body => e the type is inferred from e).
- 15.2 Reflection — reflect(T) -> TypeInfo (comptime only)
Examples
let top = from o in db.Order
where o.userId == uid && o.total > MIN_TOTAL
order by o.createdAt desc
skip page * PAGE_SIZE
take PAGE_SIZE
load(items)
let names = from u in users where u.active select u.name // in-memory List
let byRole = from u in users group by u.role into g select (g.key, g.count())type Bytes2 = [u8; 2] // alias, the same type
type UserId = distinct u64 // a new type, no implicit conversions
type Port = u16 where 1..=65535 // refined type
type Name = str where len(1..=64)
type Email = str where matches(re".+@.+\..+")— 3.6 Aliases, new types and refined types
Related diagnostics
query-not-sql, refinement-violated, bound-not-satisfied, generic-args, break-value, outside-loop, arg-count, named-arg