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>
| Argument | Type | Description |
|---|---|---|
name | MaybeRefOrGetter<string> | The full function name (reactive) |
args? | MaybeRefOrGetter<unknown[]> | Arguments supplied to the function (reactive) |
asyncDataOptions? | AsyncDataOptions | Options for useAsyncData |
useSurrealVersion
Returns the version information of the connected SurrealDB server.
<script setup lang="ts">
const { data: version } = await useSurrealVersion()
</script>
| Argument | Type | Description |
|---|---|---|
asyncDataOptions? | AsyncDataOptions | Options for useAsyncData |
useSurrealExport
Export the database as a SurrealQL string.
<script setup lang="ts">
const { data: dump } = await useSurrealExport()
</script>
| Argument | Type | Description |
|---|---|---|
expOptions? | MaybeRefOrGetter<Partial<SqlExportOptions>> | Export options (reactive) |
asyncDataOptions? | AsyncDataOptions | Options for useAsyncData |
useSurrealImport
Import SurrealQL data into the database.
<script setup lang="ts">
const { data: ok } = await useSurrealImport('DEFINE TABLE users;')
</script>
| Argument | Type | Description |
|---|---|---|
input | MaybeRefOrGetter<string> | The SurrealQL string to import (reactive) |
asyncDataOptions? | AsyncDataOptions | Options 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.