Skip to content

Request: Prepared Query Batch #22

Description

@Strepto

Nice package for Sqlite on the web! Simple design and seems to work well! Starred to see the development of this.

I'd like to see a prepared query interface, possibly with a batch method. This is to populate the database based on json from a server.
I believe sqlites prepared statements could be used to optimize inserts.

const preparedStatement = await db.prepare("INSERT INTO animals VALUES (?)");
const result = await preparedStatement.runOnce(["Goose"]); // Run a single query possibly more performant due to the preparedStatement
const result2 = preparedStatement.runBatch([["Squirrel"],["Fox"]]); // Run a batch of queries to avoid IO on the worker etc for each query.
preparedStatement.dispose();

As of v0.0.1-alpha.7 its a lot faster to batch queries by doing something like below. But this requires more calls and opens up for injections etc.

// Current Workaround 
const megaquery = animals.map(x => `INSERT INTO animals values ('${x.Id}', '${x.name}')`).join(";\n")
const result = db.query(megaquery);

If this is not planned or you want to cleanup issues feel free to close this. Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions