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 🙏

© 2024 – Pkg Stats / Ryan Hefner

surrealdb

v1.1.0

Published

The official SurrealDB SDK for JavaScript.

Downloads

17,399

Readme

surrealdb

The official SurrealDB SDK for JavaScript.

Documentation

View the SDK documentation here.

Learn SurrealDB

  • SurrealDB University: https://surrealdb.com/learn/fundamentals
  • Aeon's Surreal Renaissance (Interative book): https://surrealdb.com/learn/book
  • Documentation: https://surrealdb.com/docs

How to install

Install for JSR/Deno

Import it with:

import Surreal from "@surrealdb/surrealdb";

Install for Node.js

Install it with:

# using npm
npm i surrealdb
# or using pnpm
pnpm i surrealdb
# or using yarn
yarn add surrealdb

Next, just import it with:

const { Surreal } = require("surrealdb");

or when you use modules:

import Surreal from "surrealdb";

Install for the browser

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
# or using pnpm
pnpm i surrealdb
# or using yarn
yarn add surrealdb

Next, just import it with:

import Surreal from "surrealdb";

or when you use CommonJS:

const { Surreal } = require("surrealdb");

Install for the browser with a CDN

For fast prototyping we provide a browser-ready bundle. You can import it with:

import Surreal from "https://unpkg.com/surrealdb";
// or
import Surreal from "https://cdn.jsdelivr.net/npm/surrealdb";

NOTE: this bundle is not optimized for production! So don't use it in production!

Getting started

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";

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"),
    },
);

Contributing

Local setup

This is a Bun project, not Node.js. It works across all major runtimes, however.

Supported environments

Requirements

  • Bun
  • SurrealDB (for testing)

Build for all supported environments

For Deno, no build is needed. For all other environments run

bun run build.

Code Quality Fixes

bun quality:apply

Code Quality unsafe fixes

bun quality:apply:unsafe

Run tests for WS

bun test

Run tests for HTTP

SURREAL_PROTOCOL=http bun test

PRs

Before you commit, please format and lint your code accordingly to check for errors, and ensure all tests still pass

Local setup

For local development the Bun extension and Biome extension for VSCode are helpful.

Directory structure

  • ./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.