-
-
Notifications
You must be signed in to change notification settings - Fork 685
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]: Don't throw when .values() is called with an empty array #1078
Comments
👍 Would be great to also have this for inArray. It is work-aroundable, like OP said, but generates significant amount of noise in the code, and acts as potential source for runtime errors due to being a "bug" TS is not able to catch. Fun fact: While I was checking my code for one of the usages to include here as an example, I did notice a bug because of exactly that. if (onlyIds.length) {
await tx.insert(applicationServiceConnections).values(
onlyIds.map((serviceId) => ({
serviceId,
applicationId: id,
}))
)
}
const serviceRows = await tx.query.services.findMany({
with: {
applications: true,
},
where: inArray(services.id, onlyIds),
}) In the first block, I thought about the length check. But for the following query, I forgot it => runtime error. |
@emdede Agreed, if it was possible to make it a TS error, that might be the ideal solution. |
It's hard to provide an API that everybody is happy with. Please see #441 for additional context. |
Describe what you want
I recently converted my codebase over from Prisma to drizzle, and I have had multiple runtime bugs slip into production where I was passing in an empty array to insert.values() and getting this error:
values() must be called with at least one value
The problem is, sometimes you need to dynamically create an array before passing it into the insert function,
and it is very easy to forget to wrap the code in:
I propose allowing empty arrays to be passed in by simply resolving the promise with an early return instead of throwing an error. To me, this seems like the lesser of two evils.
The text was updated successfully, but these errors were encountered: