yun_dao 0.0.4

  • Readme
  • Changelog
  • Installing
  • 57

中文版 #

Introduction #

It is an ORM database solution by annotation method which is based on source_gen

Usage #

1.Create entity file which names *_entity.dart,then will generate database operation file which names *.entity.dao.dart after compilation.

entity file:     student_entity.dart
generated databse file :   student_entity.dao.dart

2.Use @Entity to annotate entity class; use nameInDb property to define the database table name of entity class; use propertyList to define the columns name in table which must be correspond to the property name of the entity class.And the type of propertyList is List

@Entity(nameInDb:'student',propertyList:[Property(name:'name',type:PropertyType.STRING)])
class StudentEntity{
   String name;
}

3.Entity class must has primary key, and define the property as primary key by the code isPrimary=true in @Property annotation

@Entity(nameInDb:'student',
        propertyList:[
              Property(name:'name',type:PropertyType.STRING),
              Property(name:'id',type:PropertyType.INT,isPrimary:true),
              ])
class StudentEntity{
      String name;
      int id;
}

4.Using the command to create database operation file in the command-line:

flutter packages pub run build_runner build

5.The gennereated databse operation file includes the CURD methods after compilation.And you should init database when use in project

///import database manager class
import 'package:yun_dao/db_manager.dart';

///pass the params include vesion,path,name to init databse. DBManager is a singleton
DBManager dBManager = DBManager();
dBManager.initByPath(1,“dbPath”,"dbName");

///you can also use default path to init database.The method to get default path is `getDatabasesPath()`
dBManager.init(1,"dbName");

6.Call the method init() of genearated database operation file to create a table in project.However,the method would judge whether create a new table.Then you can don't be afraid of creating repeated tables.

StudentEntityDao.init();

7.Next,it's convenient to execute CURD operation in databse.And the all operation methods is static.

StudentEntityTable.queryAll();
StudentEntityTable.insert(StudentEntity());

8.Also you can select data by query builder

List list = await StudentEntityDao.queryBuild()
        .where(StudentEntityDao.NAME.equal("李四"))
        .where(StudentEntityDao.AGE.equal(2))
        .list();

Install #

  dev_dependencies:
      yun_dao: 0.0.3
      

Example #

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

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


dependencies:
  yun_dao: ^0.0.4

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:yun_dao/yun_dao.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
57
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.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Health suggestions

Fix lib/entity_generator.dart. (-1.49 points)

Analysis of lib/entity_generator.dart reported 3 hints:

line 5 col 8: Don't import implementation files from another package.

line 47 col 12: Don't explicitly initialize variables to null.

line 105 col 14: Avoid using braces in interpolation when not needed.

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

Analysis of lib/db_manager.dart reported 1 hint:

line 23 col 25: Use ; instead of {} for empty constructor bodies.

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

Analysis of lib/query.dart reported 1 hint:

line 1 col 8: Unused import: 'package:yun_dao/dao.dart'.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (build_config, path_provider, source_gen).

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.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and yun_dao.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
build >=0.12.0 <2.0.0 0.12.8 1.2.2
build_config ^0.3.0 0.3.2 0.4.1+1
flutter 0.0.0
mustache4dart ^3.0.0-dev.0.0 3.0.0-dev.1.0
path_provider ^0.5.0 0.5.0+1 1.5.1
source_gen ^0.8.0 0.8.3+1 0.9.4+6
sqflite ^1.1.0 1.1.8
Transitive dependencies
analyzer 0.32.6 0.39.2+1
args 1.5.2
async 2.4.0
build_resolvers 0.2.2+7 1.3.0
build_runner_core 1.0.0 4.2.0
built_collection 4.2.2 4.3.0
built_value 7.0.0
charcode 1.1.2
code_builder 3.2.1
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.1.3 1.3.3
fixnum 0.10.11
front_end 0.1.4+2 0.1.29
glob 1.2.0
graphs 0.1.3+1 0.2.0
html 0.14.0+3
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 1.2.0 3.0.0
kernel 0.3.4+2 0.3.29
logging 0.11.3+2
matcher 0.12.6
meta 1.1.7 1.1.8
mime 0.9.6+3
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
package_resolver 1.0.10
path 1.6.4
pedantic 1.9.0
plugin 0.2.0+3
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.4 0.1.5
quiver 2.1.2+1
reflectable 2.0.7 2.2.0
shelf 0.7.5
shelf_web_socket 0.2.3
sky_engine 0.0.99
source_span 1.4.1 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.19 1.1.0
string_scanner 1.0.5
synchronized 2.1.1
timing 0.1.1+2
typed_data 1.1.6
vector_math 2.0.8
watcher 0.9.7+13
web_socket_channel 1.1.0
yaml 2.2.0
Dev dependencies
build_runner ^0.9.1 0.10.3 1.7.2
flutter_test
test any