Back to top
Documentation SurrealQL Functions Scripting functions

Embedded scripting functions

SurrealDB allows for advanced functions with complicated logic, by allowing embedded functions to be written in JavaScript. These functions support the ES2020 JavaScript specification.

Simple functions

Embedded JavaScript functions within SurrealDB support all functionality in the ES2020 specification including async / await functions, and generator functions. Any value from SurrealDB is converted into a JavaScript type automatically, and the return value from the JavaScript function is converted to a SurrealDB value.

CREATE person SET scores = function() {
	return [1,2,3].map(v => v * 10);

Function arguments

Pass arguments to embedded scripting functions, and access them.

Built-in functions

Various built-in functions and utilities in the embedded scripting functions.

Function context

Access properties from the current document.

Type conversion

Type conversion between the JavaScript runtime and SurrealQL.

SurrealQL functions

Access native SurrealQL functions within the embedded scripting functions.