summaryrefslogtreecommitdiffstats
path: root/docs/queries.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/queries.md')
-rw-r--r--docs/queries.md104
1 files changed, 104 insertions, 0 deletions
diff --git a/docs/queries.md b/docs/queries.md
new file mode 100644
index 0000000..8676392
--- /dev/null
+++ b/docs/queries.md
@@ -0,0 +1,104 @@
1## Query System
2The query system should allow for efficient retrieval for just the amount of data required by the client. Efficient querying is supported by the indexes provided by the resources.
3
4The query always retrieves a set of entities matching the query, while not necessarily all properties of the entity need to be populated.
5
6Queries are declarative to keep the specification simple and to allow the implementation to choose the most efficient execution.
7
8Queries can be kept open (live) to receive updates as the store changes.
9
10### Query
11The query consists of:
12
13* a set of filters to match the wanted entities
14* the set of properties to retrieve for each entity
15
16Queryable properties are defined by the [[Domain Types]] above.
17
18### Query Result
19The result is returned directly after running the query in form of a QAbstractItemModel. Each row in the model represents a matching entity.
20
21The model allows to access the domain object directly, or to access individual properties directly via the rows columns.
22
23The model is always populated asynchronously. It is therefore initially empty and will then populate itself gradually, through the regular update mechanisms (rowsInserted).
24
25Tree Queries allow the application to query for i.e. a folder hierarchy in a single query. This is necessary for performance reasons to avoid recursive querying in large hierarchies. To avoid on the other hand loading large hierchies directly into memory, the model only populates the toplevel rows automatically, all other rows need to be populated by calling `QAbstractItemModel::fetchMore(QModelIndex);`. This way the resource can deal efficiently with the query (i.e. by avoiding the many roundtrips that would be necessary with recursive queries), while keeping the amount of data in memory to a minimum (i.e. if the majority of the folder tree is collapsed in the view anyways). A tree result set can therefore be seen as a set of sets, where every subset corresponds to the children of one parent.
26
27If the query is live, the model updates itself if the update applies to one of the already loaded subsets (otherwise it's currently irrelevant and will load once the subset is loaded).
28
29#### Enhancements
30* Asynchronous loading of entities/properties can be achieved by returning an invalid QVariant initially, and emitting dataChanged once the value is loaded.
31* To avoid loading a large list when not all data is necessary, a batch size could be defined to guarantee for instance that there is sufficient data to fill the screen, and the fetchMore mechanism can be used to gradually load more data as required when scrolling in the application.
32
33#### Filter
34A filter consists of:
35
36* a property to filter on as defined by the [[Domain Types]]
37* a comparator to use
38* a value
39
40The available comparators are:
41
42* equal
43* greater than
44* less than
45* inclusive range
46
47Value types include:
48
49* Null
50* Bool
51* Regular Expression
52* Substring
53* A type-specific literal value (e.g. string, number, date, ..)
54
55Filters can be combined using AND, OR, NOT.
56
57#### Example
58```
59query = {
60 offset: int
61 limit: int
62 filter = {
63 and {
64 collection = foo
65 or {
66 resource = res1
67 resource = res2
68 }
69 }
70 }
71}
72```
73
74possible API:
75
76```
77query.filter().and().property("collection") = "foo"
78query.filter().and().or().property("resource") = "res1"
79query.filter().and().or().property("resource") = "res2"
80query.filter().and().property("start-date") = InclusiveRange(QDateTime, QDateTime)
81```
82
83The problem is that it is difficult to adjust an individual resource property like that.
84
85### Usecases ###
86Mail:
87
88* All mails in folder X within date-range Y that are unread.
89* All mails (in all folders) that contain the string X in property Y.
90
91Todos:
92
93* Give me all the todos in that collection where their RELATED-TO field maps to no other todo UID field in the collection
94* Give me all the todos in that collection where their RELATED-TO field has a given value
95* Give me all the collections which have a given collection as parent and which have a descendant matching a criteria on its attributes;
96
97Events:
98
99* All events of calendar X within date-range Y.
100
101Generic:
102* entity with identifier X
103* all entities of resource X
104