Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for atomic updates #140

Open
kevinpiac opened this issue Sep 9, 2024 · 0 comments
Open

Add support for atomic updates #140

kevinpiac opened this issue Sep 9, 2024 · 0 comments

Comments

@kevinpiac
Copy link

kevinpiac commented Sep 9, 2024

Hey!

Thanks for this awesome library.

In the current version it seems it's not possible to update nested objects atomically.

Here is an example to illustrate what I mean.

Given the following schema:

interface User {
    firstName: string;
    metadata?: {
        nestedKey1?: number;
        nestedKey2?: boolean;
    }
}

If I want to update specifically one property inside the metadata object without replacing the whole object, I can do it by creating an atomic update object like this:

  const userId = db.users.id('my-id);

  // This works, but does not compile
  await db.users.update(userId, {
       "metadata.nestedKey1": 123
  });

It currently works fine, even using Typesaurus. However, the UpdateData type does not support it so it result in a compilation error.

I don't know if the best way would be to update the UpdateData type or to create a dedicated type but if you point me the right way to do it, I would be happy to submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant