npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-surrealdb

v0.1.0-alpha.1

Published

Embedded and remote SurrealDB for React Native

Readme

react-native-surrealdb

Native SurrealDB for React Native, backed by the official Rust SDK and exposed through generated UniFFI/Hermes JSI bindings.

This package is an early alpha. Pin the exact version and read the limitations before using it in an application.

Install

pnpm add react-native-surrealdb
cd ios && pod install

Requirements:

  • React Native 0.82 or newer with the New Architecture and Hermes enabled;
  • iOS 15.1 or newer (arm64 devices and Apple Silicon simulators);
  • Android API 24 or newer (arm64-v8a devices and x86_64 emulators).

Intel Mac simulators and 32-bit Android ABIs are not included in the alpha package. This keeps the prebuilt native distribution within npm's upload boundary while covering current production devices and development hosts.

Connect and query

import { SurrealRecordId, connect } from "react-native-surrealdb";

const db = await connect({
  endpoint: "memory",
  namespace: "app",
  database: "app",
});

const [result] = await db.query("RETURN $person", {
  person: new SurrealRecordId("person:ada"),
});

await db.transaction(async (transaction) => {
  await transaction.query("CREATE person:ada SET name = $name", {
    name: "Ada",
  });
  await transaction.query("CREATE person:lin SET name = $name", {
    name: "Lin",
  });
});

await db.close();

transaction() begins one native SurrealDB transaction, passes a JavaScript handle to the callback, and commits once the callback resolves. Each transaction.query() is executed immediately inside that transaction. If the callback throws, the transaction is cancelled and the original error is re-thrown. For manual lifecycle control, use beginTransaction(), then call commit() or cancel() on the returned handle.

const transaction = await db.beginTransaction();
try {
  await transaction.query("UPDATE account:one SET balance -= $amount", {
    amount: 10,
  });
  await transaction.query("UPDATE account:two SET balance += $amount", {
    amount: 10,
  });
  await transaction.commit();
} catch (error) {
  await transaction.cancel();
  throw error;
}

transaction.query() calls are sent individually and share the native transaction ID. For bulk work, transaction.queryBatch() executes independently parameterized queries in one asynchronous native call and preserves every result. transaction.executeBatch() is the lower-overhead write variant: it repeats one parameterized query, discards RETURN NONE results, and returns the executed count.

await db.transaction((transaction) =>
  transaction.executeBatch(
    "CREATE person CONTENT { name: $name } RETURN NONE",
    [{ name: "Ada" }, { name: "Lin" }],
  ),
);

Await transaction operations in sequence, and do not reuse a handle after commit() or cancel().

The alpha supports embedded memory and experimental surrealkv://... endpoints, plus remote ws:// and wss:// endpoints. Remote connections can select a namespace/database and authenticate with root or database credentials.

Live queries

The low-level API is a pull-based async iterator with natural backpressure:

const events = await db.live<{ text: string }>(
  "LIVE SELECT * FROM message WHERE room = $room",
  { room: "engineering" },
);

for await (const notification of events) {
  console.log(notification.action, notification.value);
}

Use a multicast subscription when multiple consumers need the same native stream or when integrating with an observable UI:

const messages = await db.subscribe<{ text: string }>(
  "LIVE SELECT * FROM message WHERE room = $room",
  { room: "engineering" },
);

const stopListening = messages.onNotification((notification) => {
  console.log(notification.action, notification.value);
});

stopListening();
await messages.close();

LiveSubscription.subscribe() and getSnapshot() implement the external-store contract used by React. The optional React entry point wraps that contract in a TanStack Query-style result:

import { useLiveQuery } from "react-native-surrealdb/react";

function LatestMessage({ db, room }: Props) {
  const message = useLiveQuery<{ text: string }>({
    client: db,
    queryKey: ["messages", room],
    surql: "LIVE SELECT * FROM message WHERE room = $room",
    variables: { room },
  });

  if (message.isPending) return <ActivityIndicator />;
  if (message.isError) return <Text>{String(message.error)}</Text>;
  return <Text>{message.data?.text ?? "Waiting for a message"}</Text>;
}

data is the latest notification value; notification also exposes its action and query ID. The hook closes its server-side live query on unmount or when its query key changes. queryKey follows TanStack Query semantics: include every variable used by the query. If omitted, the query and encoded variables form the key automatically.

Closing is idempotent and cancels the server-side live query. Automatic reconnection, re-subscription, and duplicate-event suppression are not yet implemented; applications using remote live queries must currently handle a dropped connection.

Closing the database also closes its live queries and cancels its open transactions.

Cancellation and limitations

Async operations accept { signal } as their final options argument. The package requires Hermes and React Native's New Architecture and cannot run in Expo Go. Persistent SurrealKV support is experimental. Transaction callbacks must finish before the database is closed, and remote connection recovery is currently application-managed.

Value transport

The JavaScript/Rust boundary preserves 64-bit integers, decimals, record IDs, UUIDs, bytes, sets, NONE, and other SurrealQL-only values rather than losing them through ordinary JSON conversion.

Benchmark diagnostics

queryProfiled() is an opt-in benchmark variant available on database and transaction handles. It returns the ordinary query results plus timing for JavaScript input encoding, embedded SDK execution, Rust output encoding, binding/scheduling residual, and JavaScript output decoding. benchmarkNativeBoundary() measures an async UniFFI/JSI no-op round trip. These APIs are intended for controlled benchmarks rather than production telemetry; ordinary query() calls contain no diagnostic clocks or additional return fields. Normal result transport streams the lossless wire format directly from SurrealDB values and decodes parsed arrays/objects in place, avoiding the previous pair of full intermediate value trees.

Native development

The generated TypeScript/C++/platform glue is checked in. Release archives are generated locally and ignored by Git because they are large.

pnpm install
pnpm --filter react-native-surrealdb run release:artifacts
pnpm --filter react-native-surrealdb run release:check
pnpm --filter react-native-surrealdb pack

Android generation requires Android NDK 27.1.12297006, API level 24, and cargo-ndk 4.1.2. See RELEASING.md for the complete release procedure.

Acknowledgements

The native bridge is generated by uniffi-bindgen-react-native, led by James Hugman and built on Mozilla UniFFI. See THIRD_PARTY_NOTICES.md for project, contributor, and license details included with the published package.