Skip to content

Commit

Permalink
update sqlite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani committed Jul 3, 2024
1 parent 381d249 commit 1352785
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions plugins/filters/sqlite/filter_sqlite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
PASTASH SQLITE Filter w/ better-sqlite3
/*
PASTASH SQLITE Filter
*/

var base_filter = require('@pastash/pastash').base_filter,
Expand Down Expand Up @@ -27,7 +27,8 @@ FilterSqlite.prototype.start = function(callback) {

if (this.db) {
try {
sqdb = new sqlite3(this.db);
this.db = new sqlite3(this.db);
this.db.pragma('cache_size = 0');
logger.info('Initializing Filter Sqlite3:',this.db);
} catch(e){ logger.error('Failed Initializing Filter Sqlite3',e); }
}
Expand All @@ -36,23 +37,22 @@ FilterSqlite.prototype.start = function(callback) {
};

FilterSqlite.prototype.process = function(raw) {
if (!sqdb||!this.query) return raw;
if (!this.query) return raw;
if (!this.source_field && !this.filter) return raw;

try {

this.filter = raw[this.source_field];
if (this.db) {
let row = sqdb.prepare(this.query).get(this.filter);
if (!row) this.emit('output', raw);
else {
raw[this.target_field] = row;
this.emit('output', raw);
}

const row = this.db.prepare(this.query).get(this.filter);
if (!row) this.emit('output', raw);
else {
raw[this.target_field] = row[this.target_field];
this.emit('output', raw);
}

} else { return raw; }
} catch(e) { logger.info('failed processing sqlite!',e); return raw; }

};

FilterSqlite.prototype.close = function(callback) {
Expand Down

0 comments on commit 1352785

Please sign in to comment.