Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples needed #176

Open
ajmas opened this issue Jul 21, 2020 · 3 comments
Open

Examples needed #176

ajmas opened this issue Jul 21, 2020 · 3 comments

Comments

@ajmas
Copy link

ajmas commented Jul 21, 2020

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:

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?

@ajmas
Copy link
Author

ajmas commented Jul 21, 2020

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.

@Viatorus
Copy link
Member

@ajmas
Copy link
Author

ajmas commented Jul 23, 2020

@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()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants