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

Provide syntactic sugar for upserting a record #18

Closed
isuru89 opened this issue May 24, 2017 · 1 comment
Closed

Provide syntactic sugar for upserting a record #18

isuru89 opened this issue May 24, 2017 · 1 comment
Assignees
Milestone

Comments

@isuru89
Copy link
Contributor

isuru89 commented May 24, 2017

Currently if a user wants to insert if not exist or update (upsert) a particular record to a table, he/she must write a script to do it which having at least three queries; one for check the existence, other for inserting, and another for updating.

It is nice to provide an upsert syntax to do this is one single expression (or query). AFAIK there are no rdbms database having a single syntax for upserting, but it is believed NyQL can do this by simulating these three steps automatically.

Need to think about how the syntax would like be.

@isuru89 isuru89 changed the title Provide syntactic sugar for upsert a record Provide syntactic sugar for upserting a record May 24, 2017
@isuru89 isuru89 added this to the v2.0 milestone May 24, 2017
@isuru89
Copy link
Contributor Author

isuru89 commented May 29, 2017

Basically syntax for an upsert query would be as same as an UPDATE query.
i.e. it has;

  • TARGET table
  • Optional JOINING tables
  • SET clause
  • WHERE clause

In addition to that, user can specify what to return after the execution of an upsert query. Such as, the record before update/insert happens, record after update/insert, custom fetched columns after update/insert, or nothing. These values may be defined using clauses RETURN_BEFORE, RETURN_AFTER, RETURN_COLUMNS, RETURN_NONE respectively.

Eg: Upsert query would look like

$DSL.upsert {
    TARGET (...)
    JOIN { ... }     // optional
    SET { ... }
    WHERE { ... }

    RETURN_AFTER()   // new clause user has to specify what to return
}

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

1 participant