blob: 3fc4182ac275262be0bf18aaa65577b190aa9b27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import { Agent } from '../model/agent.ts';
import { DbData, db } from './db.ts';
const addAgentStatement = db.prepare(`INSERT INTO agents(data) VALUES (json(?));`);
const getAgentStatement = db.prepare(`SELECT data FROM agents;`);
const setAgentStatement = db.prepare(`UPDATE agents SET data = json(?);`);
export function addAgent(agent: Agent): void {
addAgentStatement.run(JSON.stringify(agent));
}
export function getAgent(): Agent|null {
const data = getAgentStatement.get() as DbData|undefined;
if (!data) return null;
return JSON.parse(data.data);
}
export function setAgent(agent: Agent): void {
setAgentStatement.run(JSON.stringify(agent));
}
|