SurrealDB Docs Logo

Enter a search query

Set parameters

Within your application, you can define parameters that can be used to store and retrieve data from SurrealDB. Parameters are used to store data in a structured format, and can be used to store data in a key-value pair format.

Important

Parameters allow you to define global (database-wide) parameters that are available to every client.

MethodDescription
db.let(key, value)Assigns a value as a parameter for this connection
db.unset(key)Removes a parameter for this connection

.let()

Assigns a value as a parameter for this connection.

Method Syntax
db.let(key, value)

Arguments

ArgumentsDescription
key required

Specifies the name of the variable.

value required

Assigns the value to the variable name.

Example Usage

# Assign the variable on the connection db.let('name', { "first": 'Tobie', "last": 'Morgan Hitchcock', }) # Use the variable in a subsequent query db.query('CREATE person SET name = $name') # Use the variable in a subsequent query db.query('SELECT * FROM person WHERE name.first = $name.first')

.unset()

Removes a parameter for this connection.

Method Syntax
db.unset(key)

Arguments

ArgumentsDescription
key required

Specifies the name of the variable.

Example usage

# Remove the variable from the connection
db.unset('name')