query-structure crate provides fundamental types for working with Prisma data models, fields, filters, and query arguments. It serves as the foundation for query building and execution.
Overview
This library defines the internal representation of Prisma schemas and query operations. It bridges the gap between the PSL (Prisma Schema Language) parser and the query execution layer.Installation
Core Types
Model
Represents a Prisma model in the internal data model.Methods
fn() -> &str
Returns the model name as defined in the schema
fn() -> FieldSelection
Returns the fields used as the primary identifier for records
fn() -> &str
Returns the database table/collection name for this model
fn() -> bool
Returns true if this model is a database view
FieldSelection
A selection of fields from a model.Methods
fn() -> Iterator
Returns an iterator over all selected fields
fn() -> Iterator
Returns an iterator over scalar field selections only
fn(&Self) -> bool
Checks if this selection contains all fields from another selection
SelectedField
Represents a single selected field in a query.ScalarFieldRef
A scalar field like String, Int, DateTime
CompositeSelection
A composite type field with nested selections
RelationSelection
A relation field with nested query arguments and selections
VirtualSelection
A virtual field like relation count aggregations
QueryArguments
Defines constraints for querying data.Model
The model being queried
Option<SelectionResult>
Cursor position for pagination
Take
Number of records to take (can be negative for reverse pagination)
Option<i64>
Number of records to skip
Option<Filter>
Filter conditions (WHERE clause)
Vec<OrderBy>
Ordering specifications
Option<FieldSelection>
Fields to apply DISTINCT on
Option<RelationLoadStrategy>
Strategy for loading relations (Join or Query)
Filter
Represents query filter conditions.Filter Constructors
RelationLoadStrategy
Strategy for loading relation data.variant
Load relations using SQL JOIN operations (more efficient, single query)
variant
Load relations using separate queries (application-level joins)
Take
Represents the number of records to take in a query.Methods
Module Structure
The crate is organized into several modules:model- Model types and operationsfield- Field types (scalar, composite, relation)field_selection- Field selection typesfilter- Filter condition typesquery_arguments- Query argument typesorder_by- Ordering specificationsrecord- Record and selection result typeswrite_args- Write operation argumentsinternal_data_model- Internal representation of schemaerror- Error typesprelude- Commonly used types
Re-exports
The crate re-exports several useful types:Type Aliases
Dependencies
Key dependencies:psl- Prisma Schema Language parserprisma-value- Prisma value typesitertools- Iterator utilitiesbigdecimal- Decimal number supportchrono- Date and time types
Examples
Creating a Field Selection
Building Query Arguments
Working with Filters
Related
- query-compiler - Compiles queries using these structures
- psl-core - Schema parsing and validation