Comments (6)
Ugh, this works better than I expected. Now subleveldown
can just forward operations to a db, without unwrapping or rewrapping that db with encoding-down
or levelup
. Doesn't matter what encoding options that db used, or whether it stores data as buffers or Uint8Array internally. On the subleveldown
db you can use any encoding too, including Uint8Array even though subleveldown
internally works with Buffers and strings. It just fucking works.
The following tests are passing (locally; haven't pushed yet):
Click to expand
const test = require('tape')
const suite = require('abstract-leveldown/test')
const memdown = require('memdown')
const subleveldown = require('subleveldown')
// Test abstract-leveldown compliance
function runSuite (factory) {
suite({ test, factory })
}
// Test basic prefix
runSuite(function factory (opts) {
return subleveldown(memdown(), 'test', opts)
})
// Test empty prefix
runSuite(function factory (opts) {
return subleveldown(memdown(), '', opts)
})
// Test custom separator
runSuite(function factory (opts) {
return subleveldown(memdown(), 'test', { ...opts, separator: '%' })
})
// Test on db with buffer encoding
runSuite(function factory (opts) {
return subleveldown(memdown({ keyEncoding: 'buffer' }), 'test', opts)
})
// Test on db with view encoding (Uint8Array)
runSuite(function factory (opts) {
return subleveldown(memdown({ keyEncoding: 'view' }), 'test', opts)
})
// Have memdown internally use views too
runSuite(function factory (opts) {
return subleveldown(memdown({ keyEncoding: 'view', storeEncoding: 'view' }), 'test', opts)
})
// Lastly, for good measure:
runSuite(function factory (opts) {
return subleveldown(memdown({ keyEncoding: 'buffer', storeEncoding: 'view' }), 'test', opts)
})
@ralphtheninja @juliangruber @MeirionHughes ARE YOU EXCITED? Because I am! Fuck!
from community.
Sounds like this gets us a lot of flexibility and api simplicity as well. Well done! 👏
from community.
Added support of other ecosystem encodings (codecs
, abstract-encoding
, multiformats
) to level-transcoder
, fixed some bugs, and updated its README: https://github.com/Level/transcoder. That part is now done.
from community.
Updated the above with a more complete plan, that removes the need for serialization and asBuffer
options, and also paves the way for typed arrays.
Example of a transcoder (some should be hardcoded to optimize them, others like json+buffer
can be dynamic):
exports['utf8+view'] = new Encoding({
encode (data) {
return ArrayBuffer.isView(data) ? data : textEncoder.encode(data)
},
decode (data) {
return textDecoder.decode(data)
},
type: 'utf8+view',
format: 'view'
})
from community.
Doing this in abstract-leveldown
could have performance benefits too. For example, if we know that a particular value encoding on a get()
operation is idempotent (like buffer
or utf8
) and we know that the implementation supports that encoding "natively", then we can do _get(..., callback)
without wrapping the callback in another function that decodes the value.
from community.
https://github.com/Level/transcoder
from community.
Related Issues (20)
- Proposal: add map method to abstract-down HOT 4
- Add `db.getMany(keys)` across the board HOT 8
- `rocksdb`: to be ported from `leveldown` (after other recent PRs)
- Fix Typings on DefinitelyTyped HOT 7
- Proposal: Add `db.has(key)` and `db.hasMany(keys)` HOT 12
- Deprecate old modules
- Package level with electron HOT 2
- Redisdown: how to create new `level-` libs? HOT 1
- Replace Sauce Labs with Playwright HOT 3
- Tracking issue: implicit and explicit snapshots
- willing to help revive some databases with abstract-level api HOT 4
- rocks-level implementation HOT 6
- Switch to dependabot HOT 9
- Dump Buffer for TypedArrays (for compactness and efficiency) HOT 6
- Any interest in maintaining 'lmdb'? HOT 3
- Counting entries in a level database HOT 4
- leveldown to remote database HOT 1
- Maintenance round: drop legacy features & runtime environments HOT 1
- Move to GitHub Actions HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from community.