aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-13 16:39:01 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-13 16:39:01 +0200
commit28fb362147358819afeb0f0a5fa7a4ad136499ac (patch)
tree4c4224f503f66fcea1e25b464daf0f9659a09bab /db
parent919cdce6bcf12f564901ea536dae4227d025b031 (diff)
ignore terms
Diffstat (limited to 'db')
-rw-r--r--db/db.ts22
-rw-r--r--db/makefile2
-rw-r--r--db/user/init.sql5
3 files changed, 18 insertions, 11 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);
+ }
};
diff --git a/db/makefile b/db/makefile
index 88d4bba..3968ae7 100644
--- a/db/makefile
+++ b/db/makefile
@@ -32,7 +32,7 @@ dict/dict.sql: $(DEFAULT_DICTS)
user/base.sql: user/reset.sql user/init.sql
cat $^ > $@
-user/full.sql: user/base.sql user/root.sql
+user/full.sql: user/base.sql # user/root.sql
cat $^ > $@
%.sql: %.dict.sql $(DICT_TEMPLATE)
diff --git a/db/user/init.sql b/db/user/init.sql
index 1d0e830..af60fa3 100644
--- a/db/user/init.sql
+++ b/db/user/init.sql
@@ -4,6 +4,8 @@ create table if not exists user (
unique(username)
);
+insert into user (id, username) values (0, 'root');
+
create table if not exists sort_overlay (
id integer primary key autoincrement,
user_id int not null default 0,
@@ -14,3 +16,6 @@ create table if not exists sort_overlay (
unique(user_id, expression, reading) on conflict replace
);
+create index sort_overlay_expression on sort_overlay (expression);
+create index sort_overlay_reading on sort_overlay (reading);
+