Skip to content

Commit

Permalink
feat(useSurrealDB): sql function
Browse files Browse the repository at this point in the history
  • Loading branch information
sandros94 committed May 27, 2024
1 parent 9cdd32c commit 688d9c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
13 changes: 6 additions & 7 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<pre v-if="test && !error">
{{ test }}
<pre v-if="data && !error">
{{ data }}
</pre>
<div v-else-if="error">
{{ error }}
Expand All @@ -10,9 +10,8 @@
</div>
</template>

<script setup>
const { data: test, error } = await useSurrealFetch('sql', {
method: 'POST',
body: 'SELECT * FROM products',
})
<script setup lang="ts">
const { sql } = useSurrealDB()
const { data, error } = await sql('SELECT * FROM products;')
</script>
16 changes: 16 additions & 0 deletions src/runtime/composables/surreal-db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Overrides } from '../types'
import { useSurrealFetch } from '#imports'

export function useSurrealDB(overrides?: Overrides) {
async function sql<T>(sql: string, ovr?: Overrides) {
return useSurrealFetch<T>('sql', {
...(ovr || overrides),
method: 'POST',
body: sql,
})
}

return {
sql,
}
}

0 comments on commit 688d9c2

Please sign in to comment.