DBFlowDocs
DBFlow documentation project.
Install / Use
/learn @agrosner/DBFlowDocsREADME
DBFlow
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 {
@Override
public void onCreate() {
super.onCreate();
FlowManager.init(this);
}
}
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;
@Column
String name;
@Column
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);
adapter.insert(user);
user.name = "Not Andrew Grosner";
adapter.update(user);
adapter.delete(user);
// if you extend BaseModel or implement Model
user.insert();
user.update();
user.delete();
user.save();
// find adult users
List<User> users = SQLite.select()
.from(User.class)
.where(User_Table.age.greaterThan(18))
.queryList();
// or asynchronous retrieval
SQLite.select()
.from(User.class)
.where(User_Table.age.greaterThan(18))
.async()
.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 {
result.close();
}
})
.error((Transaction transaction, Throwable error) -> {
// handle any errors
})
.execute();
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
Security Score
Audited on Oct 14, 2021
