Composables

Other Composables

Additional SSR-safe composables for SurrealDB operations.

Other Composables

Beyond the main composables, Nuxt SurrealDB provides additional SSR-safe wrappers for common SurrealDB operations.

useSurrealRun

Run a SurrealQL function and return the result.

<script setup lang="ts">
const { data } = await useSurrealRun<number>('fn::get_count', ['users'])
</script>
ArgumentTypeDescription
nameMaybeRefOrGetter<string>The full function name (reactive)
args?MaybeRefOrGetter<unknown[]>Arguments supplied to the function (reactive)
asyncDataOptions?AsyncDataOptionsOptions for useAsyncData

useSurrealVersion

Returns the version information of the connected SurrealDB server.

<script setup lang="ts">
const { data: version } = await useSurrealVersion()
</script>
ArgumentTypeDescription
asyncDataOptions?AsyncDataOptionsOptions for useAsyncData

useSurrealExport

Export the database as a SurrealQL string.

<script setup lang="ts">
const { data: dump } = await useSurrealExport()
</script>
ArgumentTypeDescription
expOptions?MaybeRefOrGetter<Partial<SqlExportOptions>>Export options (reactive)
asyncDataOptions?AsyncDataOptionsOptions for useAsyncData

useSurrealImport

Import SurrealQL data into the database.

<script setup lang="ts">
const { data: ok } = await useSurrealImport('DEFINE TABLE users;')
</script>
ArgumentTypeDescription
inputMaybeRefOrGetter<string>The SurrealQL string to import (reactive)
asyncDataOptions?AsyncDataOptionsOptions for useAsyncData

useSurrealMemory

Access the in-memory WASM SurrealDB client. Requires @surrealdb/wasm.

<script setup lang="ts">
const client = await useSurrealMemory()

if (client) {
  const [results] = await client.query('SELECT * FROM test;').json().collect(0)
}
</script>

Returns Promise<Surreal | null>null if @surrealdb/wasm is not installed.

An alias useSurrealMem is also available.

useSurrealLocal

Access the local embedded WASM SurrealDB client. Requires @surrealdb/wasm.

<script setup lang="ts">
const client = await useSurrealLocal()

if (client) {
  const [results] = await client.query('SELECT * FROM test;').json().collect(0)
}
</script>

Returns Promise<Surreal | null>null if @surrealdb/wasm is not installed.

The IndexedDB WASM engine is currently bugged upstream. In-memory mode works as expected.