-
-
Notifications
You must be signed in to change notification settings - Fork 722
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
[BUG]: Insert empty array should be valid #1719
Comments
I don't think you should just delete this type of safeguards and not include tests verifying it didn't break another area of the codebase. await db.insert(users).values({}); See for example this test. And the test right after that one. The problem with accepting an empty array, is that it disables all the type guards around the inserted value. const myTable = pgTable("my_table", {
id: serial('id').primaryKey(),
name: text('name').notNull()
}
// if you attempt to insert the way you describe like this:
const insertedValue: typeof myTable.$inferInsert[] = []; // an empty array is a valid array for anything.
// This next line is going to fail at the database level
const response = await db.insert(myTable).values(insertedValue); Instead, you could use an empty object, to signify that you want to insert one row to the DB and the types will check it. |
What would you say then to the idea of having some special exception raised (to skip all the logic of even contacting the db) and just return |
I don't think this would be actionable until #376 is closed. And to be honest with you, I personally don't think it's a good idea. I don't really know why us dev just don't want to deal with errors. |
I don't disagree. I will close this and the PR |
What version of
drizzle-orm
are you using?0.29.2
What version of
drizzle-kit
are you using?0.20.9
Describe the Bug
drizzle-orm/drizzle-orm/src/pg-core/query-builders/insert.ts
Line 50 in d535e0b
Why would this not just be a no-op?
Expected behavior
If the
values
parameter is an object, I would expect a required value but if it is an array, I think length 0 is acceptable input.Environment & setup
No response
The text was updated successfully, but these errors were encountered: