diff --git a/.changeset/big-mugs-admire.md b/.changeset/big-mugs-admire.md new file mode 100644 index 000000000..d5fc87108 --- /dev/null +++ b/.changeset/big-mugs-admire.md @@ -0,0 +1,5 @@ +--- +"@powersync/vue": minor +--- + +Introduced `useQuery` and `useStatus` composables which include compilable query support. Deprecated `usePowerSyncQuery`, `usePowerSyncWatchedQuery`, and `usePowerSyncStatus`. diff --git a/.changeset/seven-sheep-smell.md b/.changeset/seven-sheep-smell.md new file mode 100644 index 000000000..170ec5042 --- /dev/null +++ b/.changeset/seven-sheep-smell.md @@ -0,0 +1,5 @@ +--- +"vue-supabase-todolist": patch +--- + +Using new Vue `useQuery` and `useStatus` composables instead of deprecated ones. diff --git a/demos/vue-supabase-todolist/src/components/LoadingMessage.vue b/demos/vue-supabase-todolist/src/components/LoadingMessage.vue index 8cfa023f5..c841ccd03 100644 --- a/demos/vue-supabase-todolist/src/components/LoadingMessage.vue +++ b/demos/vue-supabase-todolist/src/components/LoadingMessage.vue @@ -14,27 +14,27 @@ diff --git a/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue b/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue index 4aea95035..14456484e 100644 --- a/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue +++ b/demos/vue-supabase-todolist/src/components/widgets/TodoListsWidget.vue @@ -1,6 +1,6 @@ ``` -### Queries +## Query -The `usePowerSyncQuery` composable provides a static view of a given query. You can use refs as parameters instead to automatically refresh the query when they change. The composable exposes reactive variables for the results, the loading state and error state, as well as a refresh callback that can be invoked to rerun the query manually. +The `useQuery` composable provides a dynamic view of a given query. The data will automatically update when a dependent table is updated. + +You can use refs as parameters to refresh the query when they change. The composable exposes reactive variables for the results as well as the loading, fetching, and and error states. Note that `isLoading` indicates that the initial result is being retrieved and `isFetching` indicates the query is fetching data, which could be for the initial load or any time when the query is re-evaluating due to a change in a dependent table. ```Vue // TodoListDisplayQuery.vue ``` -### Watched Queries +### Static query -The `usePowerSyncWatchedQuery` composable provides a dynamic view of a given query. The data will automatically update when a dependent table is updated. - -You can use refs as parameters to refresh the query when they change. The composable exposes reactive variables for the results as well as the loading, fetching, and and error states. Note that `loading` initicates that the initial result is being retrieved and `fetching` indicates the query is fetching data, which could be for the initial load or any time when the query is re-evaluating due to a change in a dependent table. +The `useQuery` composable can be configured to only execute initially and not every time changes to dependent tables are detected. The query can be manually re-executed by using the returned `refresh` function. ```Vue -// TodoListDisplayWatchedQuery.vue +// TodoListDisplayStaticQuery.vue -
{{ error }}
- - +``` + +### TypeScript Support + +A type can be specified for each row returned by `useQuery`. Remember to declare `lang="ts"` when defining a `script setup` block. + +```Vue +// TodoListDisplayStaticQueryTypeScript.vue + + + ``` -### Connection Status +You are also able to use a compilable query (e.g. [Kysely queries](https://github.com/powersync-ja/powersync-js/tree/main/packages/kysely-driver)) as a query argument in place of a SQL statement string. + +```Vue +// TodolistDisplayQueryKysely.vue + +``` + +## Connection Status -The `usePowerSyncStatus` composable provides general connectivity information such as the connection status, whether the initial full sync has completed, when the last sync completed, and whether any data is being uploaded or downloaded. +The `useStatus` composable provides general connectivity information such as the connection status, whether the initial full sync has completed, when the last sync completed, and whether any data is being uploaded or downloaded. ```Vue // ConnectionStatus.vue