Available on client only
useSubscribeOne(filter?: FullFilter, options?: SubscribeParams, hookOptions?: HookOptions): AsyncResult
Retrieves a matching record from the view/table and subscribes to changes
Parameters
-
filter optional FullFilter
Data filter
{ status: 'live' }{ $or: [{ id: 1 }, { status: 'live' }] }{ $existsJoined: { referencedTable: { id: 1 } } }{ $filter: [ { $age: ["created_at"] }, "<", '1 year' ] }
-
options optional SubscribeParams
-
limit optional number | null | undefined
Max number of rows to return. Defaults to 1000
- On client publish rules can affect this behaviour: cannot request more than the maxLimit (if present)
-
offset optional number
Number of rows to skip
-
groupBy optional boolean
Will group by all non aggregated fields specified in select (or all fields by default)
-
returnType optional “row” | “value” | “values” | “statement” | “statement-no-rls” | “statement-where” | undefined
Result data structure/type:
- row: the first row as an object
- value: the first value from of first field
- values: array of values from the selected field
- statement: sql statement
- statement-no-rls: sql statement without row level security
- statement-where: sql statement where condition
-
select optional Select
Fields/expressions/linked data to select
"*"or empty will return all fields{ field: 0 }- all fields except the specified field will be selected{ field: 1 }- only the specified field will be selected{ field: { $funcName: [args] } }- the field will be selected with the specified function applied{ field: 1, referencedTable: "*" }- field together with all fields from referencedTable will be selected{ linkedData: { referencedTable: { field: 1 } } }- linkedData will contain the linked/joined records from referencedTable
-
orderBy optional OrderBy
Order by options
- Order is maintained in arrays
[{ key: "field", asc: true, nulls: "last" }]
-
having optional FullFilter
Filter applied after any aggregations (group by)
-
skipFirst optional boolean
If true then the first value will not be emitted
-
actions optional Partial
Controls which actions will trigger the subscription. If not provided then all actions will be triggered
-
skipChangedColumnsCheck optional boolean
If true then the subscription will be triggered without first checking if selected column values have changed
-
throttle optional number
If provided then the subscription will be throttled to the provided number of milliseconds
-
throttleOpts optional { skipFirst?: boolean | undefined; }
-
skipFirst optional boolean
False by default. If true then the first value will be emitted at the end of the interval. Instant otherwise
-
-
-
hookOptions optional HookOptions
-
skip optional boolean
Used to prevent the hook from fetching data
-
deps optional any[] | undefined
Used to trigger re-fetching
-
Return type
AsyncResult
Async result type:
- data: the expected data
- isLoading: true when data is being fetched (initially or on subsequent filter/option changes)
- error: any error that occurred