-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LAM-1169 feat: cache configs to disk #1190
base: dev
Are you sure you want to change the base?
Conversation
b60ac56
to
fa6c436
Compare
75104d2
to
54ce796
Compare
79eb3ac
to
bce5003
Compare
lib/sqlite.js
Outdated
exports.withDB = db => proc => db.then(proc) | ||
|
||
exports.all = withDB => (...args) => withDB(db => db.all(...args)) | ||
exports.get = withDB => (...args) => withDB(db => db.get(...args)) | ||
exports.run = withDB => (...args) => withDB(db => db.run(...args)) | ||
|
||
exports.withTx = withDB => proc => withDB(db => new Promise((resolve, reject) => | ||
db.getDatabaseInstance().serialize(() => | ||
db.run("BEGIN TRANSACTION") | ||
.then(_ => proc(db)) | ||
.then(ret => db.run("COMMIT TRANSACTION").then(_ => resolve(ret))) | ||
.catch(err => { | ||
db.run("ROLLBACK TRANSACTION").then(()=>{},()=>{}) | ||
reject(err) | ||
}) | ||
) | ||
)) | ||
|
||
exports.helpers = dbPromise => { | ||
const withDB = exports.withDB(dbPromise) | ||
const all = exports.all(withDB) | ||
const get = exports.get(withDB) | ||
const run = exports.run(withDB) | ||
const withTx = exports.withTx(withDB) | ||
return { withDB, all, get, run, withTx } | ||
} | ||
|
||
const repeat = (n, x) => Array(n).fill(x) | ||
exports.makeTuple = n => '(' + repeat(n, '?').join(',') + ')' | ||
exports.makeValues = (nColumns, nRows) => repeat(nRows, exports.makeTuple(nColumns)).join(',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused with all of the exports, most of them are not really being used anywhere and it makes an awkward read.
I'm also failing to understand the benefit of everything being 'factory' based when it uses the exact same db object anyways. Why not just do db.saveCoins
(or whatever queries) on lssettings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all
/get
/run
were used at some point, until I switched to withTx
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RE factory based: if you mean the helpers()
it's for usage-convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another more general thing. This would benefit from having a separate folder under lib, either /db
, /settings
, /config
or something in this vein. We can then have a pretty closed module.
Would be good to add testing for this as well, you can use vitest
, maybe will have to search on how to use vitest without vite.
And remove explicit return to more closely resemble `clearTimeout()`/`clearInterval()`.
No description provided.