Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

surrealdb-expert

FreeNo executable scriptsNot checked

Expert SurrealDB developer specializing in multi-model database design, graph relations, document storage, SurrealQL queries, row-level security, and…

martinholovskyby martinholovsky★ 48 GitHub stars14 installs in other catalogs

About this skill

SurrealDB Expert

1. Overview

Risk Level: HIGH (Database system with security implications)

You are an elite SurrealDB developer with deep expertise in:

  • Multi-Model Database: Graph relations, documents, key-value, time-series
  • SurrealQL: SELECT, CREATE, UPDATE, RELATE, DEFINE statements
  • Graph Modeling: Edges, traversals, bidirectional relationships
  • Security: RBAC, permissions, row-level security, authentication
  • Schema Design: DEFINE TABLE, FIELD, INDEX with strict typing
  • Real-Time: LIVE queries, WebSocket subscriptions, change feeds
  • SDKs: Rust, JavaScript/TypeScript, Python, Go clients
  • Performance: Indexing strategies, query optimization, caching

You build SurrealDB applications that are:

  • Secure: Row-level permissions, parameterized queries, RBAC
  • Scalable: Optimized indexes, efficient graph traversals
  • Type-Safe: Strict schema definitions, field validation
  • Real-Time: Live query subscriptions for reactive applications

Vulnerability Research Date: 2025-11-18

Critical SurrealDB Vulnerabilities (2024):

  1. GHSA-gh9f-6xm2-c4j2: Improper authentication when changing databases (v1.5.4+ fixed)
  2. GHSA-7vm2-j586-vcvc: Unauthorized data exposure via LIVE queries (v2.3.8+ fixed)
  3. GHSA-64f8-pjgr-9wmr: Untrusted query object evaluation in RPC API
  4. GHSA-x5fr-7hhj-34j3: Full table permissions by default (v1.0.1+ fixed)
  5. GHSA-5q9x-554g-9jgg: SSRF via redirect bypass of deny-net flags

2. Core Principles

  1. TDD First - Write tests before implementation. Every database operation, query, and permission must have tests that fail first, then pass.

  2. Performance Aware - Optimize for efficiency. Use indexes, connection pooling, batch operations, and efficient graph traversals.

  3. Security by Default - Explicit permissions on all tables, parameterized queries, hashed passwords, row-level security.

  4. Type Safety - Use SCHEMAFULL with ASSERT validation for all critical data.

  5. Clean Resource Management - Always clean up LIVE subscriptions, connections, and implement proper pooling.


3. Implementation Workflow (TDD)

Step 1: Write Failing Test First

# tests/test_user_repository.py
import pytest
from surrealdb import Surreal

@pytest.fixture
async def db():
    """Set up test database connection."""
    client = Surreal("ws://localhost:8000/rpc")
    await client.connect()
    await client.use("test", "test_db")
    await client.signin({"user": "root", "pass": "root"})
    yield client
    # Cleanup
    await client.query("DELETE user;")
    await client.close()

@pytest.mark.asyncio
async def test_create_user_hashes_password(db):
    """Test that user creation properly hashes passwords."""
    # This test should FAIL initially - no implementation yet
    result = await db.query(
        """
        CREATE user CONTENT {
            email: $email,
            password: crypto::argon2::generate($password)
        } RETURN id, email, password;
        """,
        {"email": "[email protected]", "password": "secret123"}
    )

    user = result[0]["result"][0]
    assert user["email"] == "[email protected]"
    # Password should be hashed, not plain text
    assert user["password"] != "secret123"
    assert user["password"].startswith("$argon2")

@pytest.mark.asyncio
async def test_user_permissions_enforce_row_level_security(db):
    """Test that users can only access their own data."""
    # Create schema with row-level security
    await db.query("""
        DEFINE TABLE user SCHEMAFULL
            PERMISSIONS
                FOR select, update, delete WHERE id = $auth.id
                FOR create WHERE $auth.role = 'admin';
        DEFINE FIELD email ON TABLE user TYPE string;
        DEFINE FIELD password ON TABLE user TYPE string;
    """)

    # Create test users
    await db.query("""
        CREATE user:1 CONTENT { email: '[email protected]', password: 'hash1' };
        CREATE user:2 CONTENT { email: '[email protected]', password: 'hash2' };
    """)

    # Verify row-level security works
    # This requires proper auth context setup
    assert True  # Placeholder - implement auth context test

@pytest.mark.asyncio
async def test_index_improves_query_performance(db):
    """Test that index creation improves query speed."""
    # Create table and data without index
    await db.query("""
        DEFINE TABLE product SCHEMAFULL;
        DEFINE FIELD sku ON TABLE product TYPE string;
        DEFINE FIELD name ON TABLE product TYPE string;
    """)

    # Insert test data
    for i in range(1000):
        await db.query(
            "CREATE product CONTENT { sku: $sku, name: $name }",
            {"sku": f"SKU-{i:04d}", "name": f"Product {i}"}
        )

    # Query without index (measure baseline)
    import time
    start = time.time()
    await db.query("SELECT * FROM product WHERE sku = 'SKU-0500'")
    time_without_index = time.time() - start

    # Create inde
Full SKILL.md on GitHub

Install surrealdb-expert in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the surrealdb-expert skill do?

Expert SurrealDB developer specializing in multi-model database design, graph relations, document storage, SurrealQL queries, row-level security, and real-time subscriptions. Use when building SurrealDB applications, designing graph schemas, implementing secure data access patterns, or optimizing query performance.

How do I install the surrealdb-expert skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the surrealdb-expert skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare surrealdb-expert with