Core Dart

Using Supabase Codegen in pure Dart or server-side applications.

Core Dart

The supabase_codegen package is the base library for generating type-safe models in pure Dart projects. It's ideal for server-side Dart, CLI tools, or any non-Flutter/non-Serverpod environment.

Installation

Add the package to your pubspec.yaml:

dependencies:
  supabase_codegen: ^4.0.0

Setup

    SQL Functions

    Ensure your Supabase database has the necessary helper functions. Run:

    dart run supabase_codegen:add_codegen_functions
    

    Then apply the migration with the Supabase CLI.

    Environment File

    Create a .env file in your project root:

    SUPABASE_URL=https://your-project.supabase.co
    SUPABASE_ANON_KEY=your-anon-key
    

    Initialization

    Create your configuration file:

    dart run supabase_codegen:init
    

CLI Usage

Generate your models by running:

dart run supabase_codegen:generate_types

Options

FlagDescriptionDefault
-o, --outputSet the output directorysupabase/types
-e, --envPath to the environment file.env
-t, --tagAdd a custom tag to generated files''

Client Configuration

Before using the generated types, you must initialize the client.

import 'package:supabase_codegen/supabase_codegen.dart';

void main() async {
  await loadClientFromEnv();
}