Skip to main content

useQuery()

function useQuery<T>(
query,
sqlParameters,
options): WatchedQueryResult<T>

A composable to access the results of a watched query.

Type parameters

Type parameterValue
Tany

Parameters

ParameterTypeDefault value
queryMaybeRef<string | CompilableQuery<T>>undefined
sqlParametersMaybeRef<any[]>[]
optionsAdditionalOptions{}

Returns

WatchedQueryResult<T>

Example

<script setup>
import { useQuery } from '@powersync/vue';

const { data, isLoading, isFetching, error} = useQuery('SELECT * FROM lists');
</script>

<template>
<div v-if="isLoading">Loading...</div>
<div v-else-if="isFetching">Updating results...</div>

<div v-if="error">{{ error }}</div>
<ul v-else>
<li v-for="l in data" :key="l.id">{{ l.name }}</li>
</ul>
</template>