微前端架构如何改变企业的开发模式与效率提升
849
2022-11-19
android DBFlow
随意翻了一下android数据库框架,找到这个,个人感觉是封装性高,但是如果要执行原生SQL,没有进行单独封装,不太方便,值得吐槽的是,使用SQLite.insert(XX.class)这种格式,连官方说明中都没有给出用法,不解,经测试,找出,后面会补。官方api: 中文版api:build.gradle:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' }}allprojects { repositories { jcenter() } repositories { maven { url "} }}task clean(type: Delete) {
module build.gradle
def dbflow_version = "3.0.0-beta2"dependencies{ apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}" compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}" compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}" // sql-cipher database encyrption (optional) compile "com.github.Raizlabs.DBFlow:dbflow-sqlcipher:${dbflow_version}"
增删改查
@Database(name = DBFlowDatabase.NAME, version = DBFlowDatabase.VERSION)public class DBFlowDatabase //数据库名称 public static final String NAME = "DBFlowDatabase"; //数据库版本号 public static final int VERSION = 1;}
model:
@ModelContainer@Table(database = DBFlowDatabase.class)public class UserModel extends BaseModel //自增ID @Column @PrimaryKey(autoincrement = true) public Long id; @Column public String name; @Column public int
增删改查:
public class DBFlowActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dbflow); } public void add(View view) { SQLite.insert(UserModel.class) .columns(UserModel_Table.name.getNameAlias().getName(),UserModel_Table.sex.getNameAlias().getName()) .columnValues(UserModel_Table.name.eq("测试1"),UserModel_Table.sex.eq(2)) .execute(); } public void delete(View view) { SQLite.delete(UserModel.class) .where(UserModel_Table.name.is("测试")) .query(); } public void update(View view) { SQLite.update(UserModel.class) .set(UserModel_Table.name.eq("测试1")) .where(UserModel_Table.sex.is(1)) .execute(); } public void select(View view) { List
数据库升级
改版本
@Database(name = DBFlowDatabase.NAME, version = DBFlowDatabase.VERSION)public class DBFlowDatabase //数据库名称 public static final String NAME = "DBFlowDatabase"; //数据库版本号 public static final int VERSION = 2;}
改表结构
@ModelContainer@Table(database = DBFlowDatabase.class)public class UserModel extends BaseModel //自增ID @Column @PrimaryKey(autoincrement = true) public Long id; @Column public String name; @Column public int sex; @Column public int
DBFlowDatabase增加内部类:
@Database(name = DBFlowDatabase.NAME, version = DBFlowDatabase.VERSION)public class DBFlowDatabase //数据库名称 public static final String NAME = "DBFlowDatabase"; //数据库版本号 public static final int VERSION = 2; //出现需要包含xx的封闭实例时使用静态内部类 @Migration(version = 2, database = DBFlowDatabase.class) public static class Migration1 extends AlterTableMigration
这个升级方法真的n级别吐槽,以1升到2为例,有三个表就要写三个内部类,2到3改3个表又要写3个内部类,这方式还不如原本的方式呢,不如原本的if…else结构简洁。 另外,比较要命的是,此数据库框架对sqlcipher的支持现在无效了,api的都没法用: 初始化要写成这样:
public class SQLCipherHelperImpl extends SQLCipherOpenHelper public SQLCipherHelperImpl(BaseDatabaseDefinition databaseDefinition, DatabaseHelperListener listener) { super(databaseDefinition, listener); } @Override protected String getCipherSecret() { return "sesese"; }}
FlowManager.init(FlowConfig.builder(context) .addDatabaseConfig( DatabaseConfig.builder(CipherDatabase.class) .openHelper(new DatabaseConfig.OpenHelperCreator() { @Override public OpenHelper createHelper(DatabaseDefinition databaseDefinition, DatabaseHelperListener helperListener) { return new SQLCipherHelperImpl(databaseDefinition, helperListener); } }) .build()) .build());
然而找不到类FlowConfig,官网把cipher相关的屏蔽掉了,再研究。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~