Class: ReactiveQueryResult<T, PK, R, H, M>
Provides a reactive, observable response for a query that returns a single model instance or undefined.
This class is used for queries that return a single result (e.g., .first() or .find()), and will automatically re-fetch the result when relevant model events occur on the event bus.
Example
ts
// Use the query builder's .reactive() method to get a ReactiveQueryResult
const userQuery = db.model('users').where(...)
const reactive = await userQuery.reactive()
const response = await reactive.first() // returns a ReactiveQueryResult
response.on('next', (user) => { ... })
response.on('error', (err) => { ... })
response.on('complete', () => { ... })
// ...
response.unmount()Extends
ReactiveQueryResponse<M|undefined>
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T extends PlainObject | - | The type of the model's data. |
PK extends StringKeyOf<T> | - | The type of the primary key field. |
R extends Record<string, RelationshipConfiguration> | - | The relationships configuration for the model. |
H extends Required<ReactiveDatabaseOptions["hooks"]> | - | - |
M | ReactiveModel<T, PK, R> | The model instance type (defaults to ReactiveModel). |
Implements
ReactiveQueryResponseInterface<M|undefined>ReactiveQueryResultAgumentations
Properties
| Property | Type | Description | Inherited from |
|---|---|---|---|
e | EventListenerMap | The internal event listener map for the emitter. | ReactiveQueryResponseInterface.e ReactiveQueryResponse.e |
value | undefined | M | Returns the latest query result value. Throws if the initial query has not yet completed. Throws If the query has not yet run. | ReactiveQueryResponse.value |
Methods
off()
ts
off<K>(event: string | symbol | K, listener?:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never): this;Unsubscribe from an event.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener? | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | Optional. The listener function to remove. |
Returns
this
the current instance for chaining
Remarks
When no listener is provided, all listeners for the event will be removed, otherwise only the specified listener will be removed.
Implementation of
ts
ReactiveQueryResponseInterface.off;Inherited from
on()
ts
on<K>(
event: string | symbol | K,
listener:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never,
ctx?: any): this;Subscribe to an event with a typed listener.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | The listener function. |
ctx? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining
Implementation of
ts
ReactiveQueryResponseInterface.on;Inherited from
once()
ts
once<K>(
event: string | symbol | K,
listener:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never,
ctx?: any): this;Subscribe to an event once with a typed listener.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | The listener function. |
ctx? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining
Implementation of
ts
ReactiveQueryResponseInterface.once;Inherited from
unmount()
ts
unmount(): void;Returns
void