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#

bash
npm install @plexivo/client

Quick start#

sql
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());
js
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#

js
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);
OptionWhat it does
storage, storageKeyWhere the session is kept: localStorage in a browser by default; any object with getItem, setItem and removeItem.
persistSessionfalse keeps the session in memory only.
initialSessionA session to start with, such as one your server passed down.
throwOnErrorfalse resolves failed queries and calls as { data: null, error }. By default they throw a PlexivoError.
fetch, WebSocketYour 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#

AreaMethodsGuide
Queriesfrom, select, where and every operator, order, limit, range, paginate, first, count, sum, aggregate, groupBy, findInBatches; Supabase’s eq, in, or, single, maybeSingleQueries
Joinspreload, joins, whereHas, withCount, whereIn with a subquery, model relationsJoins
Writescreate, createInBatches, upsert, save, update, increment, delete, soft deletesWrites
Transactions and functionstransaction with .ref(), lockForUpdate, rpcTransactions
Authdb.auth: signUp, signInWithPassword, signInWithOtp, signInWithOAuth, signInAnonymously, linkEmail, updateUser, onAuthStateChange, listSessions, mfa; db.orgsAuth
Realtimechannel('changes:…'), rooms, onChange, onBroadcast, onPresence, onStatusRealtime
GraphQLgraphql, graphql.subscribeGraphQL
Functionsfunctions.invokeFunctions
Server onlysql, raw, exec, sqlTransaction, migrate, migratorRaw SQL
ErrorsPlexivoError, isUniqueViolation, isPermissionDenied, isNotFoundErrors

TypeScript#

Generate types from your live Data API, and every table name and column is checked as you type:

bash
npx plexivo-generate-types --output src/database.types.ts

Run 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, order and range.
  • Nested preloads: preload('comments.profiles').
  • User profile data: signUp({ data }), auth.updateUser({ data }).
  • throwOnError: false and abortSignal.
  • 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