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

24 lines
511 B
JavaScript

"use strict";
class SqliteBackend {
constructor(config, db) {
this.config = config;
this.db = db;
}
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);
};
// vim:ts=2 sw=2 et: