Download packages/session-backends/sqlite-node/src/sqlite/session/session-sequences.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 691 Bytes
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/session-backends/sqlite-node/src/sqlite/session/session-sequences.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/session-backends/sqlite-node/src/sqlite/session/session-sequences.ts
-
curl -L -o session-sequences.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/session-backends/sqlite-node/src/sqlite/session/session-sequences.ts
691 Bytes
| import { sql } from "../sql.ts"; | |
| import type { SqliteDatabase } from "../types.ts"; | |
| export function readNextSeq(db: SqliteDatabase, sessionId: string): number { | |
| const row = sql`SELECT next_seq FROM sessions WHERE id = ${sessionId}`.get<{ next_seq: number }>(db); | |
| if (row === undefined) throw new Error(`Unknown SQLite session: ${sessionId}`); | |
| return row.next_seq; | |
| } | |
| export function advanceNextSeq(db: SqliteDatabase, sessionId: string, nextSeq: number): void { | |
| const result = sql`UPDATE sessions SET next_seq = ${nextSeq} WHERE id = ${sessionId}`.run(db); | |
| if (result.changes !== 1) | |
| throw new Error(`Expected to update one SQLite session ${sessionId}, updated ${result.changes}`); | |
| } | |