flutter_sqlite_m8_generator 0.5.0+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 45

(Deprecated) Sqlite ORM Mate Generator (flutter-sqlite-m8-generator) #

See f_orm_m8_sqlite for new updated framework

Changelog #

[Unreleased]

[0.5.0+1] - 2019-05-03

Changed #

[0.5.0] - 2019-05-03

Changed #

  • Switched from flutter_orm_m8 to the de facto successor f_orm_m8
  • Aligned generators with f_orm_m8 v0.8.0
  • Softdeletable meta determines the generation of a DateTime dateDelete field
  • The tests were refactored with caliber files

Added #

  • A custom header with timestamp on the generated files
  • Test coverage reporting to the CI pipeline
  • The example project integration tests were wired the CI pipeline

[0.4.0] - 2019-05-01

Changed #

  • Aligned generators with flutter-orm-m8 v0.7.1
  • Example project: HealthEntry model received a composite unique constraint

Added #

  • Generator support for CompositeConstraint.unique
  • Generator support for CompositeConstraint.primaryKey
  • Tests for CompositeConstraint generation
  • Flutter Driver tests on example project for all UI use cases

[0.3.0+1] - 2019-04-25

Fixed #

  • Documentation

[0.3.0] - 2019-04-23

Changed #

  • Aligned generators with flutter-orm-m8 v0.6.0
  • Default constructor on proxy entities has named parameters
  • All db helpers get*all methods return a list of proxy entities
  • The generator handles DbAccountEntity isCurrent field
  • The pluralize for model switched from "${modelName}s" to "${modelName}Proxies"
  • Example project was extended with implementations for:
    • DbEntity
    • DbAccountEntity
    • DbAccountRelatedEntity

Fixed #

  • Wrong attribute emission on accountId, for account related entities

[0.2.3+1] - 2019-04-15

Fixed #

  • Fix typo in save and update methods for trackable entities

Changed #

  • The showcase in the example project. All models are closer to a real life application

[0.2.3] - 2019-04-14

Fixed #

  • The generated entity database helper does not contain the meta columns
  • Fixed test in the example project

Changed #

  • The showcase in the example project

[0.2.2] - 2019-04-12

Added #

  • Bidirectional mapping for Model DateTime to Database Integer
  • Complete implementation for trackable, update and create, fields
  • Boolean extremeDevelopmentMode field to DatabaseHelper to control regeneration of database in dev mode

[0.2.1] - 2019-04-09

Changed #

  • Emitting only public fields

Fixed #

  • Missing metadataLevel on DataColumn annotated model fields, generates wrong emition

[0.2.0] - 2019-04-07

Added #

  • A full implementation in the example project for a dbEntity CRUD

Fixed #

  • Returning all rows on softDeletable entities

[0.1.1] - 2019-04-06

Changed #

  • FileStamp for database file

Fixed #

  • Fixing format and analyzer issues recommended after publish
  • Fixing readme formatting issues

[0.1.0] - 2019-04-05

Added #

  • Chaining database adapter builder with annotation helpers builder
  • Tests
  • A proxy default constructor with mandatory parameters
  • A database adapter

Changed #

  • Generated files extension

[0.0.7] - 2019-04-03

Added #

  • Working generator, ready to be published
  • Soft delete annotation implemented
  • Track create annotation implemented
  • Track update annotation implemented

[0.0.6] - 2019-04-02

Added #

  • Proxy writer

[0.0.5] - 2019-04-01

Added #

  • A simple fields enumeration with model type
  • A basic type mapper for Sqlite types
  • Expanding metadata in column definition
  • Extracting the primary key name

[0.0.4] - 2019-03-22

Added #

  • An entity factory for account related, account and independent entities

Changed #

  • The build output is routed to cache

[0.0.3] - 2019-03-14

Added #

  • A weak try to expand some information
  • Tests

[0.0.2] - 2019-03-14

Fixed #

  • Fixing analyzer issues

[0.0.1] - 2019-03-03

Added #

  • Basic generator

example/README.md

Example - Gymspector application #

A full, flutter working example is maintained on https://github.com/matei-tm/flutter-sqlite-m8-generator/tree/master/example.
The example presents different approaches to solve CRUD functionality for models that adhere to f_orm_m8 annotation framework.

HealthEntry - A DbAccountRelatedEntity implementation #

To demonstrate how to use a model that is dependent to UserAccount, we use a HealthEntry model that implements DbAccountRelatedEntity. The model detain a composite unique constraint based on accountId and description.

usecase002

The model #

The model file models/health_entry.dart has the following content:

import 'package:f_orm_m8/f_orm_m8.dart';

@DataTable(
    "health_entry", TableMetadata.trackCreate | TableMetadata.trackUpdate)
