aboutsummaryrefslogtreecommitdiff
path: root/db/db.ts
diff options
context:
space:
mode:
Diffstat (limited to 'db/db.ts')
-rw-r--r--db/db.ts22
1 files changed, 12 insertions, 10 deletions
diff --git a/db/db.ts b/db/db.ts
index 7bb315c..ed38dd6 100644
--- a/db/db.ts
+++ b/db/db.ts
@@ -47,7 +47,7 @@ interface DBFindResult {
* const results = db.findTerm("なった");
*/
export default class DB {
- private connection: Database;
+ private connection: Database = new Database(":memory:", { create: false });
public ready: Promise<void>;
private here = path.dirname(path.fromFileUrl(import.meta.url));
private paths = {
@@ -59,22 +59,19 @@ export default class DB {
find: path.resolve(this.here, 'find.sql'),
},
} as const;
- private statement: {
- attach: Statement;
- queryTerm: Statement;
- };
+ private statement = {
+ attach: this.connection.prepare("attach database ? as ?"),
+ queryTerm: this.connection.prepare(""),
+ termPriority: this.connection.prepare(""),
+ } satisfies { [name: string]: Statement };
constructor() {
- this.connection = new Database(":memory:", { create: false });
- this.statement = {
- attach: this.connection.prepare("attach database ? as ?"),
- queryTerm: this.connection.prepare(""),
- };
this.attach(this.paths.db.dict, 'dict');
this.attach(this.paths.db.user, 'user');
this.ready = new Promise<void>(async resolve => {
const statement = await Deno.readTextFile(this.paths.query.find);
this.statement.queryTerm = this.connection.prepare(statement);
+ this.statement.termPriority = this.connection.prepare("insert into sort_overlay (user_id, expression, reading, sort) values (?, ?, ?, ?)");
resolve();
});
}
@@ -104,4 +101,9 @@ export default class DB {
});
return terms;
}
+
+ async termPriority(userID: number, expression: string, reading: string, priority: number) {
+ await this.ready;
+ this.statement.termPriority.run(userID, expression, reading, priority);
+ }
};