engine
engine copied to clipboard
Feature: Ability to connect or create if entity doesn't exist
Here is an example:
@Unique('segment', 'parent')
class Url {
segment = def.stringColumn().notNull()
parent = def.manyHasOne(Url)
}
Let's say I would like to create following structure, but I don't know wheather Url(segment="bar")
exists:
{
"segment": "foo",
"parent": {
"segment": "bar",
"parent": null
}
}
Currently I need one query to check if it exists and then do the mutation. I propose following option:
mutation {
createUrl(data: {
segment: "foo",
parent: {
connectOrCreate: {
segment: "bar"
parent: null
}
}
}) {
ok
}
}
Inside connectOrCreate
would be also helpful to be able to specify other field. Then the engine could try to insert it as new row, but when unique constraint would be violated it would do "connect" instead.