flutter_orm_m8 0.7.0 copy "flutter_orm_m8: ^0.7.0" to clipboard
flutter_orm_m8: ^0.7.0 copied to clipboard

outdated

Flutter package for ORM annotations. It defines ColumnMetadata, TableMetadata, DataTable, DataColumn annotations. Targeted audience is code generators

Flutter ORM Mate - flutter_orm_m8 #

Gitter GitHub release pub package Build Status license

Flutter package for ORM annotations.

Introduction #

The package adds definitions for a set of types that could be combined to expand ORM capabilities in the annotated code. The current version, defines four annotation types:

  • DataTable
  • DataColumn
  • TableMetadata
  • ColumnMetadata
  • CompositeConstraint

In order to ease the code emitting, four abstract classes are defined:

  • DbOpenEntity
  • DbEntity
  • DbAccountEntity implements DbEntity
  • DbAccountRelatedEntity implements DbEntity

Annotations #

DataTable #

DataTable describes the required name for the table in conjuction with a bit mask for optional TableMetadata

@DataTable("a01_tests")
class A01Test implements DbAccountRelatedEntity {

DataColumn #

Description

The DataColumn constructor has three parameters:

  • name
    • type: String
    • positional
    • mandatory
  • metadataLevel
  • compositeConstraints
 const DataColumn(this.name, {this.metadataLevel, this.compositeConstraints});

A simple approach

DataColumn describes the required name for the column in conjunction with a bit mask for required ColumnMetadata's

  @DataColumn(
    "id", 
    metadataLevel: ColumnMetadata.primaryKey | ColumnMetadata.unique | ColumnMetadata.autoIncrement)
  int id;

A fine tuned approach

DataColumn describes the required name for the column in conjunction with a list of composite constraints. For example, if we need a composite, unique constraint defined on the combination of two fields, we define the composite with the same name:

  @DataColumn("account_id", compositeConstraints: [
    CompositeConstraint(
        name: "uq_account_entry",
        constraintType: CompositeConstraintType.unique)
  ])
  int accountId;

  @DataColumn("description", compositeConstraints: [
    CompositeConstraint(
        name: "uq_account_entry",
        constraintType: CompositeConstraintType.unique)
  ])
  String description;

TableMetadata #

The TableMetadata describes the basic options for the table:

  • softDeletable
  • trackCreate
  • trackUpdate

The options may be combined in various ways using | operator

@DataTable(
    "health_issues",
    metadataLevel: TableMetadata.softDeletable | TableMetadata.trackCreate | TableMetadata.trackUpdate)

ColumnMetadata #

The ColumnMetadata describes the basic options for a column definition:

  • ignore
  • primaryKey
  • unique
  • notNull
  • autoIncrement
  • indexed

The options may be combined in various ways using | operator

@DataColumn(
  "id", 
  metadataLevel: ColumnMetadata.primaryKey | ColumnMetadata.unique | ColumnMetadata.autoIncrement)

CompositeConstraint #

The CompositeConstraint is instantiated with named, required parameters:

  • name - the name of the constraint
  • constraintType - the type of the constraint as enum with the following values:
    • unique,
    • primaryKey,
    • foreignKey,
    • indexed

Interfaces #

DbOpenEntity #

DbOpenEntity is as it's name suggest a template for non restrictive models with composite primary keys. Also it may be used for non integer primary key implementation.
It defines a single method getPrimaryKey

DbEntity #

May be used for a general purpose model template with integer primary key named id

DbAccountEntity #

It implements DbEntity. May be used for a model template in a generic user account with the following fields:

  • userName
  • email
  • abbreviation
  • isCurrent

DbAccountRelatedEntity implements DbEntity #

It implements DbEntity. May be used for a model template in a generic, account dependent, entity with the following fields:

  • accountId

Usage #

The package can be a start for other projects that aim to develop an ORM. Such project is https://github.com/matei-tm/flutter-sqlite-m8-generator

@DataTable("a01_tests", TableMetadata.softDeletable)
class A01Test implements DbAccountRelatedEntity {
  @DataColumn(
    "id", 
    metadataLevel: ColumnMetadata.primaryKey | ColumnMetadata.unique | ColumnMetadata.autoIncrement)
  int id;

  @DataColumn("account_id", compositeConstraints: [
    CompositeConstraint(
        name: "uq_account_entry",
        constraintType: CompositeConstraintType.unique)
  ])
  int accountId;

  @DataColumn("description", compositeConstraints: [
    CompositeConstraint(
        name: "uq_account_entry",
        constraintType: CompositeConstraintType.unique)
  ])
  String description;

  @DataColumn("record_date")
  int recordDate;
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Flutter package for ORM annotations. It defines ColumnMetadata, TableMetadata, DataTable, DataColumn annotations. Targeted audience is code generators

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on flutter_orm_m8