class HealthEntry implements DbAccountRelatedEntity {
  @DataColumn("id",
      metadataLevel: ColumnMetadata.primaryKey |
          ColumnMetadata.unique |
          ColumnMetadata.autoIncrement)
  int id;

  @DataColumn("diagnosys_date")
  DateTime diagnosysDate;

  @override
  @DataColumn("account_id",
      metadataLevel: ColumnMetadata.notNull,
      compositeConstraints: [
        CompositeConstraint(
            name: "uq_account_entry",
            constraintType: CompositeConstraintType.unique),
        CompositeConstraint(
            name: "ix_account_entry",
            constraintType: CompositeConstraintType.indexed)
      ])
  int accountId;

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

  @DataColumn("my_future_column7",
      metadataLevel: ColumnMetadata.ignore | ColumnMetadata.unique)
  int futureData;
}

The generated code #

From the model, the builder creates models/health_entry.g.m8.dart file with content

// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// Generator: OrmM8GeneratorForAnnotation
// **************************************************************************

import 'package:sqflite/sqflite.dart';
import 'dart:async';
import 'package:sqlite_m8_demo/models/health_entry.dart';

class HealthEntryProxy extends HealthEntry {
  DateTime dateCreate;
  DateTime dateUpdate;

  HealthEntryProxy({accountId, description}) {
    this.accountId = accountId;
    this.description = description;
  }

  Map<String, dynamic> toMap() {
    var map = Map<String, dynamic>();
    map['id'] = id;
    map['diagnosys_date'] = diagnosysDate.millisecondsSinceEpoch;
    map['account_id'] = accountId;
    map['description'] = description;
    map['date_create'] = dateCreate.millisecondsSinceEpoch;
    map['date_update'] = dateUpdate.millisecondsSinceEpoch;

    return map;
  }

  HealthEntryProxy.fromMap(Map<String, dynamic> map) {
    this.id = map['id'];
    this.diagnosysDate =
        DateTime.fromMillisecondsSinceEpoch(map['diagnosys_date']);
    this.accountId = map['account_id'];
    this.description = map['description'];
    this.dateCreate = DateTime.fromMillisecondsSinceEpoch(map['date_create']);
    this.dateUpdate = DateTime.fromMillisecondsSinceEpoch(map['date_update']);
  }
}

mixin HealthEntryDatabaseHelper {
  Future<Database> db;
  final theHealthEntryColumns = [
    "id",
    "diagnosys_date",
    "account_id",
    "description",
    "date_create",
    "date_update"
  ];

  final String _theHealthEntryTableHandler = 'health_entry';
  Future createHealthEntryTable(Database db) async {
    await db.execute('''CREATE TABLE $_theHealthEntryTableHandler (
    id INTEGER  PRIMARY KEY AUTOINCREMENT UNIQUE,
    diagnosys_date INTEGER ,
    account_id INTEGER  NOT NULL,
    description TEXT  NOT NULL,
    date_create INTEGER,
    date_update INTEGER    ,
    UNIQUE(account_id, description)
)''');
  }

  Future<int> saveHealthEntry(HealthEntryProxy instanceHealthEntry) async {
    var dbClient = await db;

    instanceHealthEntry.dateCreate = DateTime.now();
    instanceHealthEntry.dateUpdate = DateTime.now();

    var result = await dbClient.insert(
        _theHealthEntryTableHandler, instanceHealthEntry.toMap());
    return result;
  }

  Future<List<HealthEntry>> getHealthEntryProxiesAll() async {
    var dbClient = await db;
    var result = await dbClient.query(_theHealthEntryTableHandler,
        columns: theHealthEntryColumns, where: '1');

    return result.map((e) => HealthEntryProxy.fromMap(e)).toList();
  }

  Future<int> getHealthEntryProxiesCount() async {
    var dbClient = await db;
    return Sqflite.firstIntValue(await dbClient.rawQuery(
        'SELECT COUNT(*) FROM $_theHealthEntryTableHandler  WHERE 1'));
  }

  Future<HealthEntry> getHealthEntry(int id) async {
    var dbClient = await db;
    List<Map> result = await dbClient.query(_theHealthEntryTableHandler,
        columns: theHealthEntryColumns, where: '1 AND id = ?', whereArgs: [id]);

    if (result.length > 0) {
      return HealthEntryProxy.fromMap(result.first);
    }

    return null;
  }

  Future<int> deleteHealthEntry(int id) async {
    var dbClient = await db;
    return await dbClient
        .delete(_theHealthEntryTableHandler, where: 'id = ?', whereArgs: [id]);
  }

  Future<bool> deleteHealthEntryProxiesAll() async {
    var dbClient = await db;
    await dbClient.delete(_theHealthEntryTableHandler);
    return true;
  }

  Future<int> updateHealthEntry(HealthEntryProxy instanceHealthEntry) async {
    var dbClient = await db;

    instanceHealthEntry.dateUpdate = DateTime.now();

    return await dbClient.update(
        _theHealthEntryTableHandler, instanceHealthEntry.toMap(),
        where: "id = ?", whereArgs: [instanceHealthEntry.id]);
  }

  Future<List<HealthEntry>> getHealthEntryProxiesByAccountId(
      int accountId) async {
    var dbClient = await db;
    var result = await dbClient.query(_theHealthEntryTableHandler,
        columns: theHealthEntryColumns,
        where: 'account_id = ? AND 1',
        whereArgs: [accountId]);

    return result.map((e) => HealthEntryProxy.fromMap(e)).toList();
  }
}

