sqlentity 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

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.0.6

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.0.6 #

  • 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/README.md

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:sqlentity/base-entity/entity.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao/i-dao-repository.dart';
import 'package:sqlentity/repository/dao/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;

  _MyAppState(){
    initDatabase();
    _idao = new DAORepository(new UserEntity());
    initData();
  }

  void initDatabase() {
    DataBaseConfig dataBaseConfig = DataBaseConfig.getInstance();
    dataBaseConfig.database_name = "Teste";
    dataBaseConfig.database_version = 1;
    dataBaseConfig.entitys = [new UserEntity()];
  }

  void initData() async {
    //criar a entidade
    UserEntity jose = new UserEntity(name: "Jose");
    UserEntity marcos = new UserEntity(name: "Marcos");
    UserEntity rodrigo = new UserEntity(name: "Rodrigo");

    //realiza a inserção no banco e retorna o id
    int idjose = await _idao.insert(jose);
    await _idao.insert(marcos);
    int idrodrigo = await _idao.insert(rodrigo);
    jose.id = idjose;
    jose.name = "Roger";

    //realiza a atualização da entidade no banco e retorna um status
    await _idao.update(jose);
    rodrigo.id = idrodrigo;

    //realiza a exclusao no banco e retorna um status
    await _idao.delete(rodrigo);

    //lista de usuarios no banco
    var userlist = await _idao.select() as List<UserEntity>;
    setState(() {
      //setando lista
      users = userlist;
    });
  }


  @override
  void initState() {
    super.initState();
  }

  @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(
                    child: new Center(
                        child: new Text(
                  '${users[index].name}',
                )));
              })),
    );
  }
}

class UserEntity extends Entity {
  int _id;
  String _name;

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

  @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);
  }

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

  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);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  sqlentity: ^1.0.6

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]
60
Health:
Code health derived from static analysis. [more]
87
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

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

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

line 45 col 21: Await only futures.

line 46 col 9: Await only futures.

line 54 col 14: Await only futures.

line 64 col 12: Await only futures.

line 86 col 9: Await only futures.

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

Analysis of lib/repository/dao-repository/dao-repository.dart reported 6 hints, including:

line 32 col 14: Await only futures.

line 47 col 23: Await only futures.

line 49 col 14: Await only futures.

line 68 col 14: Await only futures.

line 84 col 14: Await only futures.

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 additional 7 files with analysis or formatting issues. (-1.50 points)

Additional issues in the following files:

  • lib/repository/repository.dart (2 hints)
  • lib/database/abstract-database.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.2 1.6.4
sqflite ^1.1.5 1.1.7+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
synchronized 2.1.0+1
typed_data 1.1.6
vector_math 2.0.8