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

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 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