Skills2026年4月12日·1 分钟阅读

SurrealDB — Scalable Multi-Model Database for Modern Apps

SurrealDB is a scalable, distributed, collaborative, document-graph database for the real-time web. Combines relational, document, graph, and time-series models in one database with SurrealQL query language. Built in Rust for performance and reliability.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
先审查命令
npx -y tokrepo@latest install 9033274f-3649-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
SurrealDB unifies relational, document, graph, and time-series models with SurrealQL.
§01

What it is

SurrealDB is a scalable, multi-model database designed for the real-time web. It combines relational, document, graph, and time-series data models in a single database with its own query language called SurrealQL. You can write SQL-like queries that traverse graphs, filter documents, and aggregate time-series data in one statement.

SurrealDB targets full-stack developers building real-time applications who want to avoid managing separate databases for different data models.

§02

How it saves time or tokens

SurrealDB eliminates the need for a document store, a graph database, and a relational database. One connection string, one query language, one backup process. The built-in permissions system means you can expose SurrealDB directly to the frontend with row-level security, removing the need for a separate backend API for simple CRUD operations.

Real-time subscriptions via WebSocket push data changes to clients without polling.

§03

How to use

  1. Install SurrealDB: curl -sSf https://install.surrealdb.com | sh
  2. Start the server: surreal start --user root --pass root
  3. Connect with the CLI: surreal sql --conn http://localhost:8000 --user root --pass root
  4. Create tables and query with SurrealQL
§04

Example

-- Create a user document
CREATE user:alice SET name = 'Alice', age = 30, role = 'engineer';

-- Create a graph edge
RELATE user:alice->works_at->company:acme SET since = '2024-01-01';

-- Query with graph traversal
SELECT name, ->works_at->company.name AS company
FROM user
WHERE role = 'engineer';

-- Real-time subscription
LIVE SELECT * FROM user WHERE age > 25;
§05

Related on TokRepo

§06

Common pitfalls

  • SurrealDB is younger than PostgreSQL or MongoDB; the ecosystem of drivers and ORM integrations is smaller
  • The direct-to-frontend pattern requires careful permission configuration; misconfigured DEFINE TABLE PERMISSIONS can expose data
  • SurrealQL looks like SQL but has significant differences in syntax for graph traversals and record IDs

常见问题

How does SurrealDB compare to PostgreSQL?+

PostgreSQL is a mature relational database with extensions for JSON and limited graph queries. SurrealDB is purpose-built for multi-model data with native graph traversals, real-time subscriptions, and document storage. PostgreSQL has a far larger ecosystem; SurrealDB has a more integrated multi-model experience.

Can SurrealDB replace MongoDB?+

For document storage, SurrealDB is a capable alternative. It stores schemaless JSON documents and supports flexible querying. The advantage is that you also get graph and relational capabilities without adding another database. The tradeoff is a smaller ecosystem and fewer managed hosting options.

Does SurrealDB support real-time subscriptions?+

Yes. LIVE SELECT queries push changes to connected clients via WebSocket whenever matching data changes. This enables real-time features like chat, notifications, and collaborative editing without polling.

What languages have SurrealDB drivers?+

Official drivers exist for Rust, JavaScript/TypeScript, Python, Go, Java, and .NET. The JavaScript SDK works in both Node.js and browsers, enabling the direct-to-frontend pattern.

Is SurrealDB production-ready?+

SurrealDB is in active development. It is used in production by some teams, but it is newer than established databases. Evaluate its stability against your requirements and have a fallback plan for critical workloads.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产