Configure your database connection and code generation settings in your Prax schema.
The datasource block configures your database connection. It specifies the database provider, connection URL, and optional connection settings. Every schema must have at least one datasource.
For production deployments, you may need additional settings like shadow databases for migrations or direct connections for specific operations.
| Property | Required | Description |
|---|---|---|
provider |
Yes | Database provider: postgresql, mysql, or sqlite |
url |
Yes | Connection URL (use env("VAR") for environment variables) |
directUrl |
No | Direct connection URL bypassing connection pooler |
shadowDatabaseUrl |
No | Shadow database URL for safe migration testing |
connectionLimit |
No | Maximum number of connections in the pool |
poolTimeout |
No | Timeout in seconds for acquiring a connection from the pool |
relationMode |
No | How relations are handled: foreignKeys (default) or prisma |
You can define multiple datasources for connecting to different databases. Use the
@@datasource() attribute
to specify which datasource a model belongs to.
| Provider | URL Format |
|---|---|
postgresql |
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA |
mysql |
mysql://USER:PASSWORD@HOST:PORT/DATABASE |
sqlite |
file:./path/to/dev.db or sqlite::memory: |
Generators transform your schema into code. The primary generator creates the Prax client, but you can add additional generators for documentation, API schemas, and more.
| Property | Required | Description |
|---|---|---|
provider |
Yes | Generator provider name (e.g., prax-client-rust) |
output |
Yes | Output directory for generated files |
previewFeatures |
No | Array of preview features to enable |
binaryTargets |
No | Target platforms for binary engines |
plugins |
No | Array of plugins to enable |
engineType |
No | Engine type: library (default) or binary |
Plugins extend code generation with additional features. Enable them in your generator configuration.
Adds #[derive(Serialize, Deserialize)]
to all generated types for JSON serialization.
Generates async-graphql compatible types with
SimpleObject,
InputObject, and
Enum derives.
Adds validation attributes from your schema to generated types using the
validator crate.
Adds #[derive(Debug)]
to all generated types for debugging output.
Generates JSON Schema definitions for all models, useful for API documentation and frontend type generation.
You can use additional generators to create documentation, TypeScript clients, OpenAPI specifications, and more.
Use the env("VAR_NAME") function
to reference environment variables. This keeps sensitive data out of your schema file.
Security: Never commit your .env
file to version control. Add it to .gitignore.
Use .env.example to document required variables.
Here's a well-organized schema file showing the recommended structure: