Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/core/models/CommandsTable.ts
1028 views
1
import ICommandMeta from '@secret-agent/interfaces/ICommandMeta';
2
import { Database as SqliteDatabase, Statement } from 'better-sqlite3';
3
import SqliteTable from '@secret-agent/commons/SqliteTable';
4
import TypeSerializer from '@secret-agent/commons/TypeSerializer';
5
6
export default class CommandsTable extends SqliteTable<ICommandMeta> {
7
private readonly getQuery: Statement;
8
constructor(readonly db: SqliteDatabase) {
9
super(
10
db,
11
'Commands',
12
[
13
['id', 'INTEGER', 'NOT NULL PRIMARY KEY'],
14
['tabId', 'INTEGER'],
15
['frameId', 'INTEGER'],
16
['name', 'TEXT'],
17
['wasPrefetched', 'INTEGER'],
18
['args', 'TEXT'],
19
['clientStartDate', 'INTEGER'],
20
['clientSendDate', 'INTEGER'],
21
['runStartDate', 'INTEGER'],
22
['endDate', 'INTEGER'],
23
['result', 'TEXT'],
24
['resultType', 'TEXT'],
25
],
26
true,
27
);
28
this.getQuery = db.prepare(`select * from ${this.tableName} where id = ? limit 1`);
29
this.defaultSortOrder = 'id ASC';
30
}
31
32
public insert(commandMeta: ICommandMeta) {
33
this.queuePendingInsert([
34
commandMeta.id,
35
commandMeta.tabId,
36
commandMeta.frameId,
37
commandMeta.name,
38
commandMeta.wasPrefetched ? 1 : 0,
39
commandMeta.args,
40
commandMeta.clientStartDate,
41
commandMeta.clientSendDate,
42
commandMeta.runStartDate,
43
commandMeta.endDate,
44
TypeSerializer.stringify(commandMeta.result),
45
commandMeta.result?.constructor
46
? commandMeta.result.constructor.name
47
: typeof commandMeta.result,
48
]);
49
}
50
51
public get(id: number) {
52
return this.getQuery.get(id) as ICommandMeta;
53
}
54
}
55
56