Closed phil294 closed 3 months ago
I tried to fix the signatures manually
let idx = await search_index({
db: {
open: (options) => new Promise(resolve => leveldown_db.open(options, resolve)),
close: () => new Promise(resolve => leveldown_db.close(resolve)),
get: (key, options) => new Promise(resolve => leveldown_db.get(key, options, resolve)),
put: (key, value, options) => new Promise(resolve => leveldown_db.put(key, value, options, resolve)),
del: (key, options) => new Promise(resolve => leveldown_db.del(key, options, resolve)),
batch: (array, options) => new Promise(resolve => leveldown_db.batch(array, options, resolve)),
clear: (options) => new Promise(resolve => leveldown_db.clear(options, resolve)),
},
})
this fixes the invocation but apparently more stuff is broken in the background, as validateVersion
fails with This index was created with Error: Not found: , you are running 4.0.0
kNotFound
internally, at which point I stopped digging... some guidance would be much appreciated here!update: it works if you use ClassicLevel
instead, even though the types are wrong
Yes, the documentation could do with an update. ClassicLevel should provide persistent storage. When you say the types are wrong- what do you mean?
It results in a type error by TypeScript / JS tsserver:
let idx = await SI({ db: new ClassicLevel(path, { valueEncoding: 'json }), name: 'asdf' })
->
Type 'ClassicLevel<string, string>' is not assignable to type 'AbstractLevelDOWNConstructor'.
Type 'ClassicLevel<string, string>' provides no match for the signature '<K = any, V = any>(location: string): AbstractLevelDOWN<K, V>'.ts(2322)
But it works pretty amazing! still trying it out.
Also the TS info for PUT_RAW
are wrong as it expects one arg instead of the 2-3 actual ones.
None of that is super important though
Edit: While I really like this library, I have now switched to using SQLite FTS5 as a WASM module for Node instead (https://github.com/tndrle/node-sqlite3-wasm) which appears to be faster by factor ~10 and equally portable
ClassicLevel
is now the default backend in version 5.0.0
if using the lib with node, so all indexes persist to disk unless something else is specified.
For questions about search-index TS definitions these guys are the experts -> DefinitelyTyped/types/search-index
It seems the default strategy is to keep the thing in memory but not save it.
That's weird because in #39 you said
So is that outdated or...?
And in #120
I'm trying now to enable saving by passing a
{ db: require('leveldown')('/my/location') }
option, but now it fails withleveldown (once part of levelup, now living separately) relies on
abstract-leveldown
which is also linked in the docs:but abstract-leveldown's
get()
function is callback-based https://github.com/Level/abstract-leveldown/blob/master/abstract-leveldown.js whereasfergies-inverted-index
write.js
expects a promise-based calling conventionops._db.get(['~CREATED'], levelOptions).then(...)
. So I don't understand how this could have ever worked in the first place...? So this library isn't abstract-leveldown-compatible after all?!