Level / level

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

You can't save Classes #166

Closed Mwexim closed 4 years ago

Mwexim commented 4 years ago

When you want to save classes to a level storage, it simply doesn't save.

Maybe you can apply a fix for this/another solution?

And if this is valid, maybe state it on the main page?

To reproduce:

// I know, not the best example
const level = require('level');
const db = level('pathtostorage')

class AnyClass {}
var myclass = new AnyClass()
db.put('test', myclass)
db.put('test2', "Test"

When you'd get all the values in the storage, it will only get the second one, the first one isn't even added.

Maybe I'm wrong...

vweevers commented 4 years ago

You can save objects by using the json encoding:

const level = require('level')
const db = level('my-db', { valueEncoding: 'json' })

await db.put('test', { foo: 123 })
Mwexim commented 4 years ago

Now I have a problem with the streams: when I do createValueStream().on('data', data => console.log(data)), it logs 'null', but when I get it with the get() method, it works. .

vweevers commented 4 years ago

Can you share a complete code example?