Skip to main content
The 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

name
fn() -> &str
Returns the model name as defined in the schema
primary_identifier
fn() -> FieldSelection
Returns the fields used as the primary identifier for records
db_name
fn() -> &str
Returns the database table/collection name for this model
is_view
fn() -> bool
Returns true if this model is a database view

FieldSelection

A selection of fields from a model.

Methods

selections
fn() -> Iterator
Returns an iterator over all selected fields
scalars
fn() -> Iterator
Returns an iterator over scalar field selections only
is_superset_of
fn(&Self) -> bool
Checks if this selection contains all fields from another selection

SelectedField

Represents a single selected field in a query.
Scalar
ScalarFieldRef
A scalar field like String, Int, DateTime
Composite
CompositeSelection
A composite type field with nested selections
Relation
RelationSelection
A relation field with nested query arguments and selections
Virtual
VirtualSelection
A virtual field like relation count aggregations

QueryArguments

Defines constraints for querying data.
model
Model
The model being queried
cursor
Option<SelectionResult>
Cursor position for pagination
take
Take
Number of records to take (can be negative for reverse pagination)
skip
Option<i64>
Number of records to skip
filter
Option<Filter>
Filter conditions (WHERE clause)
order_by
Vec<OrderBy>
Ordering specifications
distinct
Option<FieldSelection>
Fields to apply DISTINCT on
relation_load_strategy
Option<RelationLoadStrategy>
Strategy for loading relations (Join or Query)

Filter

Represents query filter conditions.

Filter Constructors

RelationLoadStrategy

Strategy for loading relation data.
Join
variant
Load relations using SQL JOIN operations (more efficient, single query)
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 operations
  • field - Field types (scalar, composite, relation)
  • field_selection - Field selection types
  • filter - Filter condition types
  • query_arguments - Query argument types
  • order_by - Ordering specifications
  • record - Record and selection result types
  • write_args - Write operation arguments
  • internal_data_model - Internal representation of schema
  • error - Error types
  • prelude - Commonly used types

Re-exports

The crate re-exports several useful types:

Type Aliases

Dependencies

Key dependencies:
  • psl - Prisma Schema Language parser
  • prisma-value - Prisma value types
  • itertools - Iterator utilities
  • bigdecimal - Decimal number support
  • chrono - Date and time types

Examples

Creating a Field Selection

Building Query Arguments

Working with Filters