Skip to content

Commit

Permalink
feat(merge): new useSurrealDB function
Browse files Browse the repository at this point in the history
  • Loading branch information
sandros94 committed May 31, 2024
1 parent fd46b99 commit f2d9e7a
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 @@ -80,6 +80,30 @@ export function useSurrealDB(overrides?: Overrides) {

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

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

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

// TODO: patch [ thing, patches, diff ]

// query [ sql, vars ]
Expand Down Expand Up @@ -173,6 +197,8 @@ export function useSurrealDB(overrides?: Overrides) {
create,
$insert,
insert,
$merge,
merge,
$query,
query,
$select,
Expand Down

0 comments on commit f2d9e7a

Please sign in to comment.