import { createClient } from '@ondb/sdk';
const client = createClient({
endpoint: 'https://api.ondb.io',
appId: 'my-app',
appKey: 'your-app-key'
});
// Create
const result = await client.store(
{ collection: 'users', data: [{ email: 'alice@example.com', name: 'Alice', active: true }] },
async (quote) => {
const txHash = await processPayment(quote);
return { txHash, network: quote.network, sender: walletAddress, chainType: quote.chainType, paymentMethod: 'native' };
},
true
);
// Read (single)
const found = await client.queryBuilder()
.collection('users')
.whereField('email').equals('alice@example.com')
.executeUnique();
console.log('Found:', found?.name);
// Read (many)
const activeUsers = await client.queryBuilder()
.collection('users')
.whereField('active').isTrue()
.orderBy('createdAt', 'DESC')
.limit(10)
.execute();
// Update (append new version with same data + changes)
if (found) {
await client.store(
{ collection: 'users', data: [{ ...found, name: 'Alice Smith' }] },
paymentCallback,
true
);
}
// Soft Delete (append record with deleted flag)
if (found) {
await client.store(
{ collection: 'users', data: [{ ...found, deleted: true, deletedAt: new Date().toISOString() }] },
paymentCallback,
true
);
}