sqlentity 1.0.2

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

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.

É recomentado realizar os configurações e preparação do banco, no construtor inicial da classe, evite usa-lo no initState.

instalação #

dependencies:
  sqlentity: ^1.0.1

Exemplo em codigo #

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

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

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

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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/database/abstract-database.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao/dao-repository.dart';
import 'package:sqlentity/repository/dao/i-dao-repository.dart';
  
Version Uploaded Documentation Archive
1.0.2 Feb 21, 2019 Go to the documentation of sqlentity 1.0.2 Download sqlentity 1.0.2 archive
1.0.1 Jan 4, 2019 Go to the documentation of sqlentity 1.0.1 Download sqlentity 1.0.1 archive
1.0.0 Jan 4, 2019 Go to the documentation of sqlentity 1.0.0 Download sqlentity 1.0.0 archive
0.0.2 Jan 4, 2019 Go to the documentation of sqlentity 0.0.2 Download sqlentity 0.0.2 archive
0.0.1 Dec 5, 2018 Go to the documentation of sqlentity 0.0.1 Download sqlentity 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
88
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13+1
  • Flutter: 1.2.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

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

Analysis of lib/database/database-config.dart reported 14 hints, including:

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

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

line 26 col 14: Name non-constant identifiers using lowerCamelCase.

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

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

Fix lib/base-entity/column.dart. (-2.96 points)

Analysis of lib/base-entity/column.dart reported 6 hints, including:

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

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

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

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

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

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

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

line 47 col 21: Await only futures.

line 48 col 9: Await only futures.

line 66 col 24: Await only futures.

line 91 col 9: Await only futures.

line 113 col 9: Await only futures.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

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

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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.2
sqflite ^1.1.1 1.1.1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
synchronized 2.0.2+1
typed_data 1.1.6
vector_math 2.0.8