Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add DQL support #65

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

feat: Add DQL support #65

wants to merge 13 commits into from

Conversation

pvditto
Copy link
Contributor

@pvditto pvditto commented Sep 20, 2024

Adds support for DQL (see online documentation) by adding two new hooks: useQuery() and useExecuteQuery().

Also adds a new example app based on the new DQL hooks at examples/dql-create-react-app-typescript-example.

The minimum supported version of @dittolive/ditto changes to 4.8.1.

Usage

A quick overview, refer to the API reference for more details.

The useQuery() hook immediately sets up a store observer and sync subscription for a given query. This hook only supports non-mutating DQL syntax.

 const { items } = useQuery(
   'select * from tasks where _id = :id limit 10', {
     queryArguments: { id: '123' },
   }
 )

The useExecuteQuery() hook returns a function that can be called to execute a query on demand, e.g. for mutating data.

```tsx
const [executeQuery] = useExecuteQuery(
  'insert into tasks documents (:task)',
  {
    queryArguments: { task: { author: 'Alice' } },
  },
)

// Clicking the button will execute the query with query arguments
// `{ task: { author: 'Alice', description: 'Buy milk' } }`.
return <button
 onClick={() => executeQuery({ task: { description: 'Buy milk' } })}
>Add Task</button>

@pvditto pvditto added the enhancement New feature or request label Sep 20, 2024
@pvditto pvditto self-assigned this Sep 20, 2024
Base automatically changed from pv/esm-export to master September 25, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant