Appearance
Querying
Queries are defined using fluent api or as a string that is being parsed into a query graph.
The best way to build a graph is to use the fluent query builder, but for some simple queries the string query method works pretty well even it does not expose all features.
For example using:
Aeppic.Query.children('my-root').form('folder').where('data.name').is('a*')
which returns all children documents of form 'folder' under 'my-root' where the field 'data.name' matches the suffix wildcard query 'a*'
Alternatively, though a little slower due to the parsing overhead, one can define the same query as a [string][StringQuerySyntax].
e.g.
"p:my-root f.id:folder data.name:a*"
Both queries get processed into a parameterized query graph .
Since all documents have a specific form version associated with it and are stored in a tree of documents it is strongly recommended to limit queries to a form or limited list of forms and a sub section of a tree as in children or descendants of another document.
Queries are then passed into e.g. the Aeppic.find
function.
e.g.
const q = Aeppic.Query.global().where('data.name').is('xox')
const documents = await Aeppic.find(q)
Fluent Queries
The fluent query builder makes building queries simpler than creating the raw graph structure and makes it easier to write more complicated queries, especially as braces
The entry point to the fluent API is a QueryScopes
instance which is accessible by Aeppic.Query
.
QueryScopes exposes the following scopes that can be used
global()
children()
descendants()
In contextified Aeppic instances such as Design
controllers children
and descendants
are already preconfigured to use the document of the design as root of the query, but an alternate can be provided. To Aeppic.Query.children()
inside a design controller for example would return all children of the current document, whereas Aeppic.Query.children('apps')
could be used to get other children.
Let's use that as in the example:
Aeppic.Query.children('my-root').form('folder').where('data.name').is('a*')
The scope is usually followed by a form or multiple forms (e.g .form('folder')
or forms(['folder', 'file']
) which apply to all sub-conditions in the query.
After that the query can be built as a combination of where(fieldPath).is(value)
queries potentially separated by or
and nesting via subQuery
.