# greenDAO **Repository Path**: HarmonyOS-tpc/greenDAO ## Basic Information - **Project Name**: greenDAO - **Description**: GreenDAO is a light & fast ORM that maps objects to SQLite databases. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 31 - **Forks**: 2 - **Created**: 2021-04-01 - **Last Updated**: 2025-09-02 ## Categories & Tags **Categories**: harmony, database-dev **Tags**: None ## README # GreenDao GreenDAO 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 Instructions 1. A 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. 2. 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). 3. 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 DAO DaoSession daoSession = new DaoMaster(db).newSession(); personDao = daoSession.getPersonDao(); 4. **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 Name List 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: 1. 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') } ``` 2. 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' } ``` 3. 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' } ```