mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-06 23:44:36 +00:00
feat(sqlite): session seq helpers
This commit is contained in:
parent
14b5aaa213
commit
b448269c83
2 changed files with 72 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
import { sql } from "../sql.ts";
|
||||
import type { SqliteDatabase } from "../types.ts";
|
||||
|
||||
export function readNextSeq(db: SqliteDatabase): number {
|
||||
const rows = sql`SELECT next_seq FROM session`.all<{ next_seq: number }>(db);
|
||||
if (rows.length !== 1) throw new Error(`Expected exactly one session row, found ${rows.length}`);
|
||||
return rows[0]!.next_seq;
|
||||
}
|
||||
|
||||
export function advanceNextSeq(db: SqliteDatabase, nextSeq: number): void {
|
||||
const result = sql`UPDATE session SET next_seq = ${nextSeq}`.run(db);
|
||||
if (result.changes !== 1) throw new Error(`Expected to update exactly one session row, updated ${result.changes}`);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue