DBFlow is a SQLite library for Android that makes it ridiculously easy to interact and use databases. Built with Annotation Processing that generates most of the boilerplate code for you, code use within a DB is fast, efficient, and type-safe. It removes the tedious (and tough-to-maintain) database interaction code.

Creating a database is as easy as a few lines of code:

@Database(name = AppDatabase.NAME, version = AppDatabase.VERSION)
public class AppDatabase {

  public static final String NAME = "AppDatabase";

  public static final int VERSION = 1;

The @Database annotation generates a DatabaseDefinition which now references your SQLite Database on disk in the file named "AppDatabase.db". You can reference it in code as:

DatabaseDefinition db = FlowManager.getDatabase(AppDatabase.class);

To ensure generated code in DBFlow is found by the library, initialize the library in your Application class:

public class MyApp extends Application {

  public void onCreate() {

By default, DBFlow generates the GeneratedDatabaseHolder class, which is instantiated once by reflection, only once in memory.

Creating a table is also very simple:

@Table(database = AppDatabase.class)
public class User {

  @PrimaryKey // at least one primary key required
  UUID id; 

  String name;

  int age;

Then to create, read, update, and delete the model:

User user = new User();
user.id = UUID.randomUUID();
user.name = "Andrew Grosner";
user.age = 27;

ModelAdapter<User> adapter = FlowManager.getModelAdapter(User.class);

user.name = "Not Andrew Grosner";


// if you extend BaseModel or implement Model

// find adult users
List<User> users = SQLite.select()

// or asynchronous retrieval
  .queryListCallback((QueryTransaction transaction, @NonNull CursorResult<User> result) -> {
              // called when query returns on UI thread
              try {
                List<User> users = result.toList();
                // do something with users
              } finally {
  .error((Transaction transaction, Throwable error) -> {
              // handle any errors

results matching ""

    No results matching ""