sqlentity 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Sqlentity #

o Sqlentity é um ORM focado em facilitar o vida do desenvolvedor, onde é possivel criar uma classe e apartir desta classe realizar a criação do banco de dados interno (sqlite) no dispositivo mobile.

instalação #

dependencies:
  sqlentity: ^1.1.0

Exemplo em codigo #

import 'package:flutter/material.dart';
import 'package:sqlentity/base-entity/entity.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao-repository/dao-repository.dart';
import 'package:sqlentity/repository/dao-repository/i-dao-repository.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<UserEntity> users = new List();
  IDAORepository<UserEntity> _idao;

  @override
  void initState() {
    super.initState();
    initDatabase();
    _idao = new DAORepository(new UserEntity());
    initData();
  }
  
  void initDatabase() {
    DataBaseConfig dataBaseConfig = DataBaseConfig();
    dataBaseConfig.database_name = "Teste";
    dataBaseConfig.database_version = 1;
    dataBaseConfig.entitys = [new UserEntity()];
  }

  void initData() async {
    //criar a entidade
    UserEntity dart = new UserEntity(name: "DART",sobrename: "FLUTTER");
    UserEntity flutter = new UserEntity(name: "JS",sobrename: "ANGULAR");
    UserEntity android = new UserEntity(name: "JS",sobrename: "REACT");

    //realiza a inserção no banco e retorna o id
    int iddart = await _idao.insert(dart);
    var idFlutter = await _idao.insert(flutter);
    int idandroid = await _idao.insert(android);
    dart.id = iddart;
    dart.sobrename = "KOTLIN";

    //realiza a atualização da entidade no banco e retorna um status
    var isUpdate = await _idao.update(dart);
    android.id = idandroid;
    
    // realiza a exclusao no banco e retorna um status
    var isDelete = await _idao.delete(android);

    //lista de usuarios no banco
    var userlist = await _idao.select();

    //busca de usuarios especifico
    var getById = await _idao.getById(dart);

    //quantidade de usuarios
    var count = await _idao.count();
    
    if(userlist.length == count)
    //setando item local
    userlist.add(getById);
    
    setState(() {
      //setando lista
      users = userlist;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('DataBase'),
          ),
          body: new ListView.builder(
              padding: new EdgeInsets.all(4.0),
              shrinkWrap: true,
              itemCount: users.length,
              itemBuilder: (context, index) {
                return new Container(
                    margin: new EdgeInsets.all(8.0),
                    child: new Center(
                        child: new Text(
                      '${users[index].name}, ${users[index].sobrename}',
                      style: new TextStyle(
                          color: Colors.green,
                          fontWeight: FontWeight.bold,
                          fontSize: 18),
                    )));
              })),
    );
  }
}

class UserEntity extends Entity {
  int _id;
  String _name;
  String _sobrename;

  UserEntity({var id: 0, var name: "", var sobrename: ""}) : super('USER') {
    this.id = id;
    this.name = name;
    this.sobrename = sobrename;
  }

  @override
  void configColumn() {
    //O id deve ser sempre o primeiro caso queira usar as operaçoes padroes do DAO
    createColumn("ID", "INTEGER PRIMARY KEY AUTOINCREMENT", 1);

    //nova coluna
    createColumn("NAME", "TEXT", 1);
    createColumn("SOBRENAME", "TEXT", 1);
  }

  @override
  Entity map(Map<String, dynamic> map) {
    return new UserEntity(
      id: map['ID'],
      name: map['NAME'],
      sobrename: map['SOBRENAME'],
    );
  }

  int get id => _id;

  set id(int value) {
    _id = value;
    updateValeu("ID", value: id);
  }

  String get name => _name;

  set name(String value) {
    _name = value;
    updateValeu("NAME", value: _name);
  }
  
  String get sobrename => _sobrename;

