psl-core crate provides the core functionality for parsing, validating, and working with Prisma schema files. It transforms PSL text into a validated internal representation.
Overview
This library is the foundation of all Prisma tooling that works with schema files. It parses.prisma files, validates them, and provides a rich API for working with models, fields, relations, and configuration.
Installation
Core Functions
validate
Parse and validate a Prisma schema file.SourceFile
required
The schema file source to parse
ConnectorRegistry
required
Registry of available database connectors
&dyn ExtensionTypes
required
Extension types for custom type validation
ValidatedSchema
Contains the validated schema, configuration, and diagnostics
validate_multi_file
Parse and validate multiple Prisma schema files.&[(String, SourceFile)]
required
List of (filename, source) pairs to parse
parse_configuration
Parse only the configuration blocks (datasource, generator) from a schema.&str
required
The schema string to parse
Configuration
Contains datasources and generators configuration
reformat
Reformat a Prisma schema file.&str
required
The schema string to reformat
usize
required
Number of spaces per indentation level
String
The reformatted schema string
Core Types
ValidatedSchema
The result of validating a Prisma schema.Configuration
Parsed datasources and generators
ParserDatabase
The parsed and validated schema database
&'static dyn Connector
The active database connector
Diagnostics
Errors and warnings from parsing/validation
Methods
Configuration
Configuration blocks from the schema.Vec<Generator>
List of generator blocks
Vec<Datasource>
List of datasource blocks
Vec<String>
Configuration warnings
Datasource
Represents a datasource block in the schema.String
The datasource name (e.g., “db”)
String
The provider string from the schema
&'static str
The resolved active provider name
&'static dyn Connector
The connector implementation for this datasource
Option<RelationMode>
Explicit relation mode (foreignKeys or prisma)
Vec<(String, Span)>
Database schemas/namespaces (for multi-schema support)
Methods
Generator
Represents a generator block in the schema.String
The generator name
StringFromEnvVar
The generator provider (can reference env var)
Option<StringFromEnvVar>
Output path for generated code
Option<BitFlags<PreviewFeature>>
Enabled preview features
PreviewFeature
Enum of available preview features.Parser Database
TheParserDatabase provides access to the parsed schema:
Connector Registry
Built-in connectors are available:Feature Flags
Database-specific features:Dependencies
Key dependencies:diagnostics- Error and warning reportingparser-database- Internal database representationschema-ast- Abstract syntax tree typesprisma-value- Prisma value typesserde- Serialization supportregex- Regular expression support
Re-exports
Commonly used types are re-exported:Examples
Parsing a Schema
Parsing Configuration Only
Multi-file Schema
Reformatting a Schema
Related
- query-structure - Uses PSL types for queries
- schema-core - Uses PSL for migrations
- PSL Overview - Language guide