SurrealDB Operations & Code Standards

Enforce a centralized injected QueryService for SurrealDB operations.

Updated Jan 9, 2026
One-click install
npx skills add https://github.com/HNULS-LabHub/HNULS-KnowledgeDatabase --skill surrealdb-operations-code-standards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: SurrealDB Operations & Code Standards
Source: https://github.com/HNULS-LabHub/HNULS-KnowledgeDatabase/tree/main/.agent/skills/SurrealDB%20Operations%20%26%20Code%20Standards
Command: npx skills add https://github.com/HNULS-LabHub/HNULS-KnowledgeDatabase --skill surrealdb-operations-code-standards

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

规范所有 SurrealDB 相关操作的编写方式,涵盖实例管理、查询模式、错误处理、并发安全、跨库查询、日志规范和类型安全。基于 KnowledgeDatabase 项目重构中总结的实战教训,防止"查询静默失败"、"并发串库"、"重复实例"三大顽疾。适用于 Main Process、Utility Process 及 SharedUtils 中所有与 SurrealDB 交互的代码。

Core Features & Use Cases

  • 单例化管理 SurrealDB 实例与查询服务,确保生命周期清晰且可注入
  • 参数化查询、类型安全与错误处理的统一实现,避免注入风险与静默失败
  • 并发安全与跨库查询保护,防止并发串库和数据不一致
  • 日志规范与跨项目复用,提供可追溯的操作日志和统一错误类型
  • 适用于 Main Process、Utility Process 及 SharedUtils 的 SurrealDB 交互代码

Quick Start

Follow the injection order to initialize SurrealDB services and inject the QueryService before exposing database operations.

Frequently Asked Questions about SurrealDB Operations & Code Standards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent query silent failures in SurrealDB?

Prevent query silent failures in SurrealDB by enforcing a centralized QueryService with fail-fast error handling and unified type safety. This ensures operations halt immediately upon encountering execution errors.

What is the best way to manage SurrealDB instance lifecycle across processes?

The best way to manage SurrealDB instance lifecycle is through singleton instance management and a centralized injection workflow. This guarantees a single, traceable instance across Main Process, Utility Process, and SharedUtils.

How do I handle concurrency safety for cross-database queries in SurrealDB?

Handle concurrency safety for SurrealDB cross-database queries by enforcing exclusive operation chains. This prevents concurrent cross-database operations from causing data inconsistency or database crossover issues.

How to standardize logging and parameterized queries for SurrealDB operations?

Standardize SurrealDB operations by routing all interactions through a single injected QueryService. This provides traceable operation logs, prevents injection risks via parameterized queries, and ensures consistent error types.

Does this SurrealDB standardization work for both Main Process and Utility Process?

Yes, this SurrealDB standardization applies across Main Process, Utility Process, and SharedUtils. It provides a shared, type-safe query layer that enforces consistent conventions regardless of the execution context.