supabase_model_generator 0.1.1
supabase_model_generator: ^0.1.1 copied to clipboard
A powerful code generator that automatically creates Dart models and repositories from your Supabase database schema, streamlining your development workflow.
Supabase Model Generator #
A powerful code generator that automatically creates Dart models and repositories from your Supabase database schema. This package streamlines your development workflow by generating type-safe Dart code that integrates seamlessly with your Supabase backend.
Features #
- π Automatic model generation from Supabase schema
- π¦ Type-safe repository classes for each model
- π Built-in CRUD operations
- π Customizable code generation
- π― Full type safety and null safety support
- π Automatic relationship handling
Installation #
Add the following to your pubspec.yaml:
dependencies:
supabase_model_generator: ^0.1.0
dev_dependencies:
build_runner: ^2.3.3
Configuration #
- Create a
supabase_config.yamlfile in your project root (you can copy fromsupabase_config.yaml.template):
project_id: your-project-id
database_url: postgresql://postgres:postgres@localhost:54322/postgres
output_directory: lib/models
- Configure your database connection details.
Usage #
- Run the generator:
dart run build_runner build
- Use the generated models and repositories:
// Using a generated model
final user = User(
id: 1,
name: 'John Doe',
email: 'john@example.com',
);
// Using a generated repository
final userRepository = UserRepository();
await userRepository.create(user);
final users = await userRepository.findAll();
Generated Code Structure #
The generator creates two files for each table in your Supabase database:
{model_name}.model.dart: Contains the model class with all properties{model_name}.repository.dart: Contains the repository class with CRUD operations
Customization #
You can customize the generation process by:
- Adding annotations to control field generation
- Configuring relationships in your schema
- Extending generated classes with custom functionality
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.