Moved eveything related to the api to a seperate folder seasoned_api.
This commit is contained in:
15
seasoned_api/src/database/database.js
Normal file
15
seasoned_api/src/database/database.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
const SqliteDatabase = require('src/database/sqliteDatabase');
|
||||
const database = new SqliteDatabase(configuration.get('database', 'host'));
|
||||
|
||||
/**
|
||||
* This module establishes a connection to the database
|
||||
* specified in the confgiuration file. It tries to setup
|
||||
* the required tables after successfully connecting.
|
||||
* If the tables already exists, it simply proceeds.
|
||||
*/
|
||||
Promise.resolve()
|
||||
.then(() => database.connect())
|
||||
// .then(() => database.setUp());
|
||||
|
||||
module.exports = database;
|
||||
32
seasoned_api/src/database/sqliteDatabase.js
Normal file
32
seasoned_api/src/database/sqliteDatabase.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3');
|
||||
|
||||
class SqliteDatabase {
|
||||
|
||||
constructor(host) {
|
||||
this.host = host;
|
||||
this.connection = sqlite3;
|
||||
|
||||
// this.schemaDirectory = path.join(__dirname, 'schemas');
|
||||
}
|
||||
|
||||
connect() {
|
||||
return Promise.resolve()
|
||||
.then(() => new sqlite3.Database(this.host))
|
||||
}
|
||||
|
||||
all(sql, parameters) {
|
||||
return this.connection.all(sql, parameters);
|
||||
}
|
||||
|
||||
get(sql, parameters) {
|
||||
return this.connection.get(sql, parameters);
|
||||
}
|
||||
|
||||
run(sql, parameters) {
|
||||
return this.connection.run(sql, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SqliteDatabase;
|
||||
Reference in New Issue
Block a user