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

26 lines
595 B
JavaScript

"use strict";
const Track = require('./track');
class SqliteBackend {
constructor(config, db) {
this.config = config;
this.db = db;
}
find(tag, callback) {
this.db.get("SELECT uuid, tag, label 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(new Track(row['tag'], row['uuid'], row['label']));
});
}
}
module.exports = function(config, db) {
return new SqliteBackend(config, db);
};
// vim:ts=2 sw=2 et: