Skip to content

Consider replacing Deno.KvU64 by standard BigInt #104

@WilcoKruijer

Description

@WilcoKruijer

Hello again,

I'm not sure what the exact reasoning is behind using a Deno specific unsigned value (please enlighten me!), but I'd it's quite limiting. It looks like FoundationDB supports atomic operations for signed values just fine.

Because of the unsignedness restriction, some seemingly simple use cases are impossible:

  await db.atomic()
    .set(["a"], 1n)
    .commit();
  await db.atomic()
    .sum(["a"], 2n).commit();

This throws with TypeError: Failed to perform 'sum' mutation on a non-U64 value in the database.

We also cannot subtract from atomic values at all:

  await db.atomic()
    .set(["a"], new Deno.KvU64(100n));
    .commit();

  await db.atomic()
    .sum(["a"], -3n);
    .commit();

RangeError: value must be a positive bigint

Imo, a nice solution would be to get rid of Deno.KvU64 altogether and just opaquely swap it out for a (signed) long value internally. Throwing when the value goes out of range.

Another, albeit less nice, solution would be to give the option to use either Deno.KvU64 or a signed variant of it when you set a value.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions