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
.
Specify the modelqlKotlinDir property to enable the generation. |
For properties, references and single-valued child links use the set
-functions.
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.
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.
client.query { root ->
root.children("classes").ofConcept(C_ClassConcept)
.first()
.untyped()
.remove()
}