30 lines
801 B
JavaScript
30 lines
801 B
JavaScript
"use strict";
|
|
|
|
const Track = require('./track');
|
|
|
|
class SqliteBackend {
|
|
constructor(config, db, logger) {
|
|
this.config = config;
|
|
this.db = db;
|
|
this.logger = logger;
|
|
}
|
|
|
|
find(tag, callback) {
|
|
this.db.run("INSERT INTO tags (tag) VALUES (?)", tag);
|
|
this.db.get("SELECT uuid, tag, label FROM library WHERE tag = ? ORDER BY RANDOM() LIMIT 1", tag, (err, row) => {
|
|
if (typeof row === 'undefined') {
|
|
this.logger.debug("no matching tag in sqlite backend", { tag: tag });
|
|
return callback();
|
|
}
|
|
this.logger.debug("found a matching tag", { tag: tag });
|
|
callback(new Track(row['tag'], row['uuid'], row['label']));
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = function(config, db, logger) {
|
|
return new SqliteBackend(config, db, logger);
|
|
};
|
|
|
|
// vim:ts=2 sw=2 et:
|