Built-in Functions
Anvil includes 55+ built-in functions covering aggregation, string manipulation, math, list operations, type conversion, temporal, and spatial operations.
Scalar Functions
| Function | Description |
|---|
| id(node) | Internal node ID |
| type(rel) | Relationship type string |
| labels(node) | List of node labels |
| properties(entity) | Properties map (excludes internals) |
| keys(map) | List of map keys |
| coalesce(a, b, ...) | First non-null value |
| exists(expr) | Whether expression is non-null |
| toBoolean(expr) | Convert to boolean |
| timestamp() | Current epoch milliseconds |
| randomUUID() / uuid() | Generate UUID v4 (requires write access; see Generated Values) |
String Functions
| Function | Description |
|---|
| toString(x) | Convert to string |
| toUpper(s) / toLower(s) | Case conversion |
| trim(s) / ltrim(s) / rtrim(s) | Whitespace trimming |
| replace(s, from, to) | Replace substring |
| substring(s, start, len?) | Extract substring |
| left(s, n) / right(s, n) | First/last n characters |
| split(s, delimiter) | Split into list |
| reverse(s) | Reverse string |
| size(s) | String length |
Math Functions
| Function | Description |
|---|
| abs(n) | Absolute value |
| ceil(n) / floor(n) / round(n) | Rounding |
| sign(n) | Sign (-1, 0, or 1) |
| sqrt(n) | Square root |
| log(n) / log10(n) | Natural / base-10 logarithm |
| exp(n) | Euler's number raised to n |
| e() / pi() | Mathematical constants |
| rand() | Random float between 0 and 1 |
| toInteger(x) / toFloat(x) | Numeric type conversion |
List Functions
| Function | Description |
|---|
| size(list) | Number of elements |
| head(list) | First element |
| last(list) | Last element |
| tail(list) | All elements except first |
| range(start, end, step?) | Generate integer range |
| reverse(list) | Reverse list order |
| nodes(path) | List of nodes in a path |
| relationships(path) | List of relationships in a path |
Temporal Functions
| Function | Description |
|---|
| date() | Current date |
| datetime() | Current datetime |
| time() | Current time |
| duration({days: 5}) | Create a duration |
| date.truncate('month', d) | Truncate to unit |
| datetime.truncate('hour', dt) | Truncate datetime to unit |
Spatial Functions
| Function | Description |
|---|
| point({x, y}) | 2D Cartesian point |
| point({x, y, z}) | 3D Cartesian point |
| point({latitude, longitude}) | Geographic point (WGS 84) |
| distance(p1, p2) | Distance between points (Haversine for geographic) |