Query tables and call functions with from() and rpc().
JavaScript
// Select with filters, ordering and pagination
const { data } = await stitchdb
.from('todos')
.select('id, task, is_complete')
.eq('is_complete', false)
.order('created_at', { ascending: false })
.range(0, 9)
// Insert, update and delete
await stitchdb.from('todos').insert({ task: 'New task' })
await stitchdb.from('todos').update({ is_complete: true }).eq('id', 1)
await stitchdb.from('todos').delete().eq('id', 1)
// Call a Postgres function
const { data: total } = await stitchdb.rpc('count_open_todos')#Query builder
| Group | Methods |
|---|---|
| Read and write | select, insert, upsert, update, delete |
| Filters | eq, neq, gt, gte, lt, lte, like, ilike, likeAnyOf, ilikeAnyOf, is, in, contains, containedBy, overlaps, rangeGt, rangeGte, rangeLt, rangeLte, rangeAdjacent, textSearch, match, not, or, filter |
| Modifiers | order, limit, range, single, maybeSingle, csv, geojson, explain, abortSignal, setHeader, throwOnError |
| Counts | select('*', { count: 'exact' | 'planned' | 'estimated', head: true }) |
Every call resolves to { data, error, count, status }; errors are returned, not thrown, unless you add .throwOnError(). See Filtering and pagination and Insert, update and delete for examples.
#TypeScript
Generate a Database type from your schema with the generate_typescript_types tool of the MCP server and pass it to the client:
JavaScript
import type { Database } from './database.types'
const stitchdb = createClient<Database>('https://<project-ref>.p.stitchdb.com', '<anon-key>')