Execute oxfmt (#1166)
Ran pnpm oxfmt . This should get the web repo aligned so that we can better enforce oxfmt going forward.
This commit is contained in:
@@ -16,23 +16,32 @@ export type SqlocalDb = BaseSQLiteDatabase<"async", unknown, typeof schema>;
|
||||
* returns a Drizzle client typed against the schema. One instance per origin —
|
||||
* sqlocal serializes writes via Web Locks under the hood.
|
||||
*/
|
||||
export async function createSqlocalDb(options: CreateSqlocalDbOptions = {}): Promise<SqlocalDb> {
|
||||
export async function createSqlocalDb(
|
||||
options: CreateSqlocalDbOptions = {},
|
||||
): Promise<SqlocalDb> {
|
||||
const databasePath = options.databasePath ?? "meshtastic.db";
|
||||
const { driver, batchDriver, sql } = new SQLocalDrizzle({ databasePath });
|
||||
const db = drizzle(driver, batchDriver, { schema, casing: "snake_case" }) as SqlocalDb;
|
||||
const db = drizzle(driver, batchDriver, {
|
||||
schema,
|
||||
casing: "snake_case",
|
||||
}) as SqlocalDb;
|
||||
|
||||
await applyMigrations(sql);
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
type RawSql = (query: TemplateStringsArray, ...values: ReadonlyArray<unknown>) => Promise<unknown>;
|
||||
type RawSql = (
|
||||
query: TemplateStringsArray,
|
||||
...values: ReadonlyArray<unknown>
|
||||
) => Promise<unknown>;
|
||||
|
||||
async function applyMigrations(sql: RawSql): Promise<void> {
|
||||
await sql`CREATE TABLE IF NOT EXISTS _schema (version INTEGER PRIMARY KEY)`;
|
||||
const rows = (await sql`SELECT version FROM _schema ORDER BY version DESC LIMIT 1`) as Array<{
|
||||
version: number;
|
||||
}>;
|
||||
const rows =
|
||||
(await sql`SELECT version FROM _schema ORDER BY version DESC LIMIT 1`) as Array<{
|
||||
version: number;
|
||||
}>;
|
||||
const current = rows[0]?.version ?? 0;
|
||||
for (const migration of MIGRATIONS) {
|
||||
if (migration.version <= current) continue;
|
||||
|
||||
Reference in New Issue
Block a user