Add sqlite3 library backend

This commit is contained in:
Annika Backstrom 2019-12-14 21:11:21 -05:00
parent 9576373dbf
commit 5782510af1
5 changed files with 33 additions and 3 deletions

2
Vagrantfile vendored
View File

@ -17,7 +17,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "sudo apt-get update -y" config.vm.provision "shell", inline: "sudo apt-get update -y"
config.vm.provision "shell", inline: "sudo apt-get upgrade -y" config.vm.provision "shell", inline: "sudo apt-get upgrade -y"
config.vm.provision "shell", inline: "sudo apt-get install -y make nodejs npm" config.vm.provision "shell", inline: "sudo apt-get install -y make nodejs npm sqlite3"
end end
# vim:set ts=2 sw=2 et: # vim:set ts=2 sw=2 et:

1
create.sql Normal file
View File

@ -0,0 +1 @@
CREATE TABLE tags(uuid TEXT PRIMARY KEY, tag TEXT);

View File

@ -0,0 +1,27 @@
"use strict";
const sqlite3 = require('sqlite3');
class SqliteBackend {
constructor(config) {
this.config = config;
sqlite3.verbose();
this.db = new sqlite3.Database(this.config.db, sqlite3.OPEN_READONLY);
console.log(this.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) {
return new SqliteBackend(config);
};
// vim:ts=2 sw=2 et:

View File

@ -20,8 +20,10 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"morgan": "^1.7.0", "morgan": "^1.7.0",
"mustache": "^3.1.0", "mustache": "^3.1.0",
"sqlite": "^3.0.3",
"throttle-debounce": "^2.1.0", "throttle-debounce": "^2.1.0",
"utf-8-validate": "^5.0.2", "utf-8-validate": "^5.0.2",
"uuid": "^3.3.3",
"winston": "^3.2.1", "winston": "^3.2.1",
"ws": "^7.2.1" "ws": "^7.2.1"
}, },

View File

@ -5,8 +5,8 @@ const config = require('./config.json')
const views = require('./jukebox/views')(__dirname + '/templates/'); const views = require('./jukebox/views')(__dirname + '/templates/');
const library = require('./jukebox/library'); const library = require('./jukebox/library');
const MediaLibraryFileBackend = require('./jukebox/library/file-backend')(config); const MediaLibrarySqliteBackend = require('./jukebox/library/sqlite-backend')(config);
const MediaLibrary = new library.Library(config, MediaLibraryFileBackend); const MediaLibrary = new library.Library(config, MediaLibrarySqliteBackend);
const ScriptRunner = require('./jukebox/scripts')(config); const ScriptRunner = require('./jukebox/scripts')(config);