18 changed files with 412 additions and 30 deletions
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
{ |
||||
"formatVersion": 1, |
||||
"database": { |
||||
"version": 1, |
||||
"identityHash": "2a46dc7add9af1cfb97918cdfe07c10d", |
||||
"entities": [ |
||||
{ |
||||
"tableName": "t_check_record", |
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `check_type` TEXT, `name` TEXT, `check_date` INTEGER, `description` TEXT, `create_date` INTEGER, `deleted` INTEGER, PRIMARY KEY(`id`))", |
||||
"fields": [ |
||||
{ |
||||
"fieldPath": "id", |
||||
"columnName": "id", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "checkType", |
||||
"columnName": "check_type", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "name", |
||||
"columnName": "name", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "checkDate", |
||||
"columnName": "check_date", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "description", |
||||
"columnName": "description", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "createDate", |
||||
"columnName": "create_date", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "deleted", |
||||
"columnName": "deleted", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
} |
||||
], |
||||
"primaryKey": { |
||||
"autoGenerate": false, |
||||
"columnNames": [ |
||||
"id" |
||||
] |
||||
}, |
||||
"indices": [], |
||||
"foreignKeys": [] |
||||
} |
||||
], |
||||
"views": [], |
||||
"setupQueries": [ |
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", |
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2a46dc7add9af1cfb97918cdfe07c10d')" |
||||
] |
||||
} |
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
{ |
||||
"formatVersion": 1, |
||||
"database": { |
||||
"version": 2, |
||||
"identityHash": "2a46dc7add9af1cfb97918cdfe07c10d", |
||||
"entities": [ |
||||
{ |
||||
"tableName": "t_check_record", |
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `check_type` TEXT, `name` TEXT, `check_date` INTEGER, `description` TEXT, `create_date` INTEGER, `deleted` INTEGER, PRIMARY KEY(`id`))", |
||||
"fields": [ |
||||
{ |
||||
"fieldPath": "id", |
||||
"columnName": "id", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "checkType", |
||||
"columnName": "check_type", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "name", |
||||
"columnName": "name", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "checkDate", |
||||
"columnName": "check_date", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "description", |
||||
"columnName": "description", |
||||
"affinity": "TEXT", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "createDate", |
||||
"columnName": "create_date", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
}, |
||||
{ |
||||
"fieldPath": "deleted", |
||||
"columnName": "deleted", |
||||
"affinity": "INTEGER", |
||||
"notNull": false |
||||
} |
||||
], |
||||
"primaryKey": { |
||||
"autoGenerate": false, |
||||
"columnNames": [ |
||||
"id" |
||||
] |
||||
}, |
||||
"indices": [], |
||||
"foreignKeys": [] |
||||
} |
||||
], |
||||
"views": [], |
||||
"setupQueries": [ |
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", |
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2a46dc7add9af1cfb97918cdfe07c10d')" |
||||
] |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
package cc.niushuai.didicheck.biz.dao; |
||||
|
||||
import androidx.room.Dao; |
||||
import androidx.room.Delete; |
||||
import androidx.room.Insert; |
||||
import androidx.room.Query; |
||||
|
||||
import java.util.List; |
||||
|
||||
import cc.niushuai.didicheck.biz.entity.CheckRecord; |
||||
import io.reactivex.Completable; |
||||
import io.reactivex.Flowable; |
||||
|
||||
@Dao |
||||
public interface CheckRecordDao { |
||||
|
||||
@Query("SELECT * FROM t_check_record") |
||||
Flowable<List<CheckRecord>> listAll(); |
||||
|
||||
|
||||
@Query("select * from t_check_record where deleted = 0 and check_date = :date") |
||||
Flowable<List<CheckRecord>> queryByDate(long date); |
||||
|
||||
@Query("select * from t_check_record where deleted = 0 and create_date >= :startDate and create_date <= :endDate ") |
||||
Flowable<List<CheckRecord>> queryByDate(long startDate, long endDate); |
||||
|
||||
|
||||
@Insert |
||||
Completable insertAll(CheckRecord... records); |
||||
|
||||
@Delete |
||||
void delete(CheckRecord record); |
||||
|
||||
@Delete |
||||
void delete(CheckRecord... records); |
||||
|
||||
|
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
package cc.niushuai.didicheck.biz.room; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import androidx.room.Room; |
||||
import androidx.room.RoomDatabase; |
||||
|
||||
import cc.niushuai.didicheck.biz.dao.CheckRecordDao; |
||||
|
||||
public class DBManager { |
||||
|
||||
public static DBManager INSTANCE; |
||||
private Context context; |
||||
private DiDiCheckDataBase diDiCheckDataBase; |
||||
|
||||
|
||||
public DBManager(Context context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
public static void init(Context context) { |
||||
INSTANCE = new DBManager(context); |
||||
} |
||||
|
||||
public static RoomDatabase buildDatabase(Context context, Class<? extends RoomDatabase> clazz, String dbName) { |
||||
RoomDatabase.Builder<? extends RoomDatabase> databaseBuilder = Room.databaseBuilder(context, clazz, dbName); |
||||
databaseBuilder.setJournalMode(RoomDatabase.JournalMode.AUTOMATIC); |
||||
return databaseBuilder.build(); |
||||
} |
||||
|
||||
public DiDiCheckDataBase getDiDiCheckDataBase() { |
||||
if (null == diDiCheckDataBase) { |
||||
diDiCheckDataBase = (DiDiCheckDataBase) buildDatabase(context, DiDiCheckDataBase.class, "didi_check"); |
||||
} |
||||
return diDiCheckDataBase; |
||||
} |
||||
|
||||
public CheckRecordDao checkRecordDao() { |
||||
return getDiDiCheckDataBase().checkRecordDao(); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
package cc.niushuai.didicheck.biz.room; |
||||
|
||||
import androidx.room.Database; |
||||
import androidx.room.RoomDatabase; |
||||
|
||||
import cc.niushuai.didicheck.biz.dao.CheckRecordDao; |
||||
import cc.niushuai.didicheck.biz.entity.CheckRecord; |
||||
|
||||
@Database(entities = {CheckRecord.class}, version = 2) |
||||
public abstract class DiDiCheckDataBase extends RoomDatabase { |
||||
|
||||
public abstract CheckRecordDao checkRecordDao(); |
||||
} |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 4.5 KiB |
Loading…
Reference in new issue