
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
surrealdb.js
Advanced tools
The official SurrealDB SDK for JavaScript.
View the SDK documentation here.
Import it with:
import Surreal from "@surrealdb/surrealdb";
For best results, set a version in the url:
Install it with:
# using npm
npm i surrealdb.js
# or using pnpm
pnpm i surrealdb.js
# or using yarn
yarn add surrealdb.js
Next, just import it with:
const { Surreal } = require("surrealdb.js");
or when you use modules:
import Surreal from "surrealdb.js";
For usage in a browser environment, when using a bundler (e.g. Rollup, Vite, or webpack) you can install it with:
# using npm
npm i surrealdb.js
# or using pnpm
pnpm i surrealdb.js
# or using yarn
yarn add surrealdb.js
Next, just import it with:
import Surreal from "surrealdb.js";
or when you use CommonJS:
const { Surreal } = require("surrealdb.js");
For fast prototyping we provide a browser-ready bundle. You can import it with:
import Surreal from "https://unpkg.com/surrealdb.js";
// or
import Surreal from "https://cdn.jsdelivr.net/npm/surrealdb.js";
NOTE: this bundle is not optimized for production! So don't use it in production!
In the example below you can see how to connect to a remote instance of SurrealDB, authenticating with the database, and issuing queries for creating, updating, and selecting data from records.
This example requires SurrealDB to be installed and running on port 8000.
This example makes use of top level await, available in modern browsers, Deno and Node.js >= 14.8.
import { Surreal, RecordId, Table } from "surrealdb.js";
const db = new Surreal();
// Connect to the database
await db.connect("http://127.0.0.1:8000/rpc");
// Select a specific namespace / database
await db.use({
namespace: "test",
database: "test"
});
// Signin as a namespace, database, or root user
await db.signin({
username: "root",
password: "root",
});
// Create a new person with a random id
let created = await db.create("person", {
title: "Founder & CEO",
name: {
first: "Tobie",
last: "Morgan Hitchcock",
},
marketing: true,
});
// Update a person record with a specific id
let updated = await db.merge(new RecordId('person', 'jaime'), {
marketing: true,
});
// Select all people records
let people = await db.select("person");
// Perform a custom advanced query
let groups = await db.query(
"SELECT marketing, count() FROM $tb GROUP BY marketing",
{
tb: new Table("person"),
},
);
This is a Bun project, not Node.js. It works across all major runtimes, however.
For Deno, no build is needed. For all other environments run
bun run build
.
bun quality:apply
bun quality:apply:unsafe
bun test
SURREAL_PROTOCOL=http bun test
Before you commit, please format and lint your code accordingly to check for errors, and ensure all tests still pass
For local development the Bun extension and Biome extension for VSCode are helpful.
./biome.json
include settings for code quality../scripts
include the build scripts for NPM and JSR../src
includes all source code. ./src/index.ts
is the main entrypoint../dist
is build by ./scripts/build.ts
and includes the compiled and minified bundles for ESM, CJS and bundled ESM targets../tests
includes all test files.FAQs
Javascript driver for SurrealDB
We found that surrealdb.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.