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

IDB name is undefined #14

Open
quolpr opened this issue Aug 19, 2021 · 6 comments
Open

IDB name is undefined #14

quolpr opened this issue Aug 19, 2021 · 6 comments

Comments

@quolpr
Copy link
Contributor

quolpr commented Aug 19, 2021

I am using the latest version of the absurd-sql + your sql.js (0.0.53). When I do this:

main:

function init() {
  let worker = new Worker(
    new URL('./SqlNotesRepository.worker.js', import.meta.url),
    {
      name: 'sql-notes-worker',
      type: 'module',
    },
  );

  // This is only required because Safari doesn't support nested
  // workers. This installs a handler that will proxy creating web
  // workers through the main thread
  initBackend(worker);
}

init()

worker:

import initSqlJs from '@jlongster/sql.js';
import { SQLiteFS } from 'absurd-sql';
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';

const run = async () => {
  let SQL = await initSqlJs({
    locateFile: (file: string) => `/sqljs/${file}`,
  });
  let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
  SQL.register_for_idb(sqlFS);

  SQL.FS.mkdir('/blocked');

  SQL.FS.mount(sqlFS, {}, '/blocked');

  const db = new SQL.Database(`/blocked/123.sqlite`, {
    filename: true,
  });

  db.exec(`
    PRAGMA journal_mode=MEMORY;
  `);

  let sqlstr =
    "CREATE TABLE IF NOT EXISTS hello (a int, b char); \
INSERT INTO hello VALUES (0, 'hello'); \
INSERT INTO hello VALUES (1, 'world');";
  db.run(sqlstr); // Run the query without returning anything
};

run();

The new IndexedDB DB got created, but its name is undefined

image

But in your example site, IndexedDB DBs have the correct names 🤔

Also, on page reload I am getting this message on insert:

image

And I think it somehow may relate to the issue 🤔 The interesting is that when it overwrites(I guess) all blocks from the previous site open — it starts working well.

Btw, great lib 👍 I was making a note-taking app, and I was on stage where I was needed to introduce a full-text search, and in IndexedDB it is a headache. Now I am going to rewrite the persistence layer to absurd-sql, and I am super excited to get overall speed improvements with a text search for free 🙂 And it also gives me the easy way to improve the speed when I will be porting the app to the phones/desktops — ionic/cordova/electron has wrappers for the native SQLite.

@jlongster
Copy link
Owner

Thanks for the issues! You are using the fallback mode, which has the limitation that only one tab can write the to db at a time. It falls back to this mode when SharedArrayBuffer isn't available. Unfortunately, for browsers to make it available you need to make sure you site is served with these headers:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

If you are using webpack dev mode, check out the webpack config in the examples folder and you'll see how to get it to serve those headers.

The undefined name might be a bug in the fallback mode. I'll check it out!

@quolpr
Copy link
Contributor Author

quolpr commented Aug 20, 2021

@jlongster ooops, you were absolutely right! All issues are gone 🙂 Thank you so much for the help and the fast reply

@quolpr quolpr closed this as completed Aug 20, 2021
@quolpr
Copy link
Contributor Author

quolpr commented Aug 20, 2021

But it seems that a bug in the fallback mode is still present though

@jlongster
Copy link
Owner

Re-opening to track the fallback mode bug

@jlongster jlongster reopened this Aug 25, 2021
@quolpr
Copy link
Contributor Author

quolpr commented Sep 1, 2021

Some investigations. At https://priceless-keller-d097e5.netlify.app on safari IDB creates correctly:

image

But on https://app-next.actualbudget.com/subscribe the IDB is undefined too:

image

I also cloned the current repo and started the bench example, it shows the DB name is undefined too(but I see the message SharedArrayBuffer is not available in your browser. Falling back..)

@jlongster do you know on which version of absurd-sql priceless-keller-d097e5.netlify.app is running?

@quolpr
Copy link
Contributor Author

quolpr commented Sep 1, 2021

Nevermind, I found that this commit 33f9898 breaks safari support

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