GymLocation - A DbEntity implementation #

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_sqlite_m8_generator: ^0.5.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_sqlite_m8_generator/builder.dart';
import 'package:flutter_sqlite_m8_generator/exceptions/exception_expander.dart';
import 'package:flutter_sqlite_m8_generator/exceptions/field_parse_exception.dart';
import 'package:flutter_sqlite_m8_generator/generator/core.dart';
import 'package:flutter_sqlite_m8_generator/generator/database_helper_generator.dart';
import 'package:flutter_sqlite_m8_generator/generator/emitted_entity.dart';
import 'package:flutter_sqlite_m8_generator/generator/entity_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/model_parser.dart';
import 'package:flutter_sqlite_m8_generator/generator/orm_m8_generator_for_annotation.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/attribute_metadata_parser.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/db_entity_type_enum.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/entity_attribute.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/format_utils.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/type/checkers.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/type/column_assertions.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/type/table_assertions.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/type_mapper.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/type_utils.dart';
import 'package:flutter_sqlite_m8_generator/generator/utils/utils.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/account_entity_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/account_related_entity_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/attribute_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/database_helper_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/entity_writer_factory.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/independent_entity_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/proxy_writer.dart';
import 'package:flutter_sqlite_m8_generator/generator/writers/sql_definition_writer.dart';
import 'package:flutter_sqlite_m8_generator/m8_builder.dart';
import 'package:flutter_sqlite_m8_generator/orm_m8_generator.dart';
  
Version Uploaded Documentation Archive
0.5.0+1 May 3, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.5.0+1 Download flutter_sqlite_m8_generator 0.5.0+1 archive
0.5.0 May 3, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.5.0 Download flutter_sqlite_m8_generator 0.5.0 archive
0.4.0 May 1, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.4.0 Download flutter_sqlite_m8_generator 0.4.0 archive
0.3.0+1 Apr 24, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.3.0+1 Download flutter_sqlite_m8_generator 0.3.0+1 archive
0.3.0 Apr 23, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.3.0 Download flutter_sqlite_m8_generator 0.3.0 archive
0.2.3+1 Apr 14, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.2.3+1 Download flutter_sqlite_m8_generator 0.2.3+1 archive
0.2.3 Apr 14, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.2.3 Download flutter_sqlite_m8_generator 0.2.3 archive
0.2.2 Apr 12, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.2.2 Download flutter_sqlite_m8_generator 0.2.2 archive
0.2.1 Apr 8, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.2.1 Download flutter_sqlite_m8_generator 0.2.1 archive
0.2.0 Apr 7, 2019 Go to the documentation of flutter_sqlite_m8_generator 0.2.0 Download flutter_sqlite_m8_generator 0.2.0 archive

All 12 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
75
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

We analyzed this package on Jun 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: other

Platform components identified in package: build, io, mirrors.

Health issues and suggestions

Document public APIs. (-0.04 points)

205 out of 212 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/exceptions/exception_expander.dart. (-0.50 points)

Analysis of lib/exceptions/exception_expander.dart reported 1 hint:

line 8 col 37: Don't type annotate initializing formals.

Maintenance issues and suggestions

Support latest dependencies. (-25 points)

The version constraint in pubspec.yaml does not support the latest published versions for 4 dependencies (1 direct: analyzer).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.35.0 0.35.4 0.36.3
build >=0.12.0 <2.0.0 1.1.4
f_orm_m8 ^0.8.0 0.8.0+3
path ^1.6.2 1.6.2
source_gen ^0.9.0 0.9.4+2
Transitive dependencies
args 1.5.2
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
dart_style 1.2.4 1.2.8
front_end 0.1.14 0.1.18
glob 1.1.7
kernel 0.3.14 0.3.18
logging 0.11.3+2
meta 1.1.7
package_config 1.0.5
pedantic 1.7.0
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+10
yaml 2.1.16
Dev dependencies
build_runner ^1.0.0
build_test ^0.10.0
build_verify ^1.1.0
source_gen_test ^0.1.0
test ^1.3.3