ujjwalguptaofficial / JsStore

A complete IndexedDB wrapper with SQL like syntax.
http://jsstore.net/
MIT License
849 stars 109 forks source link

JsStore does not work without web worker #309

Closed excitedelektron closed 1 year ago

excitedelektron commented 1 year ago

Title

JsStore does not work without web worker

Description

I am trying to run the minimal version (without workers) verbatim from the official documentation but even that doesn't work: I am getting:

jsstore.js:549 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'run') at Connection.sendRequestToWorker (jsstore.js:549:31) at Connection.executeQry (jsstore.js:522:22) at Connection.prcoessExecutionOfQry_ (jsstore.js:508:14) at jsstore.js:495:23

image

I am using vanilla Javascript with jsstore v4.5.0

Here is my code:

async function minimalExample() {

    var connection = new JsStore.Connection();

    var dbName = 'JsStore_Demo';
    var tblProduct = {
        name: 'Product',
        columns: {
            id: { primaryKey: true, autoIncrement: true },
            itemName: { notNull: true, dataType: "string" },
            price: { notNull: true, dataType: "number" },
            quantity: { notNull: true, dataType: "number" }
        }
    };
    var database = {
        name: dbName,
        tables: [tblProduct]
    }

    const isDbCreated = await connection.initDb(database);
    if (isDbCreated === true) {
        console.log("db created");
    }
    else {
        console.log("db opened");
    }

    var value = {
        itemName: 'Blue Jeans',
        price: 2000,
        quantity: 1000
    }

    var insertCount = await connection.insert({
        into: 'Product',
        values: [value]
    });

    console.log(`${insertCount} rows inserted`);
}

Note: Description should contains the query, the current output & the expected output. You can use idbstudio to generate the example.

ujjwalguptaofficial commented 1 year ago

@excitedelektron are you including jsstore worker file ?

LeoZxy commented 1 year ago

I met the same error, I create new connection without using new Connection(new Worker(workerPath)) I just new Connection() then the error display like this err TypeError: Cannot read properties of undefined (reading 'run') at ConnectionHelper2.sendRequestToWorker_ (connectionhelper.ts:263:25) at ConnectionHelper2.executeQry (connectionhelper.ts:234:14) at ConnectionHelper2.prcoessExecutionOfQry (connection_helper.ts:212:10) at connection_helper.ts:198:14 Screenshot 2022-12-20 at 11 05 26

Also what's

Screenshot 2022-12-20 at 11 09 58

the meaning of this part?

ujjwalguptaofficial commented 1 year ago

getWorkerPath use file-loader to move the worker script to build folder and return the path of that file, so that you can use in Worker.

const worker = new Worker(<worker file path>)
ujjwalguptaofficial commented 1 year ago

@LeoZxy @excitedelektron can you guys provide me a reproducable repo, so that i can help you guys.

LeoZxy commented 1 year ago

Hi @ujjwalguptaofficial I use the vite + typescript

Could you clone this repo and run it? git@github.com:LeoZxy/jsstoreDemo.git

Screenshot 2022-12-20 at 13 24 04

or you can just open this link to check it on codesandbox https://codesandbox.io/s/romantic-leftpad-59qx5h?file=/src/App.tsx

LeoZxy commented 1 year ago

Hi @ujjwalguptaofficial @excitedelektron

I think we forget to add this code below

coonection.addPlugin(workerInjector)

now its seems working.

ujjwalguptaofficial commented 1 year ago

@excitedelektron hope your issue is also fixed, but if not please provide a reproducable repo - i am always there to help.

For now i am closing the issue.