pi-rfid-jukebox/jukebox/library/sqlite-backend.js

24 lines
511 B
JavaScript
Raw Normal View History

2019-12-15 02:11:21 +00:00
"use strict";
class SqliteBackend {
constructor(config, db) {
2019-12-15 02:11:21 +00:00
this.config = config;
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']);
});
}
}
module.exports = function(config, db) {
return new SqliteBackend(config, db);
2019-12-15 02:11:21 +00:00
};
// vim:ts=2 sw=2 et: