MCPInstall

surrealql

Generate and modify SurrealQL queries to interact with SurrealDB databases. This includes creating and retrieving records, designing and managing schemas, establishing and querying graph relationships, performing live (real-time) queries, and leveraging all unique SurrealQL features for advanced database workflows. Use this skill whenever users need to write, adapt, or troubleshoot SurrealQL statements.

Installs
707
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/surrealdb/agent-skills --skill surrealql
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads surrealql automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

SurrealQL

A skill for writing and modifying SurrealQL queries to interact with SurrealDB databases.

SurrealQL is the official query language for SurrealDB. It is a modern, flexible, and powerful query language that is designed to be easy to learn and use.

When to use this skill

Reference these guidelines when:

  • Writing, modifying, or troubleshooting SurrealQL queries
  • Designing or managing schemas
  • Converting other query languages to SurrealQL

Version & Documentation

Always target the latest stable SurrealDB release. SurrealQL evolves between major versions, and syntax from older releases (e.g. SurrealDB 2.x) is a common source of incorrect, non-validating queries. Unless the user explicitly asks for an older version, generate current (3.x) syntax.

Determine the active version before generating version-sensitive syntax:

  • If the SurrealDB CLI is installed, run surreal version.

  • Otherwise, the latest released version is published as a plain string at https://download.surrealdb.com (e.g. v3.1.4):

    curl -s https://download.surrealdb.com
    

https://surrealdb.com/docs always documents the latest stable release — treat it as the source of truth for current syntax. When in doubt about whether a function or form still applies (for example type::* helpers and how record IDs are constructed), confirm against the current docs rather than assuming older behavior.

Rules & Conventions

  • SurrealQL is NOT ANSI-SQL. Never assume SQL knowledge from other databases applies. Always refer to the examples below or the documentation at https://surrealdb.com/docs for accurate syntax and behavior.
  • When SurrealQL is stored in a file, it should have a .surql extension.
  • SurrealQL is a relatively young language and changes between releases. Default to the latest SurrealDB version (see Version & Documentation) and refer to https://surrealdb.com/docs for the most up-to-date syntax.

Statements

Query Statements

