Merge pull request #68 from KevinMidboe/add-metadata-requests
Add metadata requests
This commit is contained in:
@@ -10,6 +10,6 @@ const database = new SqliteDatabase(configuration.get('database', 'host'));
|
|||||||
*/
|
*/
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => database.connect())
|
.then(() => database.connect())
|
||||||
// .then(() => database.setUp());
|
.then(() => database.setUp());
|
||||||
|
|
||||||
module.exports = database;
|
module.exports = database;
|
||||||
|
|||||||
57
seasoned_api/src/database/schemas/setup.sql
Normal file
57
seasoned_api/src/database/schemas/setup.sql
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
|
user_name varchar(127) UNIQUE,
|
||||||
|
password varchar(127),
|
||||||
|
email varchar(127) UNIQUE,
|
||||||
|
primary key (user_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cache (
|
||||||
|
key varchar(255),
|
||||||
|
value blob,
|
||||||
|
time_to_live INTEGER DEFAULT 60,
|
||||||
|
created_at DATE DEFAULT (datetime('now','localtime')),
|
||||||
|
primary key(key)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS search_history (
|
||||||
|
id integer,
|
||||||
|
user_name varchar(127),
|
||||||
|
search_query varchar(255),
|
||||||
|
primary key (id),
|
||||||
|
foreign key(user_name) REFERENCES user(user_name) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS requests(
|
||||||
|
id TEXT,
|
||||||
|
name TEXT,
|
||||||
|
year NUMBER,
|
||||||
|
poster_path TEXT DEFAULT NULL,
|
||||||
|
background_path TEXT DEFAULT NULL,
|
||||||
|
requested_by TEXT,
|
||||||
|
ip TEXT,
|
||||||
|
requested_date DATE DEFAULT CURRENT_DATE NOT NULL,
|
||||||
|
status CHAR(25) DEFAULT 'requested' NOT NULL,
|
||||||
|
user_agent CHAR(255) DEFAULT NULL,
|
||||||
|
type CHAR(50) DEFAULT 'movie'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS stray_eps(
|
||||||
|
id TEXT UNIQUE,
|
||||||
|
parent TEXT,
|
||||||
|
path TEXT,
|
||||||
|
name TEXT,
|
||||||
|
season NUMBER,
|
||||||
|
episode NUMBER,
|
||||||
|
video_files TEXT,
|
||||||
|
subtitles TEXT,
|
||||||
|
trash TEXT,
|
||||||
|
verified BOOLEAN DEFAULT 0,
|
||||||
|
primary key(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS shows(
|
||||||
|
show_names TEXT,
|
||||||
|
date_added DATE,
|
||||||
|
date_modified DATE DEFUALT CURRENT_DATE NOT NULL
|
||||||
|
);
|
||||||
@@ -4,30 +4,80 @@ const sqlite = require('sqlite');
|
|||||||
|
|
||||||
class SqliteDatabase {
|
class SqliteDatabase {
|
||||||
|
|
||||||
constructor(host) {
|
constructor(host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.connection = sqlite;
|
this.connection = sqlite;
|
||||||
|
this.schemaDirectory = path.join(__dirname, 'schemas');
|
||||||
|
}
|
||||||
|
|
||||||
// this.schemaDirectory = path.join(__dirname, 'schemas');
|
/**
|
||||||
}
|
* Connect to the database.
|
||||||
|
* @returns {Promise} succeeds if connection was established
|
||||||
|
*/
|
||||||
|
connect() {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => sqlite.open(this.host))
|
||||||
|
.then(() => sqlite.exec('pragma foreign_keys = on;'));
|
||||||
|
}
|
||||||
|
|
||||||
connect() {
|
/**
|
||||||
return Promise.resolve()
|
* Run a SQL query against the database.
|
||||||
.then(() => sqlite.open(this.host))
|
* @param {String} sql SQL query
|
||||||
.then(() => sqlite.exec('pragma foreign_keys = on;'));
|
* @param {Array} parameters in the SQL query
|
||||||
}
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
run(sql, parameters) {
|
||||||
|
return this.connection.run(sql, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
all(sql, parameters) {
|
/**
|
||||||
return this.connection.all(sql, parameters);
|
* Run a SQL query against the database and retrieve all the rows.
|
||||||
}
|
* @param {String} sql SQL query
|
||||||
|
* @param {Array} parameters in the SQL query
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
all(sql, parameters) {
|
||||||
|
return this.connection.all(sql, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
get(sql, parameters) {
|
/**
|
||||||
return this.connection.get(sql, parameters);
|
* Run a SQL query against the database and retrieve one row.
|
||||||
}
|
* @param {String} sql SQL query
|
||||||
|
* @param {Array} parameters in the SQL query
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
get(sql, parameters) {
|
||||||
|
return this.connection.get(sql, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
run(sql, parameters) {
|
/**
|
||||||
return this.connection.run(sql, parameters);
|
* Run a SQL query against the database and retrieve the status.
|
||||||
}
|
* @param {String} sql SQL query
|
||||||
|
* @param {Array} parameters in the SQL query
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
execute(sql) {
|
||||||
|
return this.connection.exec(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the database by running setup.sql file in schemas/.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
setUp() {
|
||||||
|
const setupSchema = this.readSqlFile('setup.sql');
|
||||||
|
return this.execute(setupSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file contents of a SQL file in schemas/.
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
readSqlFile(filename) {
|
||||||
|
const schemaPath = path.join(this.schemaDirectory, filename);
|
||||||
|
const schema = fs.readFileSync(schemaPath).toString('utf-8');
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SqliteDatabase;
|
module.exports = SqliteDatabase;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class RequestRepository {
|
|||||||
constructor(cache, database) {
|
constructor(cache, database) {
|
||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||||
'fetchRequstedItems': "SELECT * FROM requests",
|
'fetchRequstedItems': "SELECT * FROM requests",
|
||||||
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ class RequestRepository {
|
|||||||
user = 'NULL';
|
user = 'NULL';
|
||||||
console.log(user)
|
console.log(user)
|
||||||
// Add request to database
|
// Add request to database
|
||||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, user, ip, user_agent, movie.type])
|
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, movie.background, user, ip, user_agent, movie.type])
|
||||||
|
|
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
// create reusable transporter object using the default SMTP transport
|
||||||
|
|||||||
Reference in New Issue
Block a user