Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify attribute deletes by using anonymous bindings #340

Open
james-whiteside opened this issue Jun 25, 2024 · 0 comments
Open

Simplify attribute deletes by using anonymous bindings #340

james-whiteside opened this issue Jun 25, 2024 · 0 comments

Comments

@james-whiteside
Copy link

james-whiteside commented Jun 25, 2024

Problem to Solve

Some users have reported that deleting or updating attributes is unintuitive. Currently, we can insert attributes without explicitly binding them to a variable, as follows:

insert
  $p isa person,
    has name "Josh",
    has age 28;

However, when we want to delete attributes, we have to bind them to a variable:

match
  $p isa person,
    has name "Josh",
    has age $a;
  $a == 28;
delete
  $p has $a;
insert
  $p has age 29;

Proposed Solution

Given that a type and value are sufficient to identify an attribute instance, there is little need for the variable $a in this case. We could consider syntax of the following form instead:

match
  $p isa person, has name "Josh";
delete
  $p has age 28;
insert
  $p has age 29;

What should happen if the attribute to be deleted does not exist is an open question. Most likely, this should not throw an error and the insert should still occur. This is in line with attribute deletion idempotency (typedb/typedb#6884).

This change will significantly simplify updates and deletes where only a single attribute must be changed. For cases where multiple attributes should be deleted, we can still use the "advanced" syntax where the attribute is "parametrised" in the delete clause:

match
  $p isa person,
    has name "Josh",
    has nickname $n;
delete
  $p has $n;

Note

The introduction of @replace in TypeDB 3.0 will simplify the case for updates, but not for deletes. This general change simplifies both, and makes @replace a syntactic sugar. These two methods for updates will have slightly different behaviour, and there may be some more nuanced cases where one syntax is preferable to the other for updates. As such, both should be permitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants