Level / level

Universal abstract-level database for Node.js and browsers.
MIT License
1.55k stars 106 forks source link

Can this be used to polyfill IndexedDB on Node? #206

Closed brianjenkins94 closed 2 years ago

brianjenkins94 commented 3 years ago

Context: https://github.com/arthurhsu/lovefield-ts/issues/20

Does a compatibility layer exist that would allow LevelDB to serve as a drop-in replacement for IndexedDB?

brianjenkins94 commented 3 years ago

Further research suggests it wouldn't be a drop-in replacement since LevelDB doesn't support transactions without cshum/level-transactions which doesn't share the same transaction interface as IndexedDB.

brianjenkins94 commented 3 years ago

Okay I think I get it now.

LevelDB is not interchangeable with IndexedDB.

But targeting Level/abstract-leveldown would enable me to use LevelDB and IndexedDB as interchangeable backstores.

Maybe naming all these things /(?:abstract-)?level(?:up|down|-?js)/i wasn't the most practical thing to do...

vweevers commented 3 years ago

But targeting Level/abstract-leveldown would enable me to use LevelDB and IndexedDB as interchangeable backstores.

This is what level does. In Node.js it uses LevelDB for storage, and in browsers it uses IndexedDB (and I don't consider that an ideal choice; IndexedDB lacks primitives for proper backpressure on streams which are a key concept in Level). Building an IndexedDB API on top of level feels backwards to me and as you realized, isn't 100% possible for lack of transactions.

Maybe naming all these things /(?:abstract-)?level(?:up|down|-?js)/i wasn't the most practical thing to do...

I hear you. This ecosystem grew over a 10-year timespan with a fair amount of experimentation, people and ideas.