Compatibility with recent typescript changes
mindreframer opened this issue · 4 comments
I have following issues when using blinkdb with bun.sh
$ bun run index.ts
SyntaxError: Indirectly exported binding name 'Ids' is not found.
The fix is to export Ids
as from db/remove.ts as type, like here:
export { clear } from "./clear";
export { count } from "./count";
export * from "./createDB";
export * from "./createTable";
export * from "./errors";
export { first } from "./first";
export { insert } from "./insert";
export type { Create } from "./insert";
export { insertMany } from "./insertMany";
export { many } from "./many";
export { one } from "./one";
export { remove } from "./remove";
export type { Ids } from "./remove";
export { removeMany } from "./removeMany";
export { removeWhere } from "./removeWhere";
export { update } from "./update";
export type { Diff } from "./update";
export { updateMany } from "./updateMany";
export { updateWhere } from "./updateWhere";
export { upsert } from "./upsert";
export { upsertMany } from "./upsertMany";
export * from "./use";
export * from "./uuid";
export * from "./watch";
The other issue is with BTree, that I have posted here:
Not sure, if it's would require code changes in Blinkdb to make it work with bun.sh.
The type issues are not specific to Bun, types used in exported BlinkDB methods should be exported as well. Oversight on my part.
I'll try and see if I can resolve the BTree issue.
Found the cause. BlinkDB uses a "module"
key as per the module resolution proposal here, which causes Bun to resolve the module differently. Since the JS Ecosystem has apparently never accepted the proposal above and instead moved on to package exports instead, I've removed the module key & will implement the export system as needed.
(And apparently BlinkDB types like Ids
, Diff
& Create
are already exported: https://github.com/blinkdb-js/blinkdb/blob/main/packages/db/src/core/index.ts)
I've pushed up a new version of BlinkDB that fixes these issues, and which works for your repository on my local machine. Can you verify on your end?
@froehlichA It works! Thanks for the super-quick response.
I will play with BlinkDB a bit more, it's a really well-structured codebase! Any plans to make the insertMany / updateMany functions faster?
This is what I get in benchmarks:
blinkdb/insert-many.ts --- lokijs is 417.44x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬──────────┬─────────┐
│ (index) │ name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼──────────┼─────────┤
│ 0 │ 'lokijs' │ 203398.47530091717 │ 4916.457699697863 │ '±1.64%' │ 101700 │
│ 1 │ 'blinkdb' │ 487.25611966443955 │ 2052308.7543542264 │ '±4.94%' │ 244 │
└─────────┴───────────┴────────────────────┴────────────────────┴──────────┴─────────┘
blinkdb/upsert-many.ts --- lokijs is 3.87x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬──────────┬─────────┐
│ (index) │ name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼──────────┼─────────┤
│ 0 │ 'lokijs' │ 1633.0642639853138 │ 612345.7735579922 │ '±4.32%' │ 817 │
│ 1 │ 'blinkdb' │ 421.87318580370237 │ 2370380.5637585605 │ '±7.20%' │ 211 │
└─────────┴───────────┴────────────────────┴────────────────────┴──────────┴─────────┘
blinkdb/update.ts --- lokijs is 3.34x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬───────────┬─────────┐
│ (index) │ name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼───────────┼─────────┤
│ 0 │ 'lokijs' │ 268725.01220459485 │ 3721.2762287964697 │ '±4.79%' │ 134364 │
│ 1 │ 'blinkdb' │ 80449.77230128765 │ 12430.115976648878 │ '±20.82%' │ 40354 │
└─────────┴───────────┴────────────────────┴────────────────────┴───────────┴─────────┘
The difference for inserts is quite unusual. And since we need to restore the application state on bootstrap, this might increase the app loading time significantly. But I would need to play with some realistic datasets before making further conclusions.
Anyways, thanks again for the quick fix and have a great Sunday!
Thanks for bringing the issue with bun to my attention in the first place :)
insertMany
is weird. I expect it to be slower than inserting into an array, since blinkDB is optimized for reads, but not that slow. I'll create a new issue & take a look at it.