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

  1. Create supafreeze.yaml in your project root:
url: ${SUPABASE_DATA_API_URL}
secret_key: ${SUPABASE_SECRET_KEY}
output: lib/models
  1. Create .env file with your credentials:
SUPABASE_DATA_API_URL=https://your-project.supabase.co
SUPABASE_SECRET_KEY=your-secret-key
  1. 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

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