mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-09-20 04:54:00 +02:00
Support regex via sqlite
This commit is contained in:
parent
733bd338e7
commit
9e86f463d8
1 changed files with 9 additions and 1 deletions
|
@ -15,7 +15,7 @@ export class Sqlite implements IDatabase {
|
|||
// eslint-disable-next-line require-await
|
||||
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any[]> {
|
||||
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
|
||||
const preparedQuery = this.db.prepare(query);
|
||||
const preparedQuery = this.db.prepare(Sqlite.processQuery(query));
|
||||
|
||||
switch (type) {
|
||||
case "get": {
|
||||
|
@ -53,6 +53,10 @@ export class Sqlite implements IDatabase {
|
|||
Sqlite.upgradeDB(this.db, this.config.fileNamePrefix, this.config.dbSchemaFolder);
|
||||
}
|
||||
|
||||
this.db.function("regexp", { deterministic: true }, (regex: string, str: string) => {
|
||||
return str.match(regex) ? 1 : 0;
|
||||
});
|
||||
|
||||
// Enable WAL mode checkpoint number
|
||||
if (this.config.enableWalCheckpointNumber) {
|
||||
this.db.exec("PRAGMA journal_mode=WAL;");
|
||||
|
@ -67,6 +71,10 @@ export class Sqlite implements IDatabase {
|
|||
this.db.prepare(`ATTACH ? as ${attachAs}`).run(database);
|
||||
}
|
||||
|
||||
private static processQuery(query: string): string {
|
||||
return query.replace(/ ~\* /g, " REGEXP ");
|
||||
}
|
||||
|
||||
private static upgradeDB(db: Database, fileNamePrefix: string, schemaFolder: string) {
|
||||
const versionCodeInfo = db.prepare("SELECT value FROM config WHERE key = ?").get("version");
|
||||
let versionCode = versionCodeInfo ? versionCodeInfo.value : 0;
|
||||
|
|
Loading…
Reference in a new issue