Install the package for the dialect you use. Each package is ESM only and has no runtime dependencies.
bun add @surrealdb/pg
bun add @surrealdb/mysqlpg is an optional peer dependency of @surrealdb/pg. It is needed only for the Prisma path, and Drizzle's node-postgres driver imports it itself.
Requirements
| Requirement | Version |
|---|---|
| Runtime | Node.js 20 or later, Bun, Deno, Cloudflare Workers, Vercel Edge, or a browser |
| SurrealDB server | A version that serves the pgsql and mysql RPC methods |
The packages use fetch, WebSocket, AbortController and TextEncoder, and no Node.js built-ins. Node.js versions without a global WebSocket need a constructor passed as the WebSocket option, for example from the ws package. HTTP alone needs nothing extra.
import WebSocket from "ws";
import { connect } from "@surrealdb/pg";
const sql = connect({ url: "surrealdb+wss://abc123.surrealdb.earth/prod/app", WebSocket });Each package is about 11 kB minified and compressed with brotli.
Do not put database credentials in browser code that real users can read. Pass a token, or a function that returns one, as the auth option.
Check the instance
Call capabilities() to check that an instance serves the method before you rely on it.
const caps = await sql.capabilities();
// { supported: true, version: "...", transport: { ... } }It reports supported: false with a reason when the method or the dialect route is denied, for example with --deny-rpc pgsql.