Database SDK
Official @nfyio/database npm package — a typed client for your nfyio Postgres database via the data-api (tables, rows CRUD, raw SQL) with anon / service keys and RLS.
Database SDK — @nfyio/database
A typed client over the nfyio data-api (https://<slug>.data.nfyio.com). Use an
anon key (RLS-enforced, safe for browsers) or a service key (bypasses RLS,
server-only). Mint keys in the dashboard at Database → your database → Keys.
Install
npm install @nfyio/database
Usage
import { NfyioDatabase } from '@nfyio/database'
const db = new NfyioDatabase({
slug: 'my-db', // <slug> in <slug>.data.nfyio.com
apiKey: process.env.NFYIO_DB_ANON_KEY!,
})
// Read (paging / ordering / search)
const { rows, total } = await db.from('users').select({
limit: 20, orderBy: 'created_at', orderDir: 'desc',
})
// Insert one or many — returns the inserted rows
await db.from('users').insert({ email: 'a@b.com', name: 'Ada' })
// Update rows matching a where clause
await db.from('users').update({ email: 'a@b.com' }, { name: 'Ada Lovelace' })
// Delete rows matching a where clause
await db.from('users').delete({ email: 'a@b.com' })
// Raw, parameterised SQL (service key recommended)
const res = await db.sql('SELECT count(*)::int AS n FROM users WHERE active = $1', [true])
anon vs service keys
- anon — publishable, RLS-enforced. Safe for browsers. Only sees what your Row-Level-Security policies allow.
- service — secret, bypasses RLS. Server-side only.
The keys map to Postgres roles (anon / authenticated / service_role); your
RLS policies decide what each can read and write.