Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

surrealdb-js

/surrealdb-js

Łączy aplikacje Node, Deno, Bun i przeglądarkę z SurrealDB przez SDK surrealdb: uwierzytelnianie, CRUD i zapytania na żywo.

Repozytorium
agent-skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
29.09.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
4
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 29.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Łączy aplikacje Node, Deno, Bun i przeglądarkę z SurrealDB przez SDK surrealdb: uwierzytelnianie, CRUD i zapytania na żywo.

Oryginalny opis (EN)

Using SurrealDB from JavaScript and TypeScript with the official surrealdb SDK, covering connecting (WebSocket/HTTP and embedded engines), authentication, CRUD, parameterized queries, and live queries. Use when connecting to SurrealDB from Node, Deno, Bun, or the browser, using the surrealdb npm package, or performing CRUD and real-time operations from JS/TS code. Triggers: surrealdb JS, surrealdb.js, new Surreal(), db.query, db.create, db.live, TypeScript SDK, npm i surrealdb.

Jak działa

  1. Installation
  2. Connect & select namespace/database
  3. Authentication
  4. CRUD
  5. Queries
  6. Live queries
  7. References
  8. Resources
Sekcje z nagłówków SKILL.md, w oryginale · 165 linii, 678 słów
Podgląd SKILL.md
---
name: surrealdb-js
description: "Using SurrealDB from JavaScript and TypeScript with the official surrealdb SDK, covering connecting (WebSocket/HTTP and embedded engines), authentication, CRUD, parameterized queries, and live queries. Use when connecting to SurrealDB from Node, Deno, Bun, or the browser, using the surrealdb npm package, or performing CRUD and real-time operations from JS/TS code. Triggers: surrealdb JS, surrealdb.js, new Surreal(), db.query, db.create, db.live, TypeScript SDK, npm i surrealdb."
metadata:
  author: surrealdb
  version: "0.2.0"
---

# SurrealDB JavaScript SDK

The official SDK (`surrealdb` on npm) works in Node.js, Deno, Bun, and the
browser. It connects to a remote SurrealDB instance over WebSocket/HTTP, or runs
an embedded engine in-process. Target the **latest** stable `surrealdb` release;
install without pinning (`npm i surrealdb`) unless the user requires a specific
version.

## Installation

```bash
npm i surrealdb
# or: pnpm i surrealdb / yarn add surrealdb / bun add surrealdb
```

## Connect & select namespace/database

Always `connect`, then `use` a namespace + database, then authenticate. Close
the connection when finished.

```ts
import { Surreal } from "surrealdb";

const db = new Surreal();
await db.connect("ws://127.0.0.1:8000/rpc");
await db.use({ namespace: "test", database: "test" });
await db.signin({ username: "root", password: "root" });

// ... work ...

await db.close();
```

Run a local server with `surreal start -u root -p root rocksdb:mydb` (or
in-memory with `surreal start -u root -p root`). To run SurrealDB in-process
with no server, see [references/embedded.md](references/embedded.md).

## Authentication

```ts
// Root / namespace / database users
await db.signin({ username: "root", password: "root" });
await db.signin({ namespace: "test", username: "ns_user", password: "..." });
await db.signin({ namespace: "test", database: "test", username: "db_user", password: "..." });

// Record (scope) access — sign in / sign up against a DEFINE ACCESS method
const token = await db.signin({
  namespace: "test",
  database: "test",
  access: "user",          // name of the access method
  variables: { email: "a@b.com", pass: "secret" },
});

await db.signup({
  namespace: "test",
  database: "test",
  access: "user",
  variables: { email: "a@b.com", pass: "secret" },
});

await db.authenticate(token); // re-auth with a stored JWT
await db.invalidate();        // log out the current session
const me = await db.info();   // info about the authenticated record user
```

## CRUD

Pass a table as a string (`"person"`) or a `RecordId` for a specific record.
See [references/data-types.md](references/data-types.md) for `RecordId`, `Table`,
`Duration`, `Decimal`, and other value classes.

