Composables
useSurreal
Access the remote SurrealDB client in your Vue components.
useSurreal
The useSurreal composable returns the main Surreal client instance connected to your remote SurrealDB endpoint. It auto-connects on first use based on your module configuration.
Usage
app/pages/index.vue
<script setup lang="ts">
const client = await useSurreal()
// Use the SDK directly
const results = await client.query('SELECT * FROM users;').json().collect(0)
</script>
Return type
Returns Promise<Surreal> — the connected SurrealDB client instance from the official SDK.
How it works
- On first call, the composable reads the endpoint and connection options from
runtimeConfig.public.surrealdb - If
autoConnectis enabled (default), it connects automatically - During SSR, if
preferHttpis enabled (default), WebSocket URLs are converted to HTTP - The
surrealdb:connectingandsurrealdb:connectedhooks are called during the connection lifecycle
Direct SDK access
You can also access the Surreal client directly via the Nuxt app instance:
const { $surreal } = useNuxtApp()
Available properties:
$surreal— the remoteSurrealclient$surrealMemory— the in-memory WASM client (ornull)$surrealLocal— the local WASM client (ornull)