Skip to content
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

feat(apps/whale-api): add dumpdb #2172

Merged
merged 11 commits into from
Dec 5, 2023
Prev Previous commit
Next Next commit
dumpdb with drain check
canonbrother committed Nov 23, 2023
commit c5a07c9f68830d510c345c9747c9e14b2896108f
Original file line number Diff line number Diff line change
@@ -32,15 +32,24 @@ export abstract class LevelUpDatabase extends Database {
csv.pipe(writer)

return await new Promise((resolve, reject) => {
this.root.createReadStream({ keyAsBuffer: false, valueAsBuffer: false })
console.time('dumpdb done in: ')
this.root.createReadStream() // query stream
.on('data', function (data) {
csv.write(data)
void (async () => {
const ok = csv.write(data)
if (!ok) {
await new Promise((resolve) => {
csv.once('drain', resolve)
})
}
})()
}).on('error', function (err) {
reject(err)
}).on('close', function () {
reject(new Error('stream closed'))
}).on('end', function () {
resolve(csv.end())
console.timeEnd('dumpdb done in: ')
})
})
}