```ts
import { RecordId } from "surrealdb";

interface Person { id: RecordId; name: string; age?: number; }

// Create (random id, or a specific RecordId)
await db.create<Person>("person", { name: "Tobie" });
await db.create<Person>(new RecordId("person", "tobie"), { name: "Tobie" });

// Select all from a table, or a single record
const people = await db.select<Person>("person");
const tobie = await db.select<Person>(new RecordId("person", "tobie"));

// Replace the whole record(s)
await db.update<Person>(new RecordId("person", "tobie"), { name: "Tobie", age: 30 });

// Insert or update (upsert)
await db.upsert<Person>(new RecordId("person", "tobie"), { name: "Tobie" });

// Merge partial data into record(s)
await db.merge<Person>("person", { active: true });

// JSON Patch a record
await db.patch(new RecordId("person", "tobie"), [
  { op: "replace", path: "/name", value: "Tobie M H" },
]);

// Bulk insert
await db.insert<Person>("person", [{ name: "A" }, { name: "B" }]);

// Graph relation:  person:tobie ->wrote-> article:surreal
await db.relate(new RecordId("person", "tobie"), "wrote", new RecordId("article", "surreal"));

// Delete record(s)
await db.delete("person");
await db.delete(new RecordId("person", "tobie"));
```

## Queries

`db.query<T>(sql, vars)` runs raw SurrealQL and returns an **array with one entry
per statement**. Always pass user input via bound parameters, never string
interpolation.

```ts
const [people, count] = await db.query<[Person[], number]>(
  `SELECT * FROM person WHERE age > $min;
   SELECT count() FROM person GROUP ALL;`,
  { min: 18 },
);

// Bind values and RecordIds as parameters
const [found] = await db.query<[Person[]]>(
  "SELECT * FROM person WHERE id = $who",
  { who: new RecordId("person", "tobie") },
);
```

Other helpers: `db.let(name, value)` / `db.unset(name)` set session parameters
usable as `$name` in later queries; `db.run(fnName, version, args)` invokes a
defined function; `db.queryRaw()` returns the unparsed RPC response (status +
timing per statement).

## Live queries

Subscribe to real-time changes on a table with `db.live()`. Requires a
WebSocket (or embedded) connection — not HTTP. See
[references/live-queries.md](references/live-queries.md).

```ts
const queryUuid = await db.live<Person>("person", (action, result) => {
  // action: "CREATE" | "UPDATE" | "DELETE" | "CLOSE"
  console.log(action, result);
});

await db.kill(queryUuid); // stop the subscription
```

## References

- [references/data-types.md](references/data-types.md) — `RecordId`, `Table`,
  `Duration`, `Decimal`, `Uuid`, geometry, and CBOR mapping.
- [references/embedded.md](references/embedded.md) — embedded engines via
  `@surrealdb/node` (RocksDB / SurrealKV / in-memory) and `@surrealdb/wasm`
  (in-memory / IndexedDB).
- [references/live-queries.md](references/live-queries.md) — `live`,
  `subscribeLive`, and `kill` patterns.

## Resources

- [SDK documentation](https://surrealdb.com/docs/sdk/javascript)
- [GitHub repository](https://github.com/surrealdb/surrealdb.js)
Pliki w paczce (4)
  • SKILL.md 6 KB
  • references/data-types.md 3 KB
  • references/embedded.md 2 KB
  • references/live-queries.md 2 KB

Wersje

W bazie nie ma innych skilli o nazwie surrealdb-js.

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 11eba2ba4df1 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95surrealdb-python
    Łączy się z SurrealDB z Pythona przez SDK, w trybie serwera przez WebSocket lub wbudowanym, z operacjami CRUD.
  • 100surrealdb
    Pomaga w SurrealDB 3: modelowanie danych, zapytania SurrealQL, grafy, wektory, uprawnienia, wdrożenia i integracje SDK.
  • 100surrealdb-agent-memory-docs
    Pobiera oficjalną dokumentację SurrealDB Agent Memory z surrealdb.com i odpowiada na pytania o szybki start, SDK i konfigurację.
  • 90sentry-node-sdk
    Konfiguruje Sentry SDK dla Node.js, Bun i Deno po stronie serwera: monitoring błędów, trasowanie, logi, profilowanie i metryki.
  • 95deno
    Pomaga budować aplikacje w Deno: uprawnienia, importy przez URL, bibliotekę std, Deno Deploy i framework Fresh.
  • 90ax-add-ingest-stage
    Dodaje nowy etap ingestu lub nową tabelę SurrealDB do grafu ax, uwzględniając pułapki rejestracji, które powodują błąd CI.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.