tydb
  • TyDB
  • Getting Started
  • Database Configurations
  • Database Operations
  • Query API
  • Update API
  • Object Mapping
  • Persistence Adapters
  • File System Persistence
  • In the Browser
  • Over the Network
Powered by GitBook
On this page
  • Installation and usage
  • Memory only
  • Using IndexedDB Adapter
  • Connecting to a remote instance

Was this helpful?

In the Browser

How to use TyDB in the browser (with demo)

PreviousFile System PersistenceNextOver the Network

Last updated 5 years ago

Was this helpful?

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
});

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.

Setting target in Webpack
Setting target in Parcel
Setting target in Rollup
Demo in JSFiddle