Skip to content

Commit 2dd4605

Browse files
authored
Merge pull request #444 from modelix/docs/modelql-write-support
MODELIX-716 Document write capabilities of typed ModelQL
2 parents 0294716 + 1bf51f9 commit 2dd4605

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
= How-To write via ModelQL
2+
3+
== Writing with the type-safe ModelQL API
4+
5+
The extensions generated by `model-api-gen-gradle` also include functions for write access.
6+
These can be called on receivers that are instances of `IMonoStep`.
7+
8+
[NOTE]
9+
--
10+
Specify the link:../reference/component-model-api-gen-gradle.adoc#model-api-gen-gradle_attributes_modelqlKotlinDir[modelqlKotlinDir] property to enable the generation.
11+
--
12+
13+
For properties, references and single-valued child links use the `set`-functions.
14+
15+
[source,kotlin]
16+
--
17+
client.query { root ->
18+
root.children("classes").ofConcept(C_ClassConcept)
19+
.member
20+
.ofConcept(C_StaticMethodDeclaration)
21+
.first()
22+
.setName("myNewMethodName".asMono())
23+
}
24+
--
25+
26+
To add a new child to multi-valued child links use the generated `addTo`-functions.
27+
The index parameter is optional: by default the child will be appended at the end.
28+
In case the target type of the child link is not abstract, the concept parameter can be omitted, because a default value will have been generated.
29+
30+
[source,kotlin]
31+
--
32+
client.query { root ->
33+
root.children("classes").ofConcept(C_ClassConcept)
34+
.first()
35+
.addToMember(C_StaticMethodDeclaration, index=1)
36+
}
37+
--
38+
39+
To remove a node, you will need to use the untyped API by calling `.untyped().remove()` on the typed node you want to remove.
40+
41+
[source,kotlin]
42+
--
43+
client.query { root ->
44+
root.children("classes").ofConcept(C_ClassConcept)
45+
.first()
46+
.untyped()
47+
.remove()
48+
}
49+
--
50+
51+
== Writing with the untyped ModelQL API
52+
53+
The untyped API is similar to the `INode` API (see `model-api`) and can be accessed by calling `.untyped()`.

docs/global/modules/core/partials/nav-howto.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
* xref:core:howto/usage-light-model-client.adoc[]
44
* xref:core:howto/testing-against-model-api.adoc[]
55
* xref:core:howto/modelql.adoc[]
6+
* xref:core:howto/modelql-writing.adoc[]

0 commit comments

Comments
 (0)