@@ -31,6 +31,7 @@ val result: List<String?> = client.getRootNode()!!.query {
31
31
== Type safe ModelQL API
32
32
33
33
You can use the `model-api-gen-gradle` plugin to generate type safe extensions from your meta-model.
34
+ Specify the `modelqlKotlinDir` property to enable the generation.
34
35
35
36
[source,kotlin]
36
37
--
@@ -45,7 +46,7 @@ val result: List<StaticMethodDeclaration> = client.query { root ->
45
46
46
47
== Run query on an INode
47
48
48
- If a query returns a node you can execute a new query starting from that node.
49
+ If a query returns a node, you can execute a new query starting from that node.
49
50
50
51
[source,kotlin]
51
52
--
@@ -55,8 +56,8 @@ val cls: ClassConcept = client.query {
55
56
val names = cls.query { it.member.ofConcept(C_StaticMethodDeclaration).name.toList() }
56
57
--
57
58
58
- Or you can just use the INode API to access further data of that node.
59
- This is not recommended though, because each access sends a new query to the server.
59
+ For convenience, it's possible to access further data of that node using the INode API,
60
+ but this is not recommended though, because each access sends a new query to the server.
60
61
61
62
[source,kotlin]
62
63
--
@@ -68,9 +69,9 @@ val className = cls.name
68
69
69
70
== Complex query results
70
71
71
- While returning a list of elements is simple
72
+ While returning a list of elements is simple,
72
73
the purpose of the query language is to reduce the number of request to a minimum.
73
- This requires to combine multiple values into more complex data structures.
74
+ This requires combining multiple values into more complex data structures.
74
75
The `zip` operation provides a simple way of doing that:
75
76
76
77
[source,kotlin]
@@ -97,7 +98,7 @@ This can be solved by defining custom data classes and using the `mapLocal` oper
97
98
data class MyProduct(val id: Int, val title: String, val images: List<MyImage>)
98
99
data class MyImage(val url: String)
99
100
100
- val result: List<MyNonSerializableClass > = remoteProductDatabaseQuery { db ->
101
+ val result: List<MyProduct > = remoteProductDatabaseQuery { db ->
101
102
db.products.map {
102
103
val id = it.id
103
104
val title = it.title
@@ -125,13 +126,12 @@ which provides a different syntax for the `zip`-`mapLocal` chain.
125
126
data class MyProduct(val id: Int, val title: String, val images: List<MyImage>)
126
127
data class MyImage(val url: String)
127
128
128
- val result: List<MyNonSerializableClass> = query { db ->
129
- db.products.mapLocal2 {
129
+ val result: List<MyProduct> = query { db ->
130
130
val id = it.id.request()
131
131
val title = it.title.request()
132
132
val images = it.images.mapLocal { MyImage(it) }.toList().request()
133
133
onSuccess {
134
- MyNonSerializableClass (id.get(), title.get(), images.get())
134
+ MyProduct (id.get(), title.get(), images.get())
135
135
}
136
136
}.toList()
137
137
}
0 commit comments