🏗️ PHORM Generator
The magic behind PHORM. This package uses build_runner to turn your Dart models into optimized SQL schemas and type-safe CRUD mixins.
What it does
- SQL Generation: Creates
CREATE TABLE,INDEX, andFOREIGN KEYstatements automatically. - Model Mixins: Generates
_$UserMixinwith automatictoJson,toString,copyWith, and relationship getters. - Pluralized Services: Generates the
Usersservice class for fluent, static-method-based interaction. - JSON Helpers: Provides optimized
_$UserFromJsonimplementations. - Runtime Metadata: Produces the
Tableconfiguration needed forPHORM.
Installation
Add these to your dev_dependencies:
dev_dependencies:
phorm_generator: ^latest
build_runner: ^latest
Usage
1. Annotate your class
@Schema(tableName: 'users')
class User extends Model with _$PhormUserMixin {
@ID()
final String id;
@Column()
final String name;
User({required this.id, required this.name});
factory User.fromJson(Map<String, dynamic> json) => _$PhormUserFromJson(json);
}
2. Run the build
# One-time build
dart run build_runner build
# Watch for changes
dart run build_runner watch --delete-conflicting-outputs
Learn More
- For annotation details, see phorm_annotations.
- For runtime query engine details, see phorm.
- For the connection manager and SQLite driver implementation, see phorm_sqlite.
License
MIT License