GithubHelp home page GithubHelp logo

yun_dao's Introduction

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

yun_dao's People

Contributors

lilizing avatar yeyunhz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.