-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
multiple row insert with db.sql / INSERT INTO #127
Comments
First, is there a reason you don't want to use the You'd just write const userIds = db.insert('users', users, { returning: ['user_id'] }).run(pool); If there is a reason, I guess we could either create something like your const completedValues = completeKeysWithDefaultValue(values, Default);
const valuesSQL = mapWithSeparator(completedValues, sql`, `, v => sql`(${vals(v)})`); Edit: ah, I now see you say you're aware of the |
Mostly just for workflow reasons. Typically I'm prototyping these queries as SQL with psql. Some of them have become fairly complex and it's easier for me to take the final query and use the db.sql<>`` syntax than it is to try to back port the query to a series of db shortcuts + db.sql<>`` statements for the pieces that I can't represent using the shortcuts. |
I've just searched for the same thing, and I can't (please correct me if I'm wrong) use the |
@maxweisel Fair enough, I'll look into adding your @jwhitmarsh Thanks. Can I check that the |
@jawj being a developer is endlessly humbling. Apologies for missing that, and thank you for the help! |
I'd also love this functionality to help when writing CTEs (with db.sql) |
I'm aware of the db.insert() shortcut that can perform multiple-row insert, however, is it possible to accomplish the same thing with INSERT INTO without performing custom string concatenation?
I love that I can do this:
I'd love to be able to do this:
Where
${db.rows(users)}
expands to something like:I could write my own shortcut to do that, but I always fear writing something that generates an unsafe query.
Max
The text was updated successfully, but these errors were encountered: