Skip to content

Only query tag trigger update callback timer聽#16

Description

@khanhicetea

Thanks for the lib, it works like charm 馃槃

Btw, I read the code and see only the query tag from init.js (https://github.com/WebReflection/sqlite-worker/blob/main/esm/init.js#L96) triggers the update callback timer.

I tried the transaction tag and it doesn't work

// no ?module needed, it's the main export in unpkg
import { init } from "//unpkg.com/sqlite-worker";

// `dist` option resolved automatically via import.meta.url
init({
  name: "my-db1",
  update(uInt8Array) {
    console.log("updated", uInt8Array);
  },
}).then(async ({ all, get, query, raw, transaction }) => {
  const table = raw`todos`;
  await query`CREATE TABLE IF NOT EXISTS ${table} (id INTEGER PRIMARY KEY, value TEXT)`;
  const { total } = await get`SELECT COUNT(id) as total FROM ${table}`;
  if (total < 10) {
    console.log("Inserting some value");
    await query`INSERT INTO ${table} (value) VALUES (${"a"})`;
    await query`INSERT INTO ${table} (value) VALUES (${"b"})`;
    await query`INSERT INTO ${table} (value) VALUES (${"c"})`;
  }
  const insert = transaction();
  for (let i = 0; i < 10; i++)
    insert`INSERT INTO todos (value) VALUES (${"Ipsum " + i})`;
  await insert.commit();
  console.log(await all`SELECT * FROM ${table}`);
});

Can we export a defer update function, save function to manual trigger save ?

Thanks

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions