-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from modelix/docs/modelql-write-support
MODELIX-716 Document write capabilities of typed ModelQL
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
= How-To write via ModelQL | ||
|
||
== Writing with the type-safe ModelQL API | ||
|
||
The extensions generated by `model-api-gen-gradle` also include functions for write access. | ||
These can be called on receivers that are instances of `IMonoStep`. | ||
|
||
[NOTE] | ||
-- | ||
Specify the link:../reference/component-model-api-gen-gradle.adoc#model-api-gen-gradle_attributes_modelqlKotlinDir[modelqlKotlinDir] property to enable the generation. | ||
-- | ||
|
||
For properties, references and single-valued child links use the `set`-functions. | ||
|
||
[source,kotlin] | ||
-- | ||
client.query { root -> | ||
root.children("classes").ofConcept(C_ClassConcept) | ||
.member | ||
.ofConcept(C_StaticMethodDeclaration) | ||
.first() | ||
.setName("myNewMethodName".asMono()) | ||
} | ||
-- | ||
|
||
To add a new child to multi-valued child links use the generated `addTo`-functions. | ||
The index parameter is optional: by default the child will be appended at the end. | ||
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. | ||
|
||
[source,kotlin] | ||
-- | ||
client.query { root -> | ||
root.children("classes").ofConcept(C_ClassConcept) | ||
.first() | ||
.addToMember(C_StaticMethodDeclaration, index=1) | ||
} | ||
-- | ||
|
||
To remove a node, you will need to use the untyped API by calling `.untyped().remove()` on the typed node you want to remove. | ||
|
||
[source,kotlin] | ||
-- | ||
client.query { root -> | ||
root.children("classes").ofConcept(C_ClassConcept) | ||
.first() | ||
.untyped() | ||
.remove() | ||
} | ||
-- | ||
|
||
== Writing with the untyped ModelQL API | ||
|
||
The untyped API is similar to the `INode` API (see `model-api`) and can be accessed by calling `.untyped()`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters