supafreeze library
Generate Freezed models from Supabase database schema.
This package provides tools to automatically generate type-safe Freezed models from your Supabase PostgreSQL database schema.
Quick Start
- Create
supafreeze.yamlin your project root:
url: ${SUPABASE_DATA_API_URL}
secret_key: ${SUPABASE_SECRET_KEY}
output: lib/models
- Create
.envfile with your credentials:
SUPABASE_DATA_API_URL=https://your-project.supabase.co
SUPABASE_SECRET_KEY=your-secret-key
- Run build_runner:
dart run build_runner build
Features
- Automatic schema fetching from Supabase
- Per-table incremental generation
- Smart caching with SHA256 hashes
- PostgreSQL to Dart type mapping
- Reserved word handling
- Configurable fetch modes (always, if_no_cache, never)
Main Classes
- ConfigLoader - Loads configuration from YAML and environment
- SchemaFetcher - Fetches schema from Supabase
- FreezedGenerator - Generates Freezed model code
- SchemaCache - Manages schema caching for incremental builds
- TypeMapper - Maps PostgreSQL types to Dart types
Classes
- BaseSupabaseConfig
- Base configuration for Supabase schema tools
- ColumnInfo
- Represents a column in a database table
- ConfigLoader
- Loads and resolves configuration from various sources
- EnumGenerator
- Generates Dart enum code from PostgreSQL enum types
- EnumInfo
- Represents a PostgreSQL enum type
- ForeignKeyInfo
- Represents a foreign key relationship
- FreezedGenerator
- Generates Freezed model code from table information
- RelationConfig
- Configuration for relations on a specific table
- RelationOverride
- Configuration for relation overrides on a specific relation
- SchemaCache
- Manages schema caching with per-table hash tracking.
- SchemaDiff
- Result of comparing current schema with cached schema.
- SchemaFetcher
- Fetches schema information from Supabase
- SupafreezeConfig
- Configuration for supafreeze
- TableInfo
- Represents a database table
- TypeMapper
- Maps PostgreSQL types to Dart types Reference: https://www.postgresql.org/docs/current/datatype.html
Enums
- FetchMode
- Fetch mode for schema retrieval
Exceptions / Errors
- ConfigException
- Exception thrown when configuration is invalid
- SchemaFetchException
- Exception thrown when schema fetching fails