StatementPurpose
SELECTQuery records, traverse graphs, aggregate data
CREATECreate new records (errors if record exists)
INSERTInsert one or more records or graph edges; supports ON DUPLICATE KEY UPDATE
UPDATEUpdate existing records (no-op if record doesn't exist)
UPSERTInsert a record, or update it if it already exists
DELETEDelete records or graph edges
RELATECreate graph edges between records
LIVE SELECTStream real-time changes to a table
KILLCancel an active LIVE SELECT query
LETAssign a value to a parameter
RETURNReturn a value from a block or function

Schema & Resource Statements

StatementPurpose
DEFINE NAMESPACEDefine a namespace
DEFINE DATABASEDefine a database
DEFINE TABLEDefine a table (schemafull, schemaless, as view)
DEFINE FIELDDefine a field with type, default, assertion
DEFINE INDEXDefine an index (unique, search, vector)
DEFINE EVENTDefine event triggers on a table
DEFINE FUNCTIONDefine a custom function
DEFINE ANALYZERDefine a search analyzer
DEFINE ACCESSDefine authentication access methods (Bearer, JWT, Record)
DEFINE APIDefine an API endpoint
DEFINE BUCKETDefine a storage bucket
DEFINE CONFIGDefine a configuration
DEFINE MODULEDefine a Surrealism extension module
DEFINE PARAMDefine a global parameter
DEFINE SEQUENCEDefine an auto-incrementing sequence
DEFINE USERDefine a system user
ALTERAlter an existing resource definition
REMOVERemove any defined resource
REBUILDRebuild an index
ACCESSManage access grants
USESwitch to a different namespace or database
INFOInspect definitions for a resource
SHOWView changefeed for a table or database

Control Flow Statements

StatementPurpose
BEGIN / COMMITBegin and commit a manual transaction
CANCELCancel a transaction
IF / ELSEConditional execution
FORIterate over values
BREAKExit a FOR loop early
CONTINUESkip to next iteration in a FOR loop
THROWCancel execution and return an error
SLEEPPause execution for a duration

References

For detailed querying patterns (filtering, graph traversal, aggregation, subqueries), see references/querying.md.

For schema management patterns (tables, fields, indexes, events, access), see references/schema.md.

For in-depth information about the values that can be stored in SurrealDB records, see references/values.md.

Validation

When generating SurrealQL queries, or modifying existing queries, you should always validate them using the SurrealDB CLI if available. Validation may fail to due version differences, at which point you can retrieve your SurrealDB CLI version with surreal version. Validation can only be performed against full queries or values, not partial or fragmentary statements.

Usage

# Validate a single file:
surreal validate query.surql

# Validate glob pattern of files:
surreal validate queries/*.surql

# Validate from stdin (available since SurrealDB v3.1.0):
echo "SELECT * FROM person WHERE age > 18" | surreal validate --stdin

Formatting

When generating SurrealQL queries or SQON values you may decide to format them using the surqlfmt CLI tool if a NodeJS-like runtime is available. Situations in which you should always format include:

  • When presenting queries to users
  • When generating migration files
  • When writing .surql files

Usage

# Format a file and print to stdout:
npx @surrealdb/surql-fmt query.surql

# Format files in-place:
npx @surrealdb/surql-fmt --write migrations/*.surql

# Check if files are already formatted (exits with code 1 if not):
npx @surrealdb/surql-fmt --check src/**/*.surql

# Format from stdin:
echo "SELECT * FROM person WHERE age>18" | npx @surrealdb/surql-fmt --stdin

FAQ

What does the surrealql skill do?

Generate and modify SurrealQL queries to interact with SurrealDB databases. This includes creating and retrieving records, designing and managing schemas, establishing and querying graph relationships, performing live (real-time) queries, and leveraging all unique SurrealQL features for advanced database workflows. Use this skill whenever users need to write, adapt, or troubleshoot SurrealQL statements.

How do I install surrealql?

Run npx skills add https://github.com/surrealdb/agent-skills --skill surrealql in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/surrealql/ (personal) or .claude/skills/surrealql/ (project).

Which AI agents can use surrealql?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is surrealql safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains surrealql?

It is published by surrealdb in surrealdb/agent-skills. It has 707 recorded installs.

More from surrealdb/agent-skills

View all →

surrealdb-vector

surrealdb/agent-skills

Vector search with SurrealDB using HNSW indexes, KNN queries, and similarity scoring. Use when creating vector indexes, querying vectors with KNN distance operators, building semantic search or RAG pipelines, tuning HNSW parameters (EFC, M, M0, distance function, type), or implementing recommendation systems with SurrealDB. Triggers: HNSW, vector, embedding, KNN, cosine, euclidean, semantic search, RAG, vector::distance.

AI & Agents537 installs

surrealdb-python

surrealdb/agent-skills

Open the skill to read its SKILL.md instructions.

AI & Agents427 installs

surrealql-performance

surrealdb/agent-skills

Open the skill to read its SKILL.md instructions.

surrealql-functions

surrealdb/agent-skills

Open the skill to read its SKILL.md instructions.

AI & Agents419 installs

surrealkit

surrealdb/agent-skills

Open the skill to read its SKILL.md instructions.

AI & Agents405 installs

surrealdb-cli

surrealdb/agent-skills

Open the skill to read its SKILL.md instructions.

AI & Agents403 installs

Popular data & databases skills

View category →

Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.

OfficialData & Databases462.2K installs

prisma-client-api

prisma/skills

Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".

OfficialData & Databases393.5K installs

Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.

OfficialData & Databases392.3K installs

prisma-cli

prisma/skills

Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.

OfficialData & Databases390.8K installs

prisma-postgres

prisma/skills

Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.

OfficialData & Databases384.4K installs

Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.

OfficialData & Databases378.9K installs