edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
214 stars 26 forks source link

Unless conflict: not working and failed #281

Closed codeyash closed 1 year ago

codeyash commented 1 year ago

Describe the bug

   let get_or_create = "insert default::SessionCart {
        discount_amount := 20

    }
    UNLESS CONFLICT ON .discount_amount
    ELSE (SELECT default::SessionCart);
    ";

    conn.query_json(get_or_create, &()).await.unwrap();```

//"Unexpected 'UNLESS'"

```rust

Expected behavior This should work as it is working fine in python and typescript: https://www.edgedb.com/docs/clients/js/insert#handling-conflicts.

Versions (please complete the following information): For EdgeDB version: {'3.4+6d5921b'} For EdgeDB CLI version: EdgeDB CLI 3.5.0+e1ad387 For Rust compiler version: rustc 1.75.0-nightly (187b8131d 2023-10-03) For Cargo version: cargo 1.75.0-nightly (59596f0f3 2023-09-29)

scotttrinh commented 1 year ago

Is this meant to be an insert statement instead of select maybe?

codeyash commented 1 year ago
  1. This will save us from duplicating data in high concurrent runs.
  2. Insert the entry or return existing entry without creating trouble.
  3. Handle conflicts gracefully like we can SELECT or UPDATE existing entries.

So this is very important to scale Rust client.

more info: https://www.edgedb.com/docs/clients/js/insert#handling-conflicts

Dhghomon commented 1 year ago

As far as I can tell this will work if you change the first select to insert.

codeyash commented 1 year ago

As far as I can tell this will work if you change the first select to insert.

Corrected. It won't change the error.

codeyash commented 1 year ago

This seems to be working fine!

False alarm!

Dhghomon commented 1 year ago

Great to hear! False alarms are the best kind