Storage Adapters
Coco is built in a platform agnostic way. As we can not assume anything about the presence of a certain storage API (e.g. IndexedDB), coco exposes a storage interface that needs to be satisfied when instantiating.
ts
const repo = new ExpoSqliteRepositories({ database: db }); // Implements the Repositories interface
await repo.init(); // Ensures schema and applies migrations
const coco = await initializeCoco({
repo, // <-- pass the storage implementation
seedGetter,
// other params
});Some storage implementations are maintained as part of the cashubtc/coco repository, but technically you can use any class that implements the Repositories interface.
@cashu/coco-indexeddb
Implements Repositories using the IndexedDB Browser API.
Installation:
sh
npm i @cashu/coco-indexeddbUsage:
ts
import { initializeCoco } from '@cashu/coco-core';
import { IndexedDbRepositories } from '@cashu/coco-indexeddb';
const repo = new IndexedDbRepositories({ name: 'your-db-name' });
const coco = await initializeCoco({
repo,
seedGetter,
});@cashu/coco-expo-sqlite
Installation:
sh
npm i @cashu/coco-expo-sqlite
# @cashu/coco-expo-sqlite expects an Expo SQLite client to be passed
npx expo install expo-sqliteUsage:
ts
import { initializeCoco } from '@cashu/coco-core';
import { ExpoSqliteRepositories } from '@cashu/coco-expo-sqlite';
import { openDatabaseAsync } from 'expo-sqlite';
// First we create an expo-sqlite client
const db = await openDatabaseAsync('coco-demo.db');
// Then we pass it to our storage implementation
const repo = new ExpoSqliteRepositories({ database: db });
const coco = await initializeCoco({
repo,
seedGetter,
});@cashu/coco-sqlite
Installation:
sh
npm i @cashu/coco-sqlite
npm i better-sqlite3Usage:
ts
import { initializeCoco } from '@cashu/coco-core';
import { SqliteRepositories } from '@cashu/coco-sqlite';
import Database from 'better-sqlite3';
// First we create a better-sqlite3 client
const db = new Database('./test.db');
// Then we pass it to our storage implementation
const repo = new SqliteRepositories({ database: db });
const coco = await initializeCoco({
repo,
seedGetter,
});@cashu/coco-sqlite-bun
SQLite adapter for Bun runtime using Bun's built-in bun:sqlite module.
Installation:
sh
npm i @cashu/coco-sqlite-bunUsage:
ts
import { initializeCoco } from '@cashu/coco-core';
import { SqliteRepositories } from '@cashu/coco-sqlite-bun';
import { Database } from 'bun:sqlite';
// First we create a bun:sqlite client
const db = new Database('./test.db');
// Then we pass it to our storage implementation
const repo = new SqliteRepositories({ database: db });
const coco = await initializeCoco({
repo,
seedGetter,
});Note: This adapter is specifically designed for Bun runtime environments. For Node.js environments, use @cashu/coco-sqlite instead.