queryModule:
module query
// Types
type ast = data
def cmp : string -> string -> data -> ast
def cmpExpr : string -> ast -> data -> ast
def eq : string -> data -> ast
def neq : string -> data -> ast
def lt : string -> data -> ast
def gt : string -> data -> ast
def le : string -> data -> ast
def ge : string -> data -> ast
def contains : string -> data -> ast
def like : string -> data -> ast
def featuresOne : string -> data -> ast
def featuresAll : string -> data -> ast
def nullFilter : ast
def token : string -> ast
def exists : string -> ast
def afterWatermark : string -> ast
def afterRow : number -> ast
def not_ : ast -> ast
def and : data -> ast // array(ast) -> ast
def or : data -> ast // array(ast) -> ast
def invoke : string -> data -> ast // string -> array(ast) -> ast
def object : data -> ast // array(ast) -> ast
def cloneMembers : ast
def cloneMembersWithExpansion : ast
def assignMember : string -> ast -> ast
def removeMember : string -> ast
def objectMember : ast -> string -> ast
def followRef : ast -> ast
def scalarFallback : data -> ast
def scalarIndexed : data -> ast
def listFallback : data -> ast
def listIndexed : data -> ast
def count : ast
def group : string -> ast
def filterOfMap : data -> ast
def filterOfMapFallback : data -> ast
def projectionOfMap : data -> ast // object -> ast
module end
type ast = data
The type ast represents the abstract syntax tree defining our query and projection language. Currently these queries can be applied to the database but soon they will be applicable to plain data as well.
An example:
> db.head() |> db.processPipeline([q.eq("foo", "bar"), q.count])
| .:1:1 (to 1:63): $value : db.query
$value = { data: [ [ "comparison", "==", [ "token", "foo" ], "bar" ], [ "invoke", [ "token", "count" ] ] ], db: "main", includeDeleted: false, includeSuperseded: false, label: "", post: [ ], postFilter: [ ], type: "rmx", unrestricted: false }
ASTs are represented as JSON data in an implementation-defined way. There are a number of helper functions in this module that create ASTs in the right format.
See Query syntax
cmp(op, field, value): compares the field of the current record with value. Comparisons: ==, !=, like (prefix), contains. The value can be a string, a boolean, or null. Helpers for specific operators also exist, eg, eq and neq.cmpExpr(op, fieldExpr, value): same, but arbitrary ast expression is accepted for the fieldexists(field): tests whether the current record has a field fieldafterWatermark(watermark): tests whether the current record is after watermark (an _rmx_rev value)afterRow(row): tests whether the current record is after the row rowfeaturesOne(field, list): whether field is a scalar and an element of list, or a list and has a non-empty intersection with list. list should be an AST element constructed via listIndexed or listFallback.featuresAll(field, list): whether field is a list and contains all elements of list (if list only has one element, a scalar field can match, too). list should be an AST element constructed via listIndexed or listFallback.not_(ast): negates the condition expressed by ast