You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inserting values into the database, sometimes I end up needing to add an empty array. Currently this throws an error:
Error: values() must be called with at least one value
at PgInsertBuilder.values (/Users/hansenq/Documents/CS/lightski/node_modules/src/pg-core/query-builders/insert.ts:50:10)
at db.transaction.isolationLevel (/Users/hansenq/Documents/CS/lightski/packages/database/bin/data-migrations/2024-01-23-backfill-embeds-from-assistants.ts:50:33)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NodePgSession.transaction (/Users/hansenq/Documents/CS/lightski/node_modules/src/node-postgres/session.ts:138:19)
at async backfillEmbedsFromAssistants (/Users/hansenq/Documents/CS/lightski/packages/database/bin/data-migrations/2024-01-23-backfill-embeds-from-assistants.ts:38:3)
at async /Users/hansenq/Documents/CS/lightski/packages/database/bin/data-migrations/2024-01-23-backfill-embeds-from-assistants.ts:84:5
at async withDb (/Users/hansenq/Documents/CS/lightski/packages/database/bin/data-migrations/2024-01-23-backfill-embeds-from-assistants.ts:31:5)
at async main (/Users/hansenq/Documents/CS/lightski/packages/database/bin/data-migrations/2024-01-23-backfill-embeds-from-assistants.ts:83:3)
Supporting [] inside db.insert(myTable).values([]) would be more ergonomically friendly and allow me to skip pulling the array into a variable and checking the length of that array before calling db.insert.
This is similar in spirit to #1295. Edit: Looks like this is the same as a previous issue #1078
The text was updated successfully, but these errors were encountered:
I'm aware that exists, but that doesn't solve my issue. Basically, sometimes I'll copy some data from one table into another table (in order to backfill it). Sometimes a local dev DB doesn't have data in the first table, so the table will be empty:
letoldModels=awaitdb.query.oldModels.findMany({})// has length 0awaitdb.insert(newModels).values(oldModels.map((om)=>({name: om.name,description: om.description,})))
But this code fails when oldModels is empty, forcing me to change the code to the following, which is unergonomic.
letoldModels=awaitdb.query.oldModels.findMany({})// has length 0if(oldModels.length!==0){awaitdb.insert(newModels).values(oldModels.map((om)=>({name: om.name,description: om.description,})))}
The most annoying thing is, because this happens to different local/test DBs that don't have prod data, this bug doesn't surface until later during runtime when another engineer is running the code or tests are being run, so it's super easy to forget.
I have run into the same issue with MySQL. Although this is more of a QoL change, I was disappointed to find that the existing DX is lacking. Small FRs like these are still valuable and can set one library apart from another.
Describe what you want
When inserting values into the database, sometimes I end up needing to add an empty array. Currently this throws an error:
Supporting
[]
insidedb.insert(myTable).values([])
would be more ergonomically friendly and allow me to skip pulling the array into a variable and checking the length of that array before callingdb.insert
.This is similar in spirit to #1295. Edit: Looks like this is the same as a previous issue #1078
The text was updated successfully, but these errors were encountered: