Moved the nodejs agent to its own subfolder to make room for my haskell agent
This commit is contained in:
parent
0bc0df0891
commit
36cc33f9e9
22 changed files with 0 additions and 0 deletions
19
nodejs/database/surveys.js
Normal file
19
nodejs/database/surveys.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import db from './db.js';
|
||||
|
||||
const deleteExpiredSurveysStatement = db.prepare(`DELETE FROM surveys WHERE data->>'expiration' < ?;`);
|
||||
const getSurveysStatement = db.prepare(`SELECT data FROM surveys WHERE data->>'symbol' = ?;`);
|
||||
const setSurveysStatement = db.prepare(`INSERT INTO surveys(data) VALUES (json(?));`);
|
||||
|
||||
export function deleteExpired() {
|
||||
return deleteExpiredSurveysStatement.run(new Date().toISOString()).changes;
|
||||
}
|
||||
|
||||
export function get(symbol) {
|
||||
deleteExpired();
|
||||
return getSurveysStatement.all(symbol);
|
||||
}
|
||||
|
||||
export function set(survey) {
|
||||
deleteExpired();
|
||||
return setSurveysStatement.run(JSON.stringify(survey));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue