objectbox-java
Android Database - first and fast, lightweight on-device vector database
Top Related Projects
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
Realm is a mobile database: a replacement for SQLite & ORMs
requery - modern SQL based query & persistence for Java / Kotlin / Android
Insanely easy way to work with Android Database.
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
Quick Overview
ObjectBox is a fast, object-oriented database for Java and Android applications. It offers high performance, a simple API, and efficient data handling, making it suitable for mobile and IoT devices as well as server applications.
Pros
- High performance and low memory footprint
- Simple and intuitive API for easy integration
- Supports relations and queries with automatic indexing
- Cross-platform compatibility (Java, Android, iOS, Go)
Cons
- Limited ecosystem compared to more established databases
- Less suitable for complex, large-scale applications
- Steeper learning curve for developers used to SQL-based systems
- Limited documentation and community resources compared to mainstream databases
Code Examples
- Creating and storing objects:
@Entity
public class User {
@Id long id;
String name;
int age;
}
Box<User> userBox = store.boxFor(User.class);
User user = new User();
user.name = "John Doe";
user.age = 30;
long id = userBox.put(user);
- Querying objects:
List<User> users = userBox.query()
.equal(User_.age, 30)
.order(User_.name)
.build()
.find();
- Updating objects:
User user = userBox.get(id);
user.age = 31;
userBox.put(user);
Getting Started
- Add ObjectBox to your project:
dependencies {
implementation "io.objectbox:objectbox-java:3.1.1"
}
- Initialize ObjectBox in your application:
BoxStore store = MyObjectBox.builder()
.name("objectbox-example")
.build();
- Define your entity classes with @Entity and @Id annotations:
@Entity
public class User {
@Id long id;
String name;
int age;
}
- Use BoxStore to perform database operations:
Box<User> userBox = store.boxFor(User.class);
User user = new User();
user.name = "John Doe";
user.age = 30;
long id = userBox.put(user);
Competitor Comparisons
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
Pros of greenDAO
- More mature and established project with a larger user base
- Simpler setup and integration process for basic use cases
- Smaller library size, potentially reducing app size
Cons of greenDAO
- Less performant for large datasets compared to ObjectBox
- Limited support for complex queries and relationships
- Lack of built-in encryption support
Code Comparison
greenDAO:
@Entity
public class User {
@Id private Long id;
private String name;
private int age;
}
ObjectBox:
@Entity
public class User {
@Id public long id;
public String name;
public int age;
}
Both libraries use annotations to define entities, but ObjectBox uses public fields by default, while greenDAO typically uses private fields with getter and setter methods.
ObjectBox offers more advanced features like automatic indexing, lazy loading, and built-in encryption. It also provides better performance for large datasets and complex queries. However, greenDAO may be easier to set up and use for simpler projects.
greenDAO has been around longer and has a larger community, which can be beneficial for finding resources and support. ObjectBox, being newer, offers more modern features and better performance but may have a smaller ecosystem.
Choose greenDAO for simpler projects with basic database needs, and ObjectBox for applications requiring high performance or advanced features.
Realm is a mobile database: a replacement for SQLite & ORMs
Pros of Realm Java
- More mature and widely adopted, with a larger community and ecosystem
- Supports real-time synchronization and multi-user collaboration out of the box
- Offers cross-platform support for iOS, Android, and web applications
Cons of Realm Java
- Steeper learning curve due to its unique object model and query language
- Larger file size and potential performance overhead in some scenarios
- Less flexible schema migration compared to ObjectBox
Code Comparison
ObjectBox Java:
@Entity
public class User {
@Id long id;
String name;
int age;
}
Box<User> userBox = store.boxFor(User.class);
userBox.put(new User(0, "Alice", 25));
List<User> users = userBox.query().equal(User_.age, 25).build().find();
Realm Java:
public class User extends RealmObject {
@PrimaryKey
private long id;
private String name;
private int age;
}
realm.executeTransaction(r -> {
User user = r.createObject(User.class, 0);
user.setName("Alice");
user.setAge(25);
});
RealmResults<User> users = realm.where(User.class).equalTo("age", 25).findAll();
Both libraries offer similar functionality for basic CRUD operations, but Realm uses its own object model and query syntax, while ObjectBox follows a more traditional approach with annotations and a fluent query API.
requery - modern SQL based query & persistence for Java / Kotlin / Android
Pros of requery
- More flexible query API with support for complex joins and subqueries
- Built-in support for RxJava and async operations
- Wider database support, including SQLite, MySQL, PostgreSQL, and Oracle
Cons of requery
- Steeper learning curve due to more complex API
- Potentially slower performance for simple operations compared to ObjectBox
- Less focus on mobile-specific optimizations
Code Comparison
ObjectBox:
Box<User> userBox = store.boxFor(User.class);
User user = new User("John", "Doe");
userBox.put(user);
requery:
EntityStore data = ...;
User user = new User();
user.setFirstName("John");
user.setLastName("Doe");
data.insert(user);
Summary
ObjectBox is designed for simplicity and performance, especially on mobile platforms, while requery offers more flexibility and broader database support. ObjectBox has a simpler API and potentially better performance for basic operations, but requery provides more advanced querying capabilities and wider platform compatibility. The choice between the two depends on the specific requirements of your project, such as the need for complex queries, database flexibility, or mobile optimization.
Insanely easy way to work with Android Database.
Pros of Sugar
- Simpler API with less boilerplate code
- Easier to set up and integrate into existing projects
- Better documentation and community support
Cons of Sugar
- Lower performance compared to ObjectBox, especially for large datasets
- Limited query capabilities and less flexibility in complex data operations
- Lack of advanced features like lazy loading and automatic schema migration
Code Comparison
Sugar:
@Table
public class Book extends SugarRecord {
String title;
String author;
}
Book book = new Book();
book.title = "1984";
book.author = "George Orwell";
book.save();
ObjectBox:
@Entity
public class Book {
@Id long id;
String title;
String author;
}
Box<Book> bookBox = store.boxFor(Book.class);
Book book = new Book();
book.title = "1984";
book.author = "George Orwell";
bookBox.put(book);
Both Sugar and ObjectBox provide ORM solutions for Android, but they differ in their approach and features. Sugar focuses on simplicity and ease of use, making it a good choice for smaller projects or developers new to ORM. ObjectBox, on the other hand, offers better performance and more advanced features, making it suitable for larger, more complex applications. The choice between the two depends on the specific requirements of your project and your familiarity with ORM concepts.
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
Pros of DBFlow
- More mature and established project with a larger community
- Supports complex queries and relationships between entities
- Offers a flexible annotation-based approach for defining database schemas
Cons of DBFlow
- Steeper learning curve due to more complex API
- Slower performance for large datasets compared to ObjectBox
- Requires more boilerplate code for basic operations
Code Comparison
DBFlow:
@Table(database = AppDatabase.class)
public class User {
@PrimaryKey
int id;
@Column
String name;
}
ObjectBox:
@Entity
public class User {
@Id
long id;
String name;
}
Key Differences
- DBFlow uses annotations extensively for configuration, while ObjectBox has a simpler entity definition
- ObjectBox offers better performance for large datasets and mobile applications
- DBFlow provides more advanced querying capabilities out of the box
- ObjectBox has a smaller footprint and is easier to set up for basic use cases
Both libraries aim to simplify database operations in Android applications, but they cater to different needs. DBFlow is more suitable for complex database structures and queries, while ObjectBox excels in performance and simplicity for mobile apps with straightforward data models.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Getting Started ⢠Documentation ⢠Example Apps ⢠Issues
ObjectBox - Fast and Efficient Java Database (Android, JVM) with Vector Search
ObjectBox Java is a lightweight yet powerful on-device database & vector database designed specifically for Java and Kotlin applications. Store and manage data effortlessly in your Android or JVM Linux, macOS or Windows app with ObjectBox. Easily manage vector data alongside your objects and perform superfast on-device vector search to empower your apps with RAG AI, generative AI, and similarity search. Enjoy exceptional speed, battery-friendly resource usage, and environmentally-friendly development. ð
Demo code
// Java
Playlist playlist = new Playlist("My Favorites");
playlist.songs.add(new Song("Lalala"));
playlist.songs.add(new Song("Lololo"));
box.put(playlist);
â¡ï¸ More details in the docs
// Kotlin
val playlist = Playlist("My Favorites")
playlist.songs.add(Song("Lalala"))
playlist.songs.add(Song("Lololo"))
box.put(playlist)
Table of Contents
- Key Features
- Getting started
- Why use ObjectBox?
- Community and Support
- Other languages/bindings
- License
Key Features
ð§ First on-device vector database: easily manage vector data and perform fast vector search
ð High performance: exceptional speed, outperforming alternatives like SQLite and Realm in all CRUD operations.
ð Efficient Resource Usage: minimal CPU, power and memory consumption for maximum flexibility and sustainability.
ð Built-in Object Relations: built-in support for object relations, allowing you to easily establish and manage relationships between objects.
ð Ease of use: concise API that eliminates the need for complex SQL queries, saving you time and effort during development.
Getting started
Gradle setup
For Android projects, add the ObjectBox Gradle plugin to your root build.gradle
:
buildscript {
ext.objectboxVersion = "4.0.2"
repositories {
mavenCentral()
}
dependencies {
classpath("io.objectbox:objectbox-gradle-plugin:$objectboxVersion")
}
}
And in your app's build.gradle
apply the plugin:
// Using plugins syntax:
plugins {
id("io.objectbox") // Add after other plugins.
}
// Or using the old apply syntax:
apply plugin: "io.objectbox" // Add after other plugins.
First steps
Create a data object class @Entity
, for example "Playlist".
// Kotlin
@Entity data class Playlist( ... )
// Java
@Entity public class Playlist { ... }
Now build the project to let ObjectBox generate the class MyObjectBox
for you.
Prepare the BoxStore object once for your app, e.g. in onCreate
in your Application class:
boxStore = MyObjectBox.builder().androidContext(this).build();
Then get a Box
class for the Playlist entity class:
Box<Playlist> box = boxStore.boxFor(Playlist.class);
The Box
object gives you access to all major functions, like put
, get
, remove
, and query
.
For details please check the docs.
Why use ObjectBox for Java data management?
ObjectBox is a NoSQL Java database designed for local data storage on resource-restricted devices, prioritizing offline-first functionality. It is a smart and sustainable choice for local data persistence in Java and Kotlin applications. It offers efficiency, ease of use, and flexibility.
Fast but resourceful
Optimized for speed and minimal resource consumption, ObjectBox is an ideal solution for mobile devices. It has excellent performance, while also minimizing CPU, RAM, and power usage. ObjectBox outperforms SQLite and Realm across all CRUD (Create, Read, Update, Delete) operations. Check out our Performance Benchmarking App repository.
Simple but powerful
With its concise language-native API, ObjectBox simplifies development by requiring less code compared to SQLite. It operates on plain objects (POJOs) with built-in relations, eliminating the need to manage rows and columns. This approach is efficient for handling large data volumes and allows for easy model modifications.
Functionality
ð Queries: filter data as needed, even across relations
ð» Multiplatform: supports Android and JVM on Linux (also on ARM), Windows and macOS
ð± Scalable: handling millions of objects resource-efficiently with ease
𦮠Statically typed: compile time checks & optimizations
ð Automatic schema migrations: no update scripts needed
And much more than just data persistence
ð ObjectBox Sync: keeps data in sync between devices and servers
ð ObjectBox TS: time series extension for time based data
Community and Support
⤠Tell us what you think! Share your thoughts through our Anonymous Feedback Form.
At ObjectBox, we are dedicated to bringing joy and delight to app developers by providing intuitive and fun-to-code-with APIs. We genuinely want to hear from you: What do you love about ObjectBox? What could be improved? Where do you face challenges in everyday app development?
We eagerly await your comments and requests, so please feel free to reach out to us:
- Add GitHub issues
- Upvote important issues ð
- Drop us a line via @ObjectBox_io or contact[at]objectbox.io
- â us on GitHub if you like what you see!
Thank you! Stay updated with our blog.
Other languages/bindings
ObjectBox supports multiple platforms and languages. Besides JVM based languages like Java and Kotlin, ObjectBox also offers:
- Swift Database: build fast mobile apps for iOS (and macOS)
- Dart/Flutter Database: cross-platform for mobile and desktop apps
- Go Database: great for data-driven tools and embedded server applications
- C and C++ Database: native speed with zero copy access to FlatBuffer objects
License
Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that this license applies to the code in this repository only. See our website on details about all licenses for ObjectBox components.
Top Related Projects
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
Realm is a mobile database: a replacement for SQLite & ORMs
requery - modern SQL based query & persistence for Java / Kotlin / Android
Insanely easy way to work with Android Database.
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot