summaryrefslogtreecommitdiff
path: root/database/config.js
blob: 7a50f68b12e1c993b1d36efb8714587bd103ed6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import db from './db.js';

const getTokenStatement = db.prepare(`SELECT value->>'token' as token from config where key = 'register_data';`);
const registerAgentStatement = db.prepare(`INSERT INTO config(key, value) VALUES ('register_data', json(?));`);

export function getToken() {
	try {
		return getTokenStatement.get().token;
	} catch (err) {
		console.log(err);
		return null;
	}
}

export function registerAgent(data) {
	try {
		registerAgentStatement.run(JSON.stringify(data));
		return true;
	} catch (err) {
		console.log(err);
		return false;
	}
}