These functions can be used to encode and decode data into other formats, such as base64 and CBOR (Concise Binary Object Representation). It is particularly used when that data needs to be stored and transferred over media that are designed to deal with text. This encoding and decoding helps to ensure that the data remains intact without modification during transport.
| Function | Description |
|---|---|
encoding::base64::decode()
| Decodes a base64-encoded string into bytes. |
encoding::base64::encode()
| Encodes bytes into a base64 string, with optional padding. |
encoding::cbor::decode()
| Decodes CBOR-formatted bytes into a SurrealQL value. |
encoding::cbor::encode()
| Encodes a SurrealQL value into CBOR-formatted bytes. |
encoding::json::decode()
| Decodes a JSON string into a SurrealQL value. |
encoding::json::encode()
| Encodes a SurrealQL value into a JSON string. |
encoding::base64::decode()
The encoding::base64::decode() function decodes a string into bytes.
The following example shows this function, and its output, when used in a RETURN statement:
You can also verify that the output of the encoded value matches the original value.
encoding::base64::encode()
The encoding::base64::encode() function encodes a bytes to base64 with optionally padded output.
The following example shows this function, and its output, when used in a RETURN statement:
As of version 2.3.0, you can pass true as the second argument to enable padded base64 outputs:
encoding::cbor::decode()
The encoding::cbor::decode() function decodes bytes in valid CBOR format into a SurrealQL value.
encoding::cbor::encode()
The encoding::cbor::encode() function encodes any SurrealQL value into bytes in CBOR format.
encoding::json::decode()
The encoding::json::decode() function decodes a JSON string into a SurrealQL value.
Examples of use:
encoding::json::encode()
The encoding::json::encode() function encodes a SurrealQL value into a JSON string.
Examples of use:
As JSON has fewer data types than SurrealDB, note that a round trip from SurrealQL to JSON and back to SurrealQL is not guaranteed to be the same type.
If a round trip is required, a combination of JSON and CBOR functions can be used.