Database
Storage

Storage

Each client has the option for how they would like to store their data.

Memory

If you would only like to store data ephemerally, you can use the memory storage engine. This will store your data in memory and will not persist across page refreshes.

If you use memory storage for your outbox, data may be lost if the user refreshes the page before the data is sent to the server.

If no storage options are provided this is the default.

const client = new TriplitClient({
  storage: 'memory',
});
 
// Which is equivalent to
 
import { MemoryBTreeStorage as MemoryStorage } from '@triplit/db/storage/memory-btree';
 
const client = new TriplitClient({
  storage: {
    outbox: new MemoryStorage(),
    cache: new MemoryStorage(),
  },
});

IndexedDB

If you would like to persist data between refreshes in the browser you can use the IndexedDB storage engine. This will store your data in the browser's IndexedDB database.

To improve performance, data is also cached in memory.

const client = new TriplitClient({
  storage: 'indexeddb',
});
 
// Which is equivalent to
 
import { IndexedDbStorage } from '@triplit/db/storage/indexed-db';
 
const client = new TriplitClient({
  storage: {
    outbox: new IndexedDBStorage('triplit-outbox'),
    cache: new IndexedDBStorage('triplit-cache'),
  },
});

Note that passing storage: 'indexeddb' to the constructor will create IndexedDB databases using the names 'triplit-outbox' and 'triplit-cache'. If your application connects to multiple projects with separate clients, we recommend you create your own custom-named instances of IndexedDBStorage so that naming conflicts do not occur.