Examples needed
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/LokiJS-Forge/LokiDB/blob/master/CONTRIBUTING.md#question
I looked in the following places for documentation on how to use LokiDB:
- https://www.npmjs.com/package/@lokidb/loki
- https://github.com/LokiJS-Forge/LokiDB
- https://lokijs-forge.github.io/LokiDB/
While the API is documented, there are no examples for anyone wanting to start with LokiDB. Maybe LokiJS could be a fall back, but it is not clear. I am not seeing a wiki either.
Can anyone indicate some examples that are suitable starting points?
In the meantime, I am trying to piece an example together that uses IndexedDB (based on examples and example in LokiJS):
import Loki from '@lokidb/loki';
import LokidIndexedAdapter from '@lokidb/indexed-storage';
async initDB () {
const adapter = new LokidIndexedAdapter();
const options = {
env: 'BROWSER',
serializationMethod: 'normal'
};
const db = new Loki('test.db', options);
const persistenceOptions = {
adapter: adapter,
autosave: false,
autosaveInterval: 1000,
autoload: false,
throttledSaves: false,
persistenceMethod: 'indexed-storage'
};
await db.initializePersistence(persistenceOptions);
let entries = await this.db.getCollection('entries');
if (entries === null) {
entries = await this.db.addCollection('entries');
}
return db;
}
function mounted() {
try {
const db = await initDB();
const entries = db.getCollection('entries');
entries.insert({
id: 321,
phrase: 'hello world'
});
} catch (error) {
console.log(error);
}
}
This results in an error:
Error: Unknown persistence method.
at Loki.initializePersistence (lokidb.loki.js?633e:4952)
ENV
- Browser: Google Chrome 84.0.4147.85 (Official Build) beta (64-bit)
- OS: macOS 10.15.5
- @lokidb/indexed-storage: 2.0.0-beta.9
- @lokidb/loki: 2.0.0-beta.
Please have a look at the tests: https://github.com/LokiJS-Forge/LokiDB/blob/master/packages/indexed-storage/spec/web/indexed_storage.spec.ts
@Viatorus thank you. Would you consider an initial example in the Read Me or as a new page in the docs?
Also, can they be await/async or do they need to be promise.then()?