Use of Android bdflow database artifact

Today, while watching other people's source code, I accidentally found a very useful database artifact. I'll share it here.

What is dbflow?

Dbflow is a tool library manipulated by annotations in Android SQLite orm. In short, it is a Java library for operating SQLite database.

ORM (object relational mapping), translated into Chinese as object relational mapping, is a technology to solve the mismatch between object-oriented and relational databases. In short, ORM is to automatically persist the objects in the program to the relational database by using metadata describing the mapping between the object and the database.

Why use dbflow?

1. Speed

Based on annotation processing (annotation processor), code is generated at compile time, with excellent runtime performance. Good speed experience is obtained by reusing objects and caching mechanism.

2. Expansibility

The data form is mapped to a data object, which inherits the model class. Generally, it inherits the basemodel class to annotate the members in the class and generate the required form.

3. Query statement

If you have used other libraries such as greendao, the query statements are very close to SQL statements.

4. Based on SQLite

There is no restriction on the platform. Dbflow can be used where there is SQLite.

5. Open source

The source code is a good thing. People with ability can see it. https://github.com/Raizlabs/DBFlow

How to use dbflow

Configuration environment

No matter what you want to learn, the environment is the main thing. For a third-party library, the first step is to import the class library.

First, add the Maven address in the main build.gradle:

Secondly, add dependencies in the base class module:

If you need to add the code of kotlin, check the source code above, and there are instructions below the address.

use

Add init in application

Create database

Use the annotation database name database name version database version

create form

Annotate the dependent database object of table database, and use various annotations for form attributes, primarykey, primary key and colum column.

Note: the basemodel we inherit here is provided to us by dbflow and can not be inherited. The difference is only the operation of adding, deleting, modifying and querying.

After creation, click build - > make to generate the necessary code under.. \ build \ generated \ source \ apt \ debug.

Insert:

Create a form object, after assignment, call the save method to insert the operation.

Delete:

Code similar to SQL statements

Query:

There are many complex query operations. If you want to know the details, please refer to the official documents.

to update:

Are similar.

Note: after creating a new form, you need to upgrade the version of the database, otherwise an error will be reported.

Here is a brief introduction to the basic use of dbflow, which is mainly used to share and record some useful things,

Source code: https://github.com/xiaogoudandan/WilliamApp

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>