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

Live queries ✨ #165

Open
edobrb opened this issue Apr 20, 2022 · 0 comments · May be fixed by #166
Open

Live queries ✨ #165

edobrb opened this issue Apr 20, 2022 · 0 comments · May be fixed by #166
Labels
📅 approved New feature approved and scheduled ✨ feature request New feature or request
Milestone

Comments

@edobrb
Copy link
Collaborator

edobrb commented Apr 20, 2022

Live queries are needed to support graphql subscriptions.

API proposal:

const user = ... User DAO ...
const lq: LiveQuery<{ name: string } | null> = await user.liveFindOne({ filter: { live: true  }, projection: { name: true }, sorts: [ { name: 'asc' } ], skip: 1 })
const it = lq.asyncIterator()
const firstUser = (await it.next()).value
const secondUser = (await it.next()).value
lq.close()
const user = ... User DAO ...
const lq: LiveQuery<{ name: string }[]> = await user.liveFindAll({ filter: { live: true  }, projection: { name: true }, sorts: [ { name: 'asc' } ], skip: 1, limit: 2 })
const it = lq.asyncIterator()
const firstUsers = (await it.next()).value
const secondUsers = (await it.next()).value
lq.close()
const user = ... User DAO ...
const lq: LiveQuery<boolean> = await user.liveExists({ filter: { live: true  } })
const it = lq.asyncIterator()
const first = (await it.next()).value
const second= (await it.next()).value
lq.close()
const user = ... User DAO ...
const lq: LiveQuery<number> = await user.liveCount({ filter: { live: true  } })
const it = lq.asyncIterator()
const first = (await it.next()).value
const second = (await it.next()).value
lq.close()
export abstract class LiveQuery<T> {
  public abstract close(): void // closes all opened iterators
  public abstract asyncIterator(): AsyncIterator<T> // creates new iterator hooked to the same live query
}
@edobrb edobrb added the ✨ feature request New feature or request label Apr 20, 2022
@edobrb edobrb added this to the September 2022 milestone Apr 20, 2022
@edobrb edobrb added the 📅 approved New feature approved and scheduled label Apr 20, 2022
@edobrb edobrb linked a pull request Apr 20, 2022 that will close this issue
6 tasks
@minox86 minox86 changed the title Live query ✨ Live queries ✨ Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📅 approved New feature approved and scheduled ✨ feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant