Escape functions provide safe handling of identifiers and values in SurrealQL queries when you need to construct queries manually.
Tip
Import:
Source: utils/escape.ts
Functions
escapeIdent(name)
Escape table names, field names, and other identifiers.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The identifier to escape. |
Returns
string - Escaped identifier
Examples
escapeKey(key)
Escape object keys for use in queries.
Returns
string - Escaped key
Example
escapeRid(value)
Escape record ID components.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | number | The record ID component to escape. |
Returns
string - Escaped record ID component
Examples
escapeValue(value)
Escape values for use in queries.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to escape. |
Returns
string - Escaped value representation
Examples
Complete examples
Dynamic table names
Dynamic field selection
Building raw queries (not recommended)
When to use
✅ use escape functions when:
Constructing queries with user-provided table/field names
Working with identifiers that have special characters
Building dynamic schema definitions
Interfacing with external query builders
❌ prefer other solutions:
For values: Use
surqlorBoundQueryFor tables: Use
TableclassFor record IDs: Use
RecordIdclassFor conditions: Use
expr
Best practices
1. Prefer type-safe alternatives
2. Validate before escaping
3. Use surql for complex queries
Security considerations
Warning
See also
surql - Recommended for parameterized queries
BoundQuery - Parameterized query class
Table - Type-safe table references
RecordId - Type-safe record identifiers