edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Optional fields inside tuple parameters

Open bastienlecorre opened this issue 2 years ago • 2 comments

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.

bastienlecorre avatar Mar 01 '23 14:03 bastienlecorre

+1 for this.

Here are the related discord threads:

  • https://discord.com/channels/841451783728529451/1079834474415656990
  • https://discord.com/channels/841451783728529451/1070149803729752165

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

mcgrealife avatar Mar 02 '23 04:03 mcgrealife

+1 for this please

CallumAlder avatar Apr 14 '24 16:04 CallumAlder