phorm_annotations 1.4.1 copy "phorm_annotations: ^1.4.1" to clipboard
phorm_annotations: ^1.4.1 copied to clipboard

Annotation library for declarative SQL table and schema definitions in Dart. Designed to be used with code generators that produce SQL schemas, migrations, or runtime metadata.

example/main.dart

// Examples print to the console for illustration only.
// ignore_for_file: avoid_print

import 'package:phorm_annotations/phorm_annotations.dart';

// In a real project you annotate your model classes and let `phorm_generator`
// produce the schema, JSON mappers and migrations. The annotations below show
// the declarative surface you work with.
//
// @Schema(
//   tableName: 'users',
//   paranoid: true, // adds soft-delete (deleted_at) support
//   indexes: [Index(columns: ['email'], unique: true)],
//   relationships: [HasMany(model: 'posts', foreignKey: 'user_id')],
// )
// class User {
//   @ID(autoIncrement: true)
//   final int id;
//
//   @Column(unique: true)
//   final String email;
//
//   @Column(nullable: true)
//   final String? name;
//
//   const User(this.id, this.email, this.name);
// }

void main() {
  // Table-level configuration.
  const schema = Schema(
    tableName: 'users',
    paranoid: true,
    indexes: [
      Index(columns: ['email'], unique: true),
    ],
    relationships: [
      HasMany(model: 'posts', foreignKey: 'user_id'),
    ],
  );

  print('table:        ${schema.tableName}');
  print('soft delete:  ${schema.paranoid}');
  print('naming:       ${schema.columnNaming}');
  print('dialect:      ${schema.dialect}');
  print('indexes:      ${schema.indexes.length}');
  print('relations:    ${schema.relationships.length}');

  // Column-level configuration.
  const id = ID(autoIncrement: true);
  const email = Column(unique: true, columnName: 'email_address');
  print('\nprimary key autoIncrement: ${id.autoIncrement}');
  print('email column name:         ${email.columnName}');
  print('email unique:              ${email.unique}');
}
1
likes
0
points
1.29k
downloads

Publisher

verified publisherinterlib.dev

Weekly Downloads

Annotation library for declarative SQL table and schema definitions in Dart. Designed to be used with code generators that produce SQL schemas, migrations, or runtime metadata.

Homepage
Repository (GitHub)
View/report issues

Topics

#orm #annotations #code-generation #database #sql

License

unknown (license)

Dependencies

meta

More

Packages that depend on phorm_annotations