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

Feature Request: Support upserts #126

Open
coren-frankel opened this issue Oct 5, 2024 · 3 comments
Open

Feature Request: Support upserts #126

coren-frankel opened this issue Oct 5, 2024 · 3 comments

Comments

@coren-frankel
Copy link

First of all, thank you for such a solid package!

I am unsure if it's a realistic request, but I couldn't find any discussion, issue, or PR alluding to upserts so I want to start the conversation.

Given that there is currently support for the findUnique Prisma API, and the create and update methods generate an encrypted field's hash counterpart, would it be possible to extend support to upsert? Perhaps beyond that question, would nested upsert operations also be possible?

@franky47
Copy link
Member

franky47 commented Oct 5, 2024

As long as the fields you want to use to check if a given record exists are either unencrypted or contain a hash to allow querying, this sounds like something that should be possible.

Would you like to open a PR?

@coren-frankel
Copy link
Author

Very cool. Yes, I am definitely interested in contributing.

Do you have any suggestions on how to approach it or where to get started? I'll aim to get familiar with the repo this weekend.

Thanks!

@franky47
Copy link
Member

franky47 commented Oct 5, 2024

The encryption.ts file is where most of the logic lives.

It's based on a visitor pattern which walks the query you pass on writes, and encrypts/hashes what needs it. The encrypted query is forwarded to the DB by Prisma, and when the result comes back, the visitor walks the response and decrypts as needed.

Regarding upsert queries, I just realised that PR #123 added a test which uses an upsert, so it seems like it's supported already. Feel free to add some integration tests to try and fish out some implementation issues (particularly with nested upserts), that could be a good start (TDD style).

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

2 participants