Connection is a Class which contains all apis like select
, count
etc. Under the hood it talks with indexeddb and return results.
var connection = new JsStore.Connection(new Worker('jsstore worker path'));
example - https://github.com/ujjwalguptaofficial/jsstore-examples/tree/master/simple_example
var connection = new JsStore.Connection();
example - https://github.com/ujjwalguptaofficial/jsstore-examples/tree/master/without_web_worker
Install jsstore using npm or yarn - npm i jsstore
Install file-loader - npm i file-loader -D
Create a file jsstore_con.js or jsstore_con.ts (for typescript). This file will be used to create the jsstore connection. You can choose any file name.
Inside the file jsstore_con.js, write below code -
👉 With Web Worker
const getWorkerPath = () => {
// return dev build when env is development
if (process.env.NODE_ENV === 'development') {
return require("file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.js");
}
else { // return prod build when env is production
return require("file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.min.js");
}
};
const workerPath = getWorkerPath().default;
export const connection = new JsStore.Connection(new Worker(workerPath));
👉 Without Web Worker #
import workerInjector from "jsstore/dist/worker_injector";
const connection = new Connection();
connection.addPlugin(workerInjector);
In the above code we are using file-loader to load jsstore worker file but you are free to use your own technique to load jsstore worker. The simplest approach is download jsstore.worker.js and then specify its path.
If you are finding difficult to understand, please take a look at examples or our medium page