sqfentity_gen 1.2.1+11

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

sqfentity_gen #

This package required for sqfentity ORM for Flutter code generator Includes Generators and Converters with build.yaml

Getting Started #

click for more information: https://github.com/hhtokpinar/sqfEntity

1.2.1+11 #

Applied range validator to forms (You can use minValue and maxValue property for integer, real and numeric field dbTypes)

1.2.1+9 #

Added One-to-One Relationships type for relationships.

as an example: to expand the product table with the properties table with one-to-one relationships

const tableProductProperties = SqfEntityTable(
tableName: 'property',
primaryKeyName: 'propertyId',
//useSoftDeleting: true,
//primaryKeyType: PrimaryKeyType.integer_auto_incremental,
fields: [
    SqfEntityField('weight', DbType.real),
    SqfEntityField('stockQty', DbType.numeric),
    SqfEntityFieldRelationship(
    //fieldName: 'productId',
        parentTable: tableProduct, relationType: RelationType.ONE_TO_ONE)
],
);

after generate the code, you will see ".property" in product item properties like below: Note: In one-to-many relations There will be ".getProperty().toList()"

final product = await Product().getById(8);

product.property
    ..stockQty = 8
    ..weight = 320;
await product.save();

print(product.toMapWithChilds());

and here is DEBUG RESULT

 flutter: { productId: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: false, categoryId: 1, rownum: 8, datetime: 2019-11-21 06:22:34.512, isDeleted: false, property: {stockQty: 4, weight: 320} } 

1.2.1+4 #

1- added equalsOrNull keyword for queries Example:

// this query lists only isActive=false 
final productList = await Product().select().isActive.not.equals(true).toList();

// but this query lists isActive=false and isActive is null both
final productList = await Product().select().isActive.not.equalsOrNull(true).toList();

   

2- you can define customCode property of your SqfEntityTable constant for ex:

const tablePerson = SqfEntityTable(
tableName: 'person',
primaryKeyName: 'id',
primaryKeyType: PrimaryKeyType.integer_auto_incremental,
fields: [
    SqfEntityField('firstName', DbType.text),
    SqfEntityField('lastName', DbType.text),
],
customCode: '''
    String fullName()
    { 
    return '\$firstName \$lastName';
    }
''');

1.2.0+13 #

modified isSaved property and to be removed when not needed

1.2.0+12 #

bugs fixed getById(id) -> id is null then return null instead exception and fixed .isNull() throws the exception

1.2.0+11 #

Converting the first character of fieldName to lowercase has been cancelled. Users should specify the field name as they wants

1.2.0+9 #

Added Form Generation Feature, and minValue, maxValue propery for datetime fields and fixed some bugs. Example:

@SqfEntityBuilderForm(tableCategory, formListTitleField: 'name', hasSubItems: true)
const tableCategory = SqfEntityTable(
    tableName: 'category',
    primaryKeyName: 'id',
    primaryKeyType: PrimaryKeyType.integer_auto_incremental,
    useSoftDeleting: true,
    // when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete)
    modelName:
        null, // SqfEntity will set it to TableName automatically when the modelName (class name) is null
    // declare fields
    fields: [
    SqfEntityField('name', DbType.text),
    SqfEntityField('isActive', DbType.bool, defaultValue: true),
    SqfEntityField('date1', DbType.datetime, defaultValue: 'DateTime.now()', minValue: '2019-01-01', maxValue: '2023-01-01'),
    SqfEntityField('date2', DbType.datetime,  minValue: '2020-01-01', maxValue: '2022-01-01')
    ]);

1.1.1+3 #

fixed the build error after defining multiple referance (RelationShip) to the same table

1.1.1+1 #

added saveResult property Note: You must re-generate your models after updating the package

Example:

final product = Product(
    name: 'Notebook 12"',
    description: '128 GB SSD i7',
    price: 6899,
    categoryId: 1);
await product.save();

print(product.saveResult.success); // bool (true/false)
print(product.saveResult.toString()); // String (message)

1.1.0+5 #

bugfix SequenceManager error on multi database

1.1.0+4 #

added unknown (text) dbType for unrecognized columns

1.1.0+3 #

added Date (Small Date) dbType

    SqfEntityField('birthDate', DbType.date),

1.1.0+2 #

added DateTime dbType

    SqfEntityField('birthDate', DbType.datetime),

1.1.0+1 #

modified sqlite dbType mapping

1.1.0 #

merged package with sqfentity_base

1.0.3+5 #

removed analyzer from dependencies

1.0.3+4 #

added FormBuilder

1.0.3+3 #

removed FormBuilder

1.0.3+2 #

added analyzer 0.38.2

1.0.3+1 #

sqfentity_base exported to sqfentity_base 1.0.1 package

1.0.2+4 #

Blob type mapped as Uint8List instead String

1.0.2 #

Added function to generate model from existing database

1.0.1 #

sqfentity_base moved into this package

1.0.0+7 #

some required changes applied

1.0.0+6 #

  • Initial publish This package required for sqfentity_gen ORM for Flutter code generator Includes SqfEntity base classes and Annotation Classes

example/main.dart

import 'package:flutter/material.dart';


// STEP 1: import sqfentity package.
import 'package:sqfentity_gen/sqfentity_gen.dart';
import 'package:sqfentity/sqfentity.dart';