  set sobrename(String value) {
    _sobrename = value;
    updateValeu("SOBRENAME", value: _sobrename);
  }
}```


## Getting Started

For help getting started with Flutter, view our online
[documentation](https://flutter.io/).

For help on editing plugin code, view the [documentation](https://flutter.io/developing-packages/#edit-plugin-package).


1.1.0 #

  • adaptacao pro androidX.

1.0.8 and 1.0.10 #

  • atualizacao da base do banco e correcao de crash inesperados.

1.0.6 and 1.0.7 #

  • controle de atividades, evitando crash inesperado caso o banco esteja aberto.

1.0.1 #

  • o Sqlentity é um ORM focado em facilitar o vida do desenvolvedor, onde é possivel criar um classe e apartir desta classe realizar a criação do banco de dados interno (sqlite) no dispositivo mobile. É recomentado realizar os configurações e preparação do banco, no construtor inicial da classe, evite usa-lo no initState.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sqlentity/base-entity/entity.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao-repository/dao-repository.dart';
import 'package:sqlentity/repository/dao-repository/i-dao-repository.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<UserEntity> users = new List();
  IDAORepository<UserEntity> _idao;

  @override
  void initState() {
    super.initState();
    initDatabase();
    _idao = new DAORepository(new UserEntity());
    initData();
  }
  
  void initDatabase() {
    DataBaseConfig dataBaseConfig = DataBaseConfig();
    dataBaseConfig.database_name = "Teste10";
    dataBaseConfig.database_version = 1;
    dataBaseConfig.entitys = [new UserEntity()];
  }

  void initData() async {
    //criar a entidade
    UserEntity dart = new UserEntity(name: "Flop",sobrename: "FLUTTER");
    UserEntity flutter = new UserEntity(name: "Tores",sobrename: "ANGULAR");
    UserEntity android = new UserEntity(name: "Gold",sobrename: "REACT");

    //realiza a inserção no banco e retorna o id
    int iddart = await _idao.insert(dart);
    var teste = _idao.select();
    var idFlutter =await _idao.insert(flutter);
    int idandroid = await _idao.insert(android);
    dart.id = iddart;
    dart.sobrename = "KOTLIN";

    //realiza a atualização da entidade no banco e retorna um status
    var teste02 = _idao.select();
    var isUpdate = await _idao.update(dart);
    android.id = idandroid;
    
    // realiza a exclusao no banco e retorna um status
    var teste03 = _idao.select();
    var isDelete = await _idao.delete(android);

    //lista de usuarios no banco
    var userlist = await _idao.select();

    //busca de usuarios especifico
    var getById = await _idao.getById(dart);

    //quantidade de usuarios
    var count = await _idao.count();
    
    if(userlist?.length == count)
    //setando item local
    userlist?.add(getById);
    
    setState(() {
      //setando lista
      users = userlist;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('DataBase'),
          ),
          body: new ListView.builder(
              padding: new EdgeInsets.all(4.0),
              shrinkWrap: true,
              itemCount: users.length,
              itemBuilder: (context, index) {
                return new Container(
                    margin: new EdgeInsets.all(8.0),
                    child: new Center(
                        child: new Text(
                      '${users[index].name}, ${users[index].sobrename}',
                      style: new TextStyle(
                          color: Colors.green,
                          fontWeight: FontWeight.bold,
                          fontSize: 18),
                    )));
              })),
    );
  }
}

class UserEntity extends Entity {
  int _id;
  String _name;
  String _sobrename;

  UserEntity({var id: 0, var name: "", var sobrename: ""}) : super('USER') {
    this.id = id;
    this.name = name;
    this.sobrename = sobrename;
  }

  @override
  void configColumn() {
    //O id deve ser sempre o primeiro caso queira usar as operaçoes padroes do DAO
    createColumn("ID", "INTEGER PRIMARY KEY AUTOINCREMENT", 1);

    //nova coluna
    createColumn("NAME", "TEXT UNIQUE", 1);
    createColumn("SOBRENAME", "TEXT", 1);
  }

  @override
  Entity map(Map<String, dynamic> map) {
    return new UserEntity(
      id: map['ID'],
      name: map['NAME'],
      sobrename: map['SOBRENAME'],
    );
  }

  int get id => _id;

  set id(int value) {
    _id = value;
    updateValeu("ID", value: id);
  }

  String get name => _name;

  set name(String value) {
    _name = value;
    updateValeu("NAME", value: _name);
  }
  
  String get sobrename => _sobrename;

  set sobrename(String value) {
    _sobrename = value;
    updateValeu("SOBRENAME", value: _sobrename);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  sqlentity: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:sqlentity/base-entity/column.dart';
import 'package:sqlentity/base-entity/entity.dart';
import 'package:sqlentity/dao/dao.dart';
import 'package:sqlentity/dao/i-dao.dart';
import 'package:sqlentity/database/abstract-database.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao-repository/dao-repository.dart';
import 'package:sqlentity/repository/dao-repository/i-dao-repository.dart';
import 'package:sqlentity/repository/repository.dart';
import 'package:sqlentity/repository/void-repository.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
58
Health:
Code health derived from static analysis. [more]
89
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/dao/dao.dart. (-7.24 points)

Analysis of lib/dao/dao.dart reported 15 hints, including:

line 48 col 23: 'await' applied to 'Batch', which is not a 'Future'.

line 49 col 11: 'await' applied to 'void', which is not a 'Future'.

line 59 col 16: 'await' applied to 'int', which is not a 'Future'.

line 64 col 14: 'await' applied to 'int', which is not a 'Future'.

line 80 col 14: 'await' applied to 'List

Fix lib/database/database-config.dart. (-2.48 points)

Analysis of lib/database/database-config.dart reported 5 hints:

line 5 col 10: Name non-constant identifiers using lowerCamelCase.

line 6 col 7: Name non-constant identifiers using lowerCamelCase.

line 7 col 25: Name non-constant identifiers using lowerCamelCase.

line 23 col 22: Avoid wrapping fields in getters and setters just to be "safe".

line 26 col 7: Avoid wrapping fields in getters and setters just to be "safe".

Fix lib/repository/dao-repository/dao-repository.dart. (-1 points)

Analysis of lib/repository/dao-repository/dao-repository.dart reported 2 hints:

line 51 col 23: 'await' applied to 'List

line 56 col 14: 'await' applied to 'List

Fix additional 7 files with analysis or formatting issues. (-1 points)

Additional issues in the following files:

  • lib/database/abstract-database.dart (1 hint)
  • lib/repository/repository.dart (1 hint)
  • lib/base-entity/column.dart (Run flutter format to format lib/base-entity/column.dart.)
  • lib/base-entity/entity.dart (Run flutter format to format lib/base-entity/entity.dart.)
  • lib/dao/i-dao.dart (Run flutter format to format lib/dao/i-dao.dart.)
  • lib/repository/dao-repository/i-dao-repository.dart (Run flutter format to format lib/repository/dao-repository/i-dao-repository.dart.)
  • lib/repository/void-repository.dart (Run flutter format to format lib/repository/void-repository.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
path ^1.6.4 1.6.4
sqflite ^1.3.0 1.3.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
sqflite_common 1.0.0+1
synchronized 2.2.0
typed_data 1.1.6
vector_math 2.0.8