planetscale / planetscale/database-js

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

Open
#147 7 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.2k
Forks
42
PR merge metrics
No merged PRs in 30d

Description

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".

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing execute API and its parameter handling, which the issue uses in its examples. Compare the proposed bulkinsert and createBulkInsert shapes, then define how rows become placeholders and bound parameters. Done means a supported bulk-insert helper with documented behavior and coverage for the multi-row example; the issue does not name specific files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, typescript
Domain
api, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.