In the Browser

How to use TyDB in the browser (with demo)

Installation and usage

Directly including TyDB in a script tag

<script src="//raw.githack.com/alexcorvi/tydb/master/dist/index.browser.js"></script>

Using a module bundler & package manager

Install TyDB using npm

npm i tydb

or using yarn

yarn add tydb

If you're using a bundler with package manager, then you will have to tell your bundler that you're bundling your project for the browser (if it doesn't defaults to that already), so the bundler will use the file specified in browser field instead of main field.

Memory only

Similar to when running in NodeJS, if you instantiate the database with no persistence adapter, data will not be persisted and will live in memory only.

const db = new tydb.Database({
    ref: "mydb",
    model: MyModel
});

Using IndexedDB Adapter

const db = new tydb.Database({
    ref: "mydb",
    model: MyModel,
    persistence_adapter: tydb.IDB_Persistence_Adapter
});

Demo in JSFiddle

Connecting to a remote instance

const db = new tydb.Database({
    ref: "tydb://http://example.com/mydb",
    model: MyModel,
});

Similar to when running in NodeJS environment, the instance in this case will be nothing more than a shell that sends arguments and receive data.

Last updated