开源软件名称:greenDAO
开源软件地址:https://gitee.com/HarmonyOS-tpc/greenDAO
开源软件介绍:
GreenDaoGreenDAO is a light & fast ORM that maps objects to SQLite databases. Being highly optimized, greenDAO offers great performance and consumes minimal memory.It relieves developers from dealing with low-level database requirements while saving development time Usage InstructionsA sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the sample/ folder.You can add new perrson info and delete person info by clicking on an existing person in the list. The following core classes are the essential interface to greenDAO:DaoMaster: The entry point for using greenDAO. DaoMaster holds the database object (SQLiteDatabase) and manages DAO classes (not objects) for a specific schema. It has static methods to create the tables or drop them. Its inner classes OpenHelper and DevOpenHelper are SQLiteOpenHelper implementations that create the schema in the SQLite database. DaoSession: Manages all available DAO objects for a specific schema, which you can acquire using one of the getter methods. DaoSession provides also some generic persistence methods like insert, load, update, refresh and delete for entities. Lastly, a DaoSession objects also keeps track of an identity scope. DAOs: Data access objects (DAOs) persists and queries for entities. For each entity, greenDAO generates a DAO. It has more persistence methods than DaoSession, for example: count, loadAll, and insertInTx. Entities: Persistable objects. Usually, entities are objects representing a database row using standard Java properties (like a POJO or a JavaBean). The steps to initialize the database and the core greenDAO classes:DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "people-db");Database db = helper.getWritableDb(); // get the person DAODaoSession daoSession = new DaoMaster(db).newSession();personDao = daoSession.getPersonDao(); QueryBuilder : The QueryBuilder class lets you build custom queries for your entities without SQL and helps detect errors already at compile time.// query all people, sorted by their NameList people = personDao.queryBuilder().orderAsc(PersonDao.Properties.NAME).build().list();
Features- Setting up the database
- Creating the DAO session
- Inserting, Deleting and updating database
- Queries, QueryBuilder, Order, Limit, Offset, and Pagination
- Query and LazyList, Executing Queries multiple times
- Raw queries, Delete queries
- Joins
- Database Encryption
Installation Tutorial:For using greendao in your sample application, add below dependencies: dependencies { implementation project(path: ':greenDAOLib:greendaoapi') implementation project(path: ':greenDAOLib:daocore') implementation project(path: ':greenDAOLib:daogenerator')} For using greendao in separate application, add the below dependencies and include greendao jars in libs folder of "entry" module: dependencies { implementation files('libs/greendaoapi.har') implementation files('libs/daocore.har') implementation files('libs/daogenerator.har')} Also for above two cases add the sqlcipher dependency in daocore build.gradle : dependencies { implementation 'io.openharmony.tpc.thirdlib:ohos-database-sqlcipher:1.0.2'} For using greendao from a remote repository in separate application, add the below dependencies in build.gradle of "entry" module: dependencies { implementation 'io.openharmony.tpc.thirdlib:greendaocore:1.0.0'} |
请发表评论