forked from jpchip/giveaway-grabber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apologies if this PR is a duplicate of jpchip#80 but I was not sure if the requested changes would be made after a month. Couldn't contribut to Kyptonova's branch due to restrictions. The original PR was good, but made changes according to the reviews and used some more ES7 syntax. From the original PR: Creates a database for tracking sweepstakes entries. After sweepstakes are entered, it will skip checking it in the future. This will prevent unnecessary hops between the main screen and individual sweepstakes. The thought being that this will cut down on login page requests and CAPTCHAs. Addresses jpchip#74.
- Loading branch information
Showing
8 changed files
with
317 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules/ | |
/eng.traineddata | ||
.ggrc.json | ||
user_data/ | ||
.vscode | ||
gg.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//Code borrowed from example found at https://www.scriptol.com/sql/sqlite-async-await.php | ||
const sqlite3 = require('sqlite3').verbose(); | ||
var db; | ||
|
||
/** | ||
* Creates or opens existing database. | ||
* @param path Database location | ||
* @returns {Promise<string>} | ||
*/ | ||
const open = path => | ||
new Promise(resolve => { | ||
this.db = new sqlite3.Database(path, err => { | ||
if (err) reject('Open error: ' + err.message); | ||
else resolve(path + ' opened'); | ||
}); | ||
}); | ||
|
||
/** | ||
* Used for insert, delete, or update queries. | ||
* @param query Query that should be executed. | ||
* @param params Array of paramaters of the query. | ||
* @returns {Promise<void>} | ||
*/ | ||
const run = (query, params) => | ||
new Promise((resolve, reject) => { | ||
this.db.run(query, params, err => { | ||
if (err) reject(err.message); | ||
else resolve(true); | ||
}); | ||
}); | ||
|
||
/** | ||
* Read the first row from a Select query. | ||
* @param query The select statement that should be processed. | ||
* @returns {Promise<void>} | ||
*/ | ||
const get = (query, params) => | ||
new Promise((resolve, reject) => { | ||
this.db.get(query, params, (err, row) => { | ||
if (err) reject('Read error: ' + err.message); | ||
else { | ||
resolve(row); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* Read all rows that match the query. | ||
* @param query Query that should be executed. | ||
* @param params Array of parameters to be used with supplied query. | ||
* @returns {Promise<void>} | ||
*/ | ||
const all = (query, params) => | ||
new Promise((resolve, reject) => { | ||
if (params == undefined) params = []; | ||
|
||
this.db.all(query, params, (err, rows) => { | ||
if (err) reject('Read error: ' + err.message); | ||
else { | ||
resolve(rows); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* Each row returned one by one | ||
* @param query Query that should be executed. | ||
* @param params Array of parameters to be used with supplied query. | ||
* @param action Call back function used to process results. | ||
* @returns {Promise<void>} | ||
*/ | ||
const each = (query, params, action) => | ||
new Promise((resolve, reject) => { | ||
var db = this.db; | ||
db.serialize(() => { | ||
db.each(query, params, (err, row) => { | ||
if (err) reject('Read error: ' + err.message); | ||
else { | ||
if (row) { | ||
action(row); | ||
} | ||
} | ||
}); | ||
db.get('', (err, row) => { | ||
resolve(true); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* Closes existing database. | ||
* @param path Database location | ||
* @returns {Promise<void>} | ||
*/ | ||
const close = () => | ||
new Promise((resolve, reject) => { | ||
this.db.close(); | ||
resolve(true); | ||
}); | ||
|
||
module.exports = { | ||
db, | ||
open, | ||
run, | ||
get, | ||
all, | ||
each, | ||
close | ||
}; |
Oops, something went wrong.