sidequest icon indicating copy to clipboard operation
sidequest copied to clipboard

Consider WAL mode as default for sqlite

Open Mortalife opened this issue 1 year ago • 5 comments

Currently the use of sqlite is in journal mode, this as you've noted in your documentation isn't great for multiple workers.

With this in mind could you consider some better defaults to allow it to work more seamlessly across multiple workers?

await knex.raw("PRAGMA journal_mode = WAL;");
await knex.raw("PRAGMA busy_timeout = 5000;");
await knex.raw("PRAGMA synchronous = NORMAL;");
await knex.raw("PRAGMA cache_size = 2000;");
await knex.raw("PRAGMA foreign_keys = ON;");

Mortalife avatar Sep 05 '25 21:09 Mortalife

Interesting. Let me talk to @merencia about this. Seems doable. Since SQLite is not recommended for production anyway, we can test it and break stuff.

GiovaniGuizzo avatar Sep 06 '25 12:09 GiovaniGuizzo

Looking for it.

My use case, using a full RDMS is overkill

BTW for long time i used sqilte (in WAL mode) as database in an app with ~30-50 simultaneous connection without issues

blikblum avatar Oct 06 '25 00:10 blikblum

@Mortalife I have created a new PR for this. Thanks for the suggestion. Even the tests are a bit faster now.

GiovaniGuizzo avatar Oct 08 '25 12:10 GiovaniGuizzo

:tada: This issue has been resolved in version 1.10.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

sidequest-release[bot] avatar Oct 08 '25 14:10 sidequest-release[bot]

Just a PSA, the migration for enabling WAL didn't actually enable WAL in my case.

So I now manually enable the WAL when creating sidequest.

Sidequest.start({
  backend: {
    driver: "@sidequest/sqlite-backend",
    config: {
      client: "better-sqlite3",
      connection: {
        filename: `sidequest.sqlite`,
      },
      pool: {
        afterCreate: (conn: any, cb: any) => {
          console.log("Sidequest database connection created");

          conn.prepare("PRAGMA journal_mode = WAL").run();
          conn.prepare("PRAGMA busy_timeout = 5000").run();
          conn.prepare("PRAGMA synchronous = NORMAL").run();
          conn.prepare("PRAGMA cache_size = 2000").run();

          cb(null, conn);
        },
      },
    },
  },
})

Mortalife avatar Dec 31 '25 14:12 Mortalife