54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
"use strict";
|
|
/**
|
|
* SessionRepository — CRUD for sessions table.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.SessionRepository = void 0;
|
|
class SessionRepository {
|
|
constructor(db) {
|
|
this.db = db;
|
|
}
|
|
create(params) {
|
|
this.db
|
|
.prepare(`INSERT INTO sessions (id, url, status, seed, max_states, started_at, config_json)
|
|
VALUES (?, ?, 'running', ?, ?, ?, ?)`)
|
|
.run(params.id, params.url, params.seed, params.maxStates, params.startedAt, params.configJson ?? '{}');
|
|
}
|
|
findById(id) {
|
|
return this.db
|
|
.prepare('SELECT * FROM sessions WHERE id = ?')
|
|
.get(id);
|
|
}
|
|
findAll() {
|
|
return this.db.prepare('SELECT * FROM sessions ORDER BY started_at DESC').all();
|
|
}
|
|
update(id, fields) {
|
|
const sets = [];
|
|
const values = [];
|
|
if (fields.status !== undefined) {
|
|
sets.push('status = ?');
|
|
values.push(fields.status);
|
|
}
|
|
if (fields.statesVisited !== undefined) {
|
|
sets.push('states_visited = ?');
|
|
values.push(fields.statesVisited);
|
|
}
|
|
if (fields.anomaliesFound !== undefined) {
|
|
sets.push('anomalies_found = ?');
|
|
values.push(fields.anomaliesFound);
|
|
}
|
|
if (fields.finishedAt !== undefined) {
|
|
sets.push('finished_at = ?');
|
|
values.push(fields.finishedAt);
|
|
}
|
|
if (sets.length === 0)
|
|
return;
|
|
values.push(id);
|
|
this.db.prepare(`UPDATE sessions SET ${sets.join(', ')} WHERE id = ?`).run(...values);
|
|
}
|
|
delete(id) {
|
|
this.db.prepare('DELETE FROM sessions WHERE id = ?').run(id);
|
|
}
|
|
}
|
|
exports.SessionRepository = SessionRepository;
|