edgedb / edgedb-rust

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

Value::Nothing meaningfulness to represent potential absence of property value in queries #252

Closed tetotechy closed 1 year ago

tetotechy commented 1 year ago

This might be a bug, but when I provide an optional value as a param in methods like Client::query_json I get an error like QueryError: parameter $0 is required if the value in Rust is None. For example:

type Maybe { val: bool; } is the EdgeDB type/table in the database, i.e. with an optional property named val

in Rust, assume I want to create Maybe values with:

client.query_json("insert MaybeInt { val := <bool>$0 }", &(rust_val, ))

where rust_val is an Option<bool> variable in scope. All is good if rust_val is Some(...), whereas I get the error when it is None, which is translated in Value::Nothing

Experimenting a bit, I had the same problem with values of other types.

Shouldn't Value::Nothing be the tool for representing "null" values of optional properties?

tailhook commented 1 year ago

You have to specify <optional bool>$0 explicitly.

Although, the fact that we allow Some() for non-optional parameter might be a bug (an artifact from early times where we didn't have this distinction manifested to the client).