27 lines
657 B
JavaScript
27 lines
657 B
JavaScript
"use strict";
|
|
|
|
const Track = require('./track');
|
|
|
|
class SqliteBackend {
|
|
constructor(config, db) {
|
|
this.config = config;
|
|
this.db = db;
|
|
}
|
|
|
|
find(tag, callback) {
|
|
this.db.run("INSERT INTO tags (tag) VALUES (?)", tag);
|
|
this.db.get("SELECT uuid, tag, label FROM library 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:
|