Skip to content

Commit

Permalink
Manage opening database
Browse files Browse the repository at this point in the history
This allows us to only specify a path in the constructor.
  • Loading branch information
haykam821 committed Sep 5, 2018
1 parent 26b6419 commit 9b016b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/Snooful/SQLite-Storage#readme",
"dependencies": {
"@snooful/settings-base": "^1.0.1"
"@snooful/settings-base": "^1.0.1",
"sqlite": "^3.0.0"
}
}
}
17 changes: 13 additions & 4 deletions settings.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const base = require("@snooful/settings-base");
const sqlite = require("sqlite");

/**
* Manages settings.
*/
class SQLiteSettingsManager extends base.BaseSettingsManager {
/**
* @param {SQLiteDatabase} database The database to store settings in.
* @param {string} databasePath The path to the database to store settings in.
*/
constructor(database) {
this.database = database;
this.init();
constructor(databasePath) {
super();

/**
* The settings cache.
*/
this.settings = {};

this.setStatement = null;

// Open the database and init
sqlite.open(databasePath).then(database => {
base.debug("opened settings database");

this.database = database;
this.init();
});

}

/**
Expand Down

0 comments on commit 9b016b3

Please sign in to comment.