drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: useLiveQuery() to have option to disable the query
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
Taking example on react query hook, a query can be disabled by passing an option.
For example, if you have a query that depend on parameters that might be undefined, you would want to not run the query when those parameter are undefined :
```ts
const user = useLiveQuery(db.query.users.findFirst({where: eq(users.id, selectedUserId)}, {enabled: !!selectedUserId})
```
This would allow enabling / disabling live queries depending on the state / the parameters / the visibility of the component, improving efficiency and removing some potential errors such as filtering on an empty field:
```ts
const [ageFilter, setAgeFilter] = useState(null)
const userAged30OrMore = useLiveQuery(db.query.users.findMany({where: gte(users.age, ageFilter)}, {enabled: typeof ageFilter === "number"})
```
Contributor guide
Research direction
Start at the useLiveQuery() hook entry point and review how its query arguments and options are currently handled. Implement the requested enabled behavior from the examples, then verify that queries stay disabled when parameters are unavailable and run normally when enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 67/100