planetscale/database-js

feat: Support syntax helper for "bulk insert with parameters"

mattrobenolt opened this issue · 0 comments

A pattern that is a bit of a pain for us is doing an INSERT with multiple rows at once.

While we support explicitly doing something like:

execute("INSERT INTO x VALUES (?, ?, ?), (?, ?, ?)", [1, 2, 3, 4, 5, 6])

It puts the burden on the user to create all of the (?, ?, ?) placeholders.

An API similar to:

bulkinsert("INSERT INTO x VALUES", [[1, 2, 3], [4, 5, 6]])

would help utilize this without the client needing to construct all of the placeholders.

We could even just provide this as a separate function that's passed into execute() as just a "query builder" thing.

So something like:

execute(createBulkInsert("INSERT INTO x VALUES", [[1, 2, 3], [4, 5, 6]]))

And createBulkInsert would return the SQL.

It's just all around a bit awkward to need to have one big flat list of all the parameters vs passing in more logical "rows".