• Start

Languages

/

Mojo

/

Methods

set

The set() method for the SurrealDB Mojo SDK assigns a value as a parameter for this connection.

Assigns a value to a parameter for the connection, so you can reference it as $name in subsequent queries.

Method Syntax

client.set(name, value_cbor, session)
ArgumentDescription
nameThe parameter name, without the leading $.
value_cborThe value, CBOR-encoded as a List[UInt8].
sessionAn optional session id.

For common scalar types, the SDK provides wrappers that encode the value for you:

  • set_string(name, value, session)

  • set_int(name, value, session)

  • set_bool(name, value, session)

client.set_string("name", "Chiru")
client.set_int("age", 30)

var resp = client.query("SELECT * FROM person WHERE name = $name AND age >= $age;")

To encode a value by hand, use CborCodec:

from surrealdb import CborCodec

var codec = CborCodec()
client.set("name", codec.encode_text("Chiru"))

Was this page helpful?