SDK Data & API
All data operations go through custom endpoints you create in the API Builder. DYPAI does not auto-generate REST endpoints for your tables β you always need to create them first.
Calling Endpoints (dypai.api)
Use dypai.api to call any endpoint created with the API Builder. All HTTP methods are supported.
GET (Read)
Retrieve data with built-in filtering and pagination.
// Simple list
const { data, error } = await dypai.api.get('get_products', {
params: { category: 'electronics', limit: 10 }
});
// Paged list
const { data, error } = await dypai.api.get('get_products', {
params: { limit: 20, offset: 0 }
});
POST (Create / Action)
Create records or trigger complex workflows.
const { data, error } = await dypai.api.post('create_order', {
customer_id: 'uuid-123',
items: [{ id: 'p1', qty: 2 }]
});
PUT / PATCH (Update)
const { data, error } = await dypai.api.put('update_product/product-uuid', {
price: 29.99
});
DELETE
const { error } = await dypai.api.delete('delete_product/product-uuid');
Every endpoint name (e.g. get_products, create_order) must correspond to an endpoint you've created in the API Builder. If the endpoint doesn't exist, the SDK will return a 404 error.
Filtering Operators
When using params in GET requests, you can use powerful operators:
| Operator | Description | Example |
|---|---|---|
eq | Equal to | status: { eq: 'active' } |
gt / gte | Greater than | price: { gte: 100 } |
contains | Text search | name: { contains: 'pizza' } |
in | In list | id: { in: ['1', '2'] } |
Direct Database Access (db.direct)
Server-side only. This is for scripts, migrations, seeds, and backend code. Never expose the serviceRoleKey in browser code. For end-user data access, use endpoints via dypai.api.
Direct DB access bypasses endpoints and workflows. It requires a serviceRoleKey:
import { createClient } from '@dypai-ai/client-sdk';
const dypaiAdmin = createClient('https://your-project.dypai.app', {
serviceRoleKey: process.env.DYPAI_SERVICE_ROLE_KEY!,
});
Select with Filters
const { data } = await dypaiAdmin.db.direct
.from('products')
.eq('active', true)
.gt('price', 50)
.orderBy('price', 'DESC')
.limit(20)
.select();
// Select specific columns
const { data } = await dypaiAdmin.db.direct.from('products').select('id, name, price');
// Single row
const { data: user } = await dypaiAdmin.db.direct.from('users').eq('id', id).single();
// Count
const { data: count } = await dypaiAdmin.db.direct.from('orders').eq('status', 'pending').count();
Insert, Update, Delete
// Insert (single or bulk β auto-chunks at 1,000 rows)
await dypaiAdmin.db.direct.from('products').insert({ name: 'Widget', price: 9.99 });
await dypaiAdmin.db.direct.from('products').insert(thousandRows);
// Update (filter required)
await dypaiAdmin.db.direct.from('products').eq('category', 'old').update({ active: false });
// Delete (filter required)
await dypaiAdmin.db.direct.from('products').eq('id', 'abc').delete();
// Upsert (insert or update on conflict)
await dypaiAdmin.db.direct.from('products').upsert({ id: '1', name: 'Widget' }, 'id');
Raw SQL
await dypaiAdmin.db.direct.sql('ALTER TABLE products ADD COLUMN sku TEXT');
const { data } = await dypaiAdmin.db.direct.sql(
'SELECT category, COUNT(*) FROM products WHERE price > $1 GROUP BY category',
[25]
);
Available Filters
| Method | SQL | Example |
|---|---|---|
.eq(col, val) | = | .eq('status', 'active') |
.neq(col, val) | != | .neq('role', 'banned') |
.gt() .gte() .lt() .lte() | > >= < <= | .gt('price', 50) |
.like(col, val) | ILIKE %val% | .like('name', 'widget') |
.in(col, arr) | IN (...) | .in('status', ['a', 'b']) |
.isNull(col) | IS NULL | .isNull('deleted_at') |
.notNull(col) | IS NOT NULL | .notNull('email') |
.contains(col, val) | @> (array/JSONB) | .contains('tags', ['sale']) |
.containedBy(col, val) | <@ | .containedBy('tags', ['a','b']) |
.overlaps(col, val) | && (array overlap) | .overlaps('tags', ['x']) |
.textSearch(col, q) | Full-text search | .textSearch('desc', 'wireless') |
.not(col, op, val) | Negate any filter | .not('status', 'eq', 'deleted') |
.or([...]) | OR group | .or([{column:'a',operator:'eq',value:1}]) |