phorm_generator 1.2.0 copy "phorm_generator: ^1.2.0" to clipboard
phorm_generator: ^1.2.0 copied to clipboard

Code generator for PHORM that turns @Schema-annotated Dart models into SQL table schemas, migrations, JSON mappers and runtime metadata for SQLite, PostgreSQL and MySQL.

🏗️ PHORM Generator #

Pub Version Build Status Coverage GitHub Stars License: MIT Dart SDK

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, and FOREIGN KEY statements automatically.
  • Model Mixins: Generates _$UserMixin with automatic toJson, toString, copyWith, and relationship getters.
  • Pluralized Services: Generates the Users service class for fluent, static-method-based interaction.
  • JSON Helpers: Provides optimized _$UserFromJson implementations.
  • Runtime Metadata: Produces the Table configuration needed for PHORM.

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

3. Control what gets generated #

By default the generator emits a pluralized service class (e.g. Users) that exposes the full CRUD/query API (insert, readAll, where, watchAll, column constants, …). For large schemas, or when you only need the lightweight artefacts, set generateFullService: false on the @Schema annotation:

@Schema(tableName: 'users', generateFullService: false)
class User extends Model with _$PhormUserMixin {
  // ...
}

With generateFullService: false, only the schema, table metadata, fromJson/toJson, and copyWith are generated — the large service class is skipped. Defaults to true.


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

1
likes
150
points
427
downloads
screenshot

Documentation

API reference

Publisher

verified publisherinterlib.dev

Weekly Downloads

Code generator for PHORM that turns @Schema-annotated Dart models into SQL table schemas, migrations, JSON mappers and runtime metadata for SQLite, PostgreSQL and MySQL.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

analyzer, build, dart_style, path, phorm_annotations, source_gen

More

Packages that depend on phorm_generator