GreenDao 的基本用法
模糊查询
daoSession.queryBuilder(MessageTable.class).where(MessageTableDao.Properties.IsRead.eq("did")).list();
创建对象
DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context, ShopConstants.SQ_MANAGE);
DaoSession daoSession = new DaoMaster(devOpenHelper.getWritableDatabase()).newSession();
添加
daoSession.insert(message);
查询所有
daoSession.loadAll(MessageTable.class);
查询一个
daoSession.load(MessageTable.class,key)
修改
daoSession.update(messageTable);
删除一个 和删除所有
daoSession.delete(MessageTable.class);
daoSession.deleteAll(MessageTable.class);
依赖
----------------------------------------GreenDao-------------Entity-----Id(autoincrement = true)------------------
@Transient 标识该属性将不会映射到表中,也就是没有这列
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
dependencies {
implementation 'org.greenrobot:greendao:3.3.0'
}
greendao {
schemaVersion 1
targetGenDir 'src/main/java'
daoPackage 'com.example.lib_core.db'
}