Skip to content

SQLite

@arona/store-sqlite is a MessageSessionStore on Effect SQL with the node SQLite adapter. It uses the same table and version checks as @arona/store-cloudflare’s D1 store. A gateway process can restart and resume messages, and the version check rejects a stale interaction.

The package needs Node 22.18 or newer, which is the runtime Arona already requires.

SqliteStore.layer opens the database, applies the schema, provides the store, and closes the database when the layer scope ends. It is the one call most apps need:

import * as SqliteStore from "@arona/store-sqlite";
const sessions = SqliteStore.layer({ filename: ".arona/sessions.sqlite" });

Pass it to DiscordGatewayClient.layer; the client requires the store and enables resumable messages automatically:

import { DiscordGatewayClient } from "@arona/platform-discord";
import * as SqliteStore from "@arona/store-sqlite";
import { Layer } from "effect";
const clientLayer = DiscordGatewayClient.layer({
token,
clientId,
intents,
devGuildId,
build,
}).pipe(Layer.provide(SqliteStore.layer({ filename: ".arona/sessions.sqlite" })));

The Rick and Morty example does this and reads the path from ARONA_SQLITE_PATH, defaulting to .arona/sessions.sqlite. Migrations run on every open; pass { migrate: false } to skip them.

SqliteStore.open, SqliteStore.migrate, SqliteStore.make, and SqliteStore.layerFrom remain available when you want to own the client lifetime yourself:

import * as SqliteStore from "@arona/store-sqlite";
import { Effect } from "effect";
const sessions =
yield *
Effect.scoped(
Effect.gen(function* () {
const sql = yield* SqliteStore.open(".arona/sessions.sqlite");
yield* SqliteStore.migrate(sql);
return SqliteStore.make(sql);
}),
);

SqliteStore.open creates parent directories, opens a scoped SQLite client, sets a busy timeout, and enables WAL for file databases. SqliteStore.layerFrom(sql, { migrate: true }) provides MessageSessionStore for an already-open client and does not close it.

SQL migrations live in packages/store-sqlite/migrations for deploy tooling. SqliteStore.migrate applies the same schema from code, so it also works where no filesystem is available; it creates the table when it is missing, adds the lease columns to an older database, and is safe to run on every startup.

Close the database when the process shuts down. The Rick and Morty example releases it with Effect.acquireRelease.