edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
513 stars 65 forks source link

Optional fields inside tuple parameters #554

Open aroblast opened 1 year ago

aroblast commented 1 year ago

Request

Add support for optional fields inside tuple parameters inside e.params({ ... }) arguments. This would allow for an implicit JSON to EdgeDB mapping inside the query.run(client, {...}) method while not having to cast every single parameter by hand using e.json params.

Syntax

Why not use the already existing e.optional() allowed in the top level properties of e.params({}) argument, and possibly implement it this way:

e.params({
    tupleParameter: e.tuple({
        requiredParam: e.int32,
        optionalParam: e.optional(e.int32), // Optional int32 parameter
    })
}, ...);

This would allow to use the query.run(client, {...}) method like so (or by simply passing the correct object as parameters):

const requiredNumberParameter: number = 42;
const optionalNumberParameter: number | null = null;

e.run(client, {
    tupleParameter: {
        requiredParam: requiredNumberParameter,
        optionalParam: optionalNumberParameter,
    })
});

Thank you in advance.

mcgrealife commented 1 year ago

+1 for this.

Here are the related discord threads:

Typing e.params() using e.array() and e.tuples() instead of e.json() is much more enjoyable, but lack of optionals prevents in many cases

CallumAlder commented 7 months ago

+1 for this please