2019-12-15 02:11:21 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class SqliteBackend {
|
2019-12-15 16:50:53 +00:00
|
|
|
constructor(config, db) {
|
2019-12-15 02:11:21 +00:00
|
|
|
this.config = config;
|
2019-12-15 16:50:53 +00:00
|
|
|
this.db = db;
|
2019-12-15 02:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
find(tag, callback) {
|
|
|
|
this.db.get("SELECT uuid FROM tags WHERE tag = ? AND _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM tags)) LIMIT 1", tag, (err, row) => {
|
|
|
|
if (typeof row === 'undefined') {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
callback(row['uuid']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 16:50:53 +00:00
|
|
|
module.exports = function(config, db) {
|
|
|
|
return new SqliteBackend(config, db);
|
2019-12-15 02:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:ts=2 sw=2 et:
|