Flutter ORM Mate - flutter_orm_m8

GitHub release pub package Build Status

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 three annotation types:

  • ColumnMetadata
  • DataTable
  • DataColumn

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

  • DbEntity
  • DbAccountEntity
  • DbAccountRelatedEntity

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", ColumnMetadata.PrimaryKey | ColumnMetadata.Unique | ColumnMetadata.AutoIncrement)

DataTable

DataTable describes the required name for the table

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

DataColumn

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

  @DataColumn("id", ColumnMetadata.PrimaryKey | ColumnMetadata.Unique | ColumnMetadata.AutoIncrement)
  int _id;

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")
class A01Test implements DbAccountRelatedEntity {
  @DataColumn("id", ColumnMetadata.PrimaryKey | ColumnMetadata.Unique | ColumnMetadata.AutoIncrement)
  int _id;

  @DataColumn("account_id")
  int _accountId;

  @DataColumn("record_date")
  int _recordDate;

  @DataColumn("is_deleted")
  int _isDeleted;

  A01Test.fromMap(Map<String, dynamic> map) {
    this._id = map['id'];
    this._accountId = map['account_id'];    
    this._recordDate = map['record_date'];
    this._isDeleted = map['is_deleted'];
  }

  @override
  A01Test getDbEntityFromMap(Map<String, dynamic> map) {
    return A01Test.fromMap(map);
  }  
}

Libraries

column_metadata
data_column
data_table
db_account_entity
db_entity
flutter_orm_m8
ORM Mate - light annotations for Dart
flutter_orm_m8.base