Add more logging to sqlite backend

This commit is contained in:
Annika Backstrom 2019-12-17 13:39:18 -05:00
parent 14d915fb7c
commit c0e2ab0129
2 changed files with 7 additions and 4 deletions

View File

@ -3,24 +3,27 @@
const Track = require('./track');
class SqliteBackend {
constructor(config, db) {
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) {
return new SqliteBackend(config, db);
module.exports = function(config, db, logger) {
return new SqliteBackend(config, db, logger);
};
// vim:ts=2 sw=2 et:

View File

@ -45,7 +45,7 @@ const play_log = require('./jukebox/library/play-log');
const sqlite3 = require('sqlite3');
var db = new sqlite3.Database(config.db);
const MediaLibrarySqliteBackend = require('./jukebox/library/sqlite-backend')(config, db);
const MediaLibrarySqliteBackend = require('./jukebox/library/sqlite-backend')(config, db, logger);
const MediaLibrary = new library.Library(config, MediaLibrarySqliteBackend);
const PlayLog = new play_log.PlayLog();