summaryrefslogtreecommitdiff
path: root/nodejs/database/agents.js
blob: 4dd7f4b89cf0009082ac60eb167a18195729a114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import db from './db.js';

const addAgentStatement = db.prepare(`INSERT INTO agents(data) VALUES (json(?));`);
const getAgentStatement = db.prepare(`SELECT data FROM agents;`);

export function addAgent(agent) {
	return addAgentStatement.run(JSON.stringify(agent)).lastInsertRowid;
}

export function getAgent() {
	const data = getAgentStatement.get();
	if (data === undefined) {
		return null;
	}
	return JSON.parse(data.data);
}