Skip to content

Commit

Permalink
Fix remaining ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Nov 10, 2018
1 parent da1b975 commit 4376724
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,31 @@ class SQLiteSettingsManager extends base.SettingsManager {
* Initializes the database.
*/
async init() {
await this.database.run("CREATE TABLE IF NOT EXISTS settings (subreddit VARCHAR(20) PRIMARY KEY, settings TEXT)").then(() => {
base.debug("ensured the settings table exists");
});
try {
await this.database.run("CREATE TABLE IF NOT EXISTS settings (subreddit VARCHAR(20) PRIMARY KEY, settings TEXT)").then(() => {
base.debug("ensured the settings table exists");
});

const rows = this.database.all("SELECT CAST(subreddit as TEXT) as subreddit, settings FROM settings").then(rows => {
base.debug("got rows of settings");
rows.forEach(row => {
base.debug("caching settings for r/%s", row.subreddit);
this.settings[row.subreddit] = JSON.parse(row.settings);
this.database.all("SELECT CAST(subreddit as TEXT) as subreddit, settings FROM settings").then(rows => {
base.debug("got rows of settings");
rows.forEach(row => {
base.debug("caching settings for r/%s", row.subreddit);
this.settings[row.subreddit] = JSON.parse(row.settings);
});
});
});

this.database.prepare("INSERT OR REPLACE INTO settings VALUES(?, ?)").then(statement => {
base.debug("prepared the set statement");
this.setStatement = statement;
});
this.database.prepare("INSERT OR REPLACE INTO settings VALUES(?, ?)").then(statement => {
base.debug("prepared the set statement");
this.setStatement = statement;
});

return true;
} catch (error) {
return false;
}
}

async update(subreddit) {
update(subreddit) {
base.debug(`updating settings database for r/${subreddit}`);
return this.setStatement.run(subreddit, JSON.stringify(this.settings[subreddit]));
}
Expand Down

0 comments on commit 4376724

Please sign in to comment.