JavaScript and TypeScript client
Install @plexivo/client and use Plexivo Postgres from the browser, React, React Native, Vue or Node: queries, Auth, Realtime and more.
@plexivo/client is the client for Plexivo Postgres as a backend. It has no runtime dependencies, is an ES module with TypeScript types, and runs in every modern browser and on Node 20 and later. This page is for version 0.4.0.
The full reference, with every method and example, is on npm.
Install#
npm install @plexivo/clientQuick start#
create table todos (
id bigint generated always as identity primary key,
owner uuid not null default auth.uid(),
title text not null,
done boolean not null default false,
created_at timestamptz not null default now()
);
alter table todos enable row level security;
create policy own_todos on todos for all to authenticated
using (owner = auth.uid()) with check (owner = auth.uid());import { createClient } from '@plexivo/client';
const db = createClient(PLEXIVO_DATA_URL, PLEXIVO_PUBLISHABLE_KEY);
await db.auth.signUp({ email, password });
await db.from('todos').create({ title: 'Ship it' });
const open = await db.from('todos').where('done', false).order('created_at', 'desc').limit(20);Pass the database’s Project URL and Publishable key, both on its Connect tab.
Client options#
const app = createClient(PLEXIVO_DATA_URL, PLEXIVO_PUBLISHABLE_KEY, {
storage: globalThis.localStorage, // where the session is kept; pass encrypted storage in React Native
persistSession: true, // false on servers
throwOnError: false // return { data, error } instead of throwing, as Supabase does
});
const controller = new AbortController();
const { data, error } = await app.from('todos').select('id, title').limit(5).abortSignal(controller.signal);| Option | What it does |
|---|---|
storage, storageKey | Where the session is kept: localStorage in a browser by default; any object with getItem, setItem and removeItem. |
persistSession | false keeps the session in memory only. |
initialSession | A session to start with, such as one your server passed down. |
throwOnError | false resolves failed queries and calls as { data: null, error }. By default they throw a PlexivoError. |
fetch, WebSocket | Your own implementations, for tests or older runtimes. |
Created in a browser with the secret key, the client throws secret_key_in_browser straight away: the secret key belongs on servers only.
What it covers#
| Area | Methods | Guide |
|---|---|---|
| Queries | from, select, where and every operator, order, limit, range, paginate, first, count, sum, aggregate, groupBy, findInBatches; Supabase’s eq, in, or, single, maybeSingle | Queries |
| Joins | preload, joins, whereHas, withCount, whereIn with a subquery, model relations | Joins |
| Writes | create, createInBatches, upsert, save, update, increment, delete, soft deletes | Writes |
| Transactions and functions | transaction with .ref(), lockForUpdate, rpc | Transactions |
| Auth | db.auth: signUp, signInWithPassword, signInWithOtp, signInWithOAuth, signInAnonymously, linkEmail, updateUser, onAuthStateChange, listSessions, mfa; db.orgs | Auth |
| Realtime | channel('changes:…'), rooms, onChange, onBroadcast, onPresence, onStatus | Realtime |
| GraphQL | graphql, graphql.subscribe | GraphQL |
| Functions | functions.invoke | Functions |
| Server only | sql, raw, exec, sqlTransaction, migrate, migrator | Raw SQL |
| Errors | PlexivoError, isUniqueViolation, isPermissionDenied, isNotFound | Errors |
TypeScript#
Generate types from your live Data API, and every table name and column is checked as you type:
npx plexivo-generate-types --output src/database.types.tsRun it with PLEXIVO_DATA_URL and PLEXIVO_PUBLISHABLE_KEY set, then pass the type in: createClient<Database>(url, key).
New in 0.4.0#
- Order by a related row’s column:
order('profiles.username'). - Subqueries:
whereIn('author_id', db.from('profiles').select('id').where(…)). - Database functions that return rows take
select, filters,orderandrange. - Nested preloads:
preload('comments.profiles'). - User profile data:
signUp({ data }),auth.updateUser({ data }). throwOnError: falseandabortSignal.- Realtime channels rejoin by themselves after a dropped connection or an expired token.
- The secret key is refused in a browser.
Updated 28 October 2026