Skip to content

Commit

Permalink
feat(insert): new useSurrealDB function
Browse files Browse the repository at this point in the history
  • Loading branch information
sandros94 committed May 31, 2024
1 parent 5467290 commit fd46b99
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/runtime/composables/surreal-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ export function useSurrealDB(overrides?: Overrides) {

// TODO: info
// TODO: insert [ thing, data ]
async function $insert<T = any>(
thing: MROGParam<T, 'insert', 0>,
opts?: Overrides & { data?: MROGParam<T, 'insert', 1> },
) {
const { data, ...ovr } = opts || {}
return $surrealRPC<T>({ method: 'insert', params: [toValue(thing), toValue(data)] }, ovr)
}
async function insert<T = any>(
thing: MROGParam<T, 'insert', 0>,
options?: SurrealRpcOptions<T> & { data?: MROGParam<T, 'insert', 1> },
): Promise<AsyncData<RpcResponse<T> | null, FetchError<any> | null>> {
const { data, immediate, key, watch, ...opts } = options || {}

const params = computed<RpcRequest<T, 'insert'>['params']>(() => ([toValue(thing), toValue(data)]))
const _key = key ?? 'Sur_' + hash(['surreal', 'insert', toValue(params)])

return useSurrealRPC<T>({ method: 'insert', params }, {
...opts,
immediate: immediate === undefined ? false : immediate,
key: _key,
watch: false,
})
}

// TODO: invalidate
// TODO: merge [ thing, data ]
// TODO: patch [ thing, patches, diff ]
Expand Down Expand Up @@ -147,6 +171,8 @@ export function useSurrealDB(overrides?: Overrides) {
return {
$create,
create,
$insert,
insert,
$query,
query,
$select,
Expand Down

0 comments on commit fd46b99

Please sign in to comment.