Add sqlite3 library backend
This commit is contained in:
parent
9576373dbf
commit
5782510af1
2
Vagrantfile
vendored
2
Vagrantfile
vendored
@ -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
1
create.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE tags(uuid TEXT PRIMARY KEY, tag TEXT);
|
27
jukebox/library/sqlite-backend.js
Normal file
27
jukebox/library/sqlite-backend.js
Normal 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:
|
@ -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"
|
||||||
},
|
},
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user