Skip to content
NEW

Introducing SurrealDB Studio, the new official app of SurrealDB

Learn more

1/3

FUNCTIONS

Functions inside the database

Push logic to where the data lives. Define reusable SurrealQL functions, drop into JavaScript when you need it, and load sandboxed WebAssembly extensions in Rust - all executing in the same ACID transaction as your query, with no service to call and no data to ship over the wire.

01 |IN-DATABASE LOGIC

From one-liners to compiled extensions

Custom functions, embedded JavaScript, and WebAssembly modules give you a ladder from a quick helper to native-speed compute, all callable directly from SurrealQL.

CUSTOM FUNCTIONS

Reusable logic, defined once

DEFINE FUNCTION stores named, typed procedures in the database. Call them from any query the way you call built-ins.

DEFINE FUNCTION fn::get::person(
$first: string,
$last: string,
$birthday: string
) {
LET $person = SELECT * FROM person WHERE
first = $first AND
last = $last AND
birthday = $birthday;

RETURN IF $person[0].id {
$person[0]
} ELSE {
CREATE person SET
first = $first,
last = $last,
birthday = $birthday
};
};

LET $person = fn::get::person('Tobie', 'Morgan Hitchcock', '2007-06-22');

WEBASSEMBLY EXTENSIONS

Native-speed logic, sandboxed

Write an extension in Rust, compile it to a WebAssembly module, and load it into a running database. Its functions become callable from SurrealQL, sandboxed and inside the transaction.

DEFINE MODULE mod::sentiment
FROM f"modules:/sentiment.surli" UNSIGNED;

UPDATE article SET
sentiment = mod::sentiment::analyze(content),
keywords = mod::sentiment::extract(content)
WHERE created_at > time::now() - 1h;

A full compute surface, next to your data

Built-in function families, custom procedures, scripting, and compiled extensions - every layer runs in the engine, in the transaction.

02 |ONE ENGINE

Move the compute to the data

Pulling rows into an application server, transforming them, and writing them back costs a round trip and breaks atomicity. Running the logic in the database removes both problems.

No round trips

Logic executes beside the data, so there is no fetch-transform-write hop across the network for every operation.

One transaction

Functions and extensions participate in the same ACID transaction as the query that calls them - results commit together or not at all.

One deployment

No function-as-a-service to provision, secure, and scale separately. The compute ships with the database.

Keep exploring

GET STARTED

Run your logic where your data lives

Define functions, script in JavaScript, and load WebAssembly extensions - all inside SurrealDB.

SamsungNVIDIAAppleVerizonTencent

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

SurrealDB

The unified data layer for AI

Graph, vector, document, and relational in one engine.
Agent Memory that connects and retrieves context wherever your data lives.

Explore with AI

Stay in the loop

Tutorials, AI agent recipes, and product updates, every two weeks.

Independently verified

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

Trust Centre

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom