surrealdb-js
Skill27 starsChanged 2 months agoMITView on GitHub
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.
- Installs packages
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- Quad4-Software/skillsedited, first seen Oct 3, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- Quad4-Software/skills★ 1100% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- surrealdb-agent-memory-docsSkill
- surrealdb-cliSkill
- surrealdb-docsSkill
- surrealdb-pythonSkill
- surrealdb-vectorSkill
- surrealkitSkill
- surrealql-functionsSkill
- surrealql-performanceSkill
- surrealqlSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Always connect, then use a namespace + database, then authenticate.
- Very specific: line 42
Run a local server with surreal start -u root -p root rocksdb:mydb (or in-memory with surreal start -u root -p root).
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
npm i surrealdb
# or: pnpm i surrealdb / yarn add surrealdb / bun add surrealdbConnect & select namespace/database
Always connect, then use a namespace + database, then authenticate. Close
the connection when finished.
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.
Authentication
// 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 userCRUD
Pass a table as a string ("person") or a RecordId for a specific record.
See references/data-types.md for RecordId, Table,
Duration, Decimal, and other value classes.
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.
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.
const queryUuid = await db.live<Person>("person", (action, result) => {
// action: "CREATE" | "UPDATE" | "DELETE" | "CLOSE"
console.log(action, result);
});
await db.kill(queryUuid); // stop the subscriptionReferences
- references/data-types.md —
RecordId,Table,Duration,Decimal,Uuid, geometry, and CBOR mapping. - references/embedded.md — embedded engines via
@surrealdb/node(RocksDB / SurrealKV / in-memory) and@surrealdb/wasm(in-memory / IndexedDB). - references/live-queries.md —
live,subscribeLive, andkillpatterns.
Resources
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

