Query Types
Query
Represents a query that can be executed against the database.The table name this query operates on
The schema defining the database structure
The return type of the query results
QueryOrQueryRequest
Union type that accepts either a Query or a QueryRequest.Row
Represents a row from a table with all relationships resolved.PullRow
Represents a row as returned from the database before transformation.Query Options
RunOptions
Controls how queries are executed.'complete': Waits for any pending data to sync before running the query'unknown': Runs immediately with whatever data is available locally
MaterializeOptions
Options for creating materialized views.Time to live for the materialized view. Controls how long query results are cached after the view is destroyed.Can be:
'never': Query is removed immediately (default)number: Seconds to keep the query cached{seconds: number}: Object form specifying seconds
PreloadOptions
Options for preloading query data.Time to live for the preloaded data. Same format as MaterializeOptions.ttl.
View Types
TypedView
A materialized view that stays synchronized with the database.The current query results
Destroys the view and stops synchronization. Must be called when done to avoid memory leaks.
Adds a listener that is called when the data changes. Returns an unsubscribe function.
Updates the time-to-live for this view
ViewFactory
Factory function for creating custom views.zero.materialize() to create custom view implementations:
Result Types
ResultType
Indicates the freshness of query results.Results are from local cache, may be stale
Results are fresh from the server
Query encountered an error
HumanReadable
Transforms query results into a human-readable format with resolved relationships.Query Builder Types
SchemaQuery
Query builders for each table in the schema.z.query is deprecated. Use createBuilder() instead:
ConditionalSchemaQuery
Query type that conditionally includes legacy query methods based on schema configuration.Query Execution Flow
-
Create Query: Build a query using the query builder
-
Execute Query: Choose execution method:
run(): Execute oncematerialize(): Create live viewpreload(): Cache for later
-
Handle Results: Process the returned data
Error Handling
QueryErrorDetails
Provides error information when a query fails.Indicates this is an error result
Function to retry the query after an error
Alias for retry
The type of error:
'app': Error in application query code'server': Server-side error'client': Client-side error
Human-readable error message
Additional error details if available