// STEP 1: define your tables as shown in the example Classes below.
// Define the 'TableCategory' constant as SqfEntityTable.
const tableCategory = SqfEntityTable(
    tableName: 'category',
    primaryKeyName: 'id',
    primaryKeyType: PrimaryKeyType.integer_auto_incremental,
    useSoftDeleting: true,
    // when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete)
    modelName:
        null, // SqfEntity will set it to TableName automatically when the modelName (class name) is null
    // declare fields
    fields: [
      SqfEntityField('name', DbType.text),
      SqfEntityField('isActive', DbType.bool, defaultValue: true),
    ]);

// Define the 'TableProduct' constant as SqfEntityTable.
const tableProduct = SqfEntityTable(
    tableName: 'product',
    primaryKeyName: 'id',
    primaryKeyType: PrimaryKeyType.integer_auto_incremental,
    useSoftDeleting: true,
    fields: [
      SqfEntityField('name', DbType.text),
      SqfEntityField('description', DbType.text),
      SqfEntityField('price', DbType.real, defaultValue: 0),
      SqfEntityField('isActive', DbType.bool, defaultValue: true),
      SqfEntityFieldRelationship(
          parentTable: tableCategory,
          deleteRule: DeleteRule.CASCADE,
          defaultValue: '0'), // Relationship column for CategoryId of Product
      SqfEntityField('rownum', DbType.integer,
          sequencedBy:
              seqIdentity /*Example of linking a column to a sequence */),
      SqfEntityField('imageUrl', DbType.text)
    ]);

// Define the 'Todo' constant as SqfEntityTable.
const tableTodo = SqfEntityTable(
    tableName: 'todos',
    primaryKeyName: 'id',
    useSoftDeleting:
        false, // when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete)
    primaryKeyType: PrimaryKeyType.integer_unique,
    defaultJsonUrl:
        'https://jsonplaceholder.typicode.com/todos', // optional: to synchronize your table with json data from webUrl

    // declare fields
    fields: [
      SqfEntityField('userId', DbType.integer),
      SqfEntityField('title', DbType.text),
      SqfEntityField('completed', DbType.bool, defaultValue: false)
    ]);

// Define the 'identity' constant as SqfEntitySequence.
const seqIdentity = SqfEntitySequence(
  sequenceName: 'identity',
  maxValue:  10000, /* optional. default is max int (9.223.372.036.854.775.807) */
  //modelName: 'SQEidentity', 
                      /* optional. SqfEntity will set it to sequenceName automatically when the modelName is null*/
  //cycle : false,    /* optional. default is false; */
  //minValue = 0;     /* optional. default is 0 */
  //incrementBy = 1;  /* optional. default is 1 */
  // startWith = 0;   /* optional. default is 0 */
);

// STEP 2: Create your Database Model constant instanced from SqfEntityModel
// Note: SqfEntity provides support for the use of multiple databases. So you can create many Database Models and use them in the application.
@SqfEntityBuilder(myDbModel)
const myDbModel = SqfEntityModel(
    modelName: null,
    databaseName: 'sampleORM.db',
    // put defined tables into the tables list.
    databaseTables: [tableCategory, tableProduct, tableTodo],
    // put defined sequences into the sequences list.
    sequences: [seqIdentity],
    bundledDatabasePath:
        null // 'assets/sample.db' // This value is optional. When bundledDatabasePath is empty then EntityBase creats a new database when initializing the database
);

/* STEP 3: That's All.. 
--> Go Terminal Window and run command below
    flutter pub run build_runner build --delete-conflicting-outputs
  Note: After running the command Please check lib/model/model.g.dart 
  Enjoy.. Huseyin TOKPINAR
*/


void main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Run Entity Model samples
  // ATTENTION! when the software/app is started, you must check the database was it initialized.
  // If needed, initilizeDb method runs CREATE / ALTER TABLE query for you.
  final bool isInitialized = await MyDbModel().initializeDB();
  if (isInitialized == false) {
    // If the database is not initialized, something went wrong. Check DEBUG CONSOLE for alerts
    // TO DO
    return;
  }
}


class MyDbModel extends SqfEntityModelProvider{
}

Use this package as a library

1. Depend on it

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


dependencies:
  sqfentity_gen: ^1.2.1+11

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:sqfentity_gen/sqfentity_gen.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix lib/sqfentity_base.dart. (-1 points)

Analysis of lib/sqfentity_base.dart reported 2 hints:

line 571 col 7: DO use curly braces for all flow control structures.

line 632 col 26: Prefer to use whereType on iterable.

Fix lib/sqfentity_gen.dart. (-0.50 points)

Analysis of lib/sqfentity_gen.dart reported 1 hint:

line 609 col 28: Prefer to use whereType on iterable.

Format lib/builder.dart.

Run dartfmt to format lib/builder.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/sqfentity_form_gen.dart (Run dartfmt to format lib/sqfentity_form_gen.dart.)
  • lib/src/sqfentity_formgenerator.dart (Run dartfmt to format lib/src/sqfentity_formgenerator.dart.)
  • lib/src/sqfentity_generator.dart (Run dartfmt to format lib/src/sqfentity_generator.dart.)
  • lib/src/sqfentity_helper.dart (Run dartfmt to format lib/src/sqfentity_helper.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
build ^1.0.0 1.2.2
source_gen ^0.9.4+4 0.9.4+6
Transitive dependencies
_fe_analyzer_shared 1.0.1
analyzer 0.39.2+1
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
logging 0.11.3+2
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0