Escape Functions
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