Skip to content

Surqlize for TypeScript

Surqlize installation

Surqlize is published on npm as surqlize. It declares the JavaScript SDK as a peer dependency, and your code imports Surreal from that package to open the connection, so a project installs both.

bun add surqlize surrealdb

Surqlize ships ESM and CommonJS builds with type declarations, so it can be imported with either module system.

Import Surqlize and the SDK
import { Surreal } from "surrealdb";
import { orm, table, t } from "surqlize";
RequirementVersion
surrealdb JavaScript SDK^2.1.0
TypeScript5 or 6
SurrealDB server3.0 or later

The SDK and the server are versioned separately: version 2 of the SDK is the one that connects to a SurrealDB 3.x server.

Surqlize targets SurrealDB 3.x. A few features depend on the server version, and the page for each feature says which. Computed fields need 3.0, filtering or projecting a live query needs 3.0, and .retry() recognises a transaction conflict from the structured error that SurrealDB 3.1.0 and later report.

The connection that you pass to Surqlize and Surqlize itself must come from the same installed copy of surrealdb. When a project installs two different versions of the SDK, TypeScript can report an error where the connection is passed to orm():

Error output
Type 'Surreal' is not assignable to type 'SurrealSession'.
  Property '#private' in type 'Surreal' refers to a different member that cannot be accessed from within type 'SurrealSession'.

To check which versions a project resolves, run npm ls surrealdb (or bun pm ls --all).

If a query fails with a DuplicateSurrealError, the connection was created by a different copy of surrealdb from the one Surqlize imports. See error handling.

Was this page helpful?