/objectbox-dart

Flutter database for super-fast Dart object persistence

Primary LanguageDartApache License 2.0Apache-2.0

ObjectBox

Getting StartedDocumentationExample AppsIssues

Build and test pub.dev package Apache 2.0 license Follow @ObjectBox_io

Flutter database for fast Dart object persistence 💙

Database for Flutter / Dart - fast and simple. Persist local Dart objects with ease & speed, focus on the value your application provides.

Demo code

var person = Person(firstName: 'Joe', lastName: 'Green');
final id = box.put(person);  // Create
person = box.get(id)!;       // Read
person.lastName = "Black";
box.put(person);             // Update
box.remove(person.id);       // Delete

--> For more details check out the docs

Table of Contents

Why use ObjectBox

ObjectBox Flutter database is a great option for storing Dart objects locally in your cross-platform apps. It uses minimal CPU, memory and battery / power, which makes it a sustainable choice for mobile and IoT devices. Made for efficient data access, it is 10x faster than any alternative across all CRUD operations. See the performance benchmarks below. No need to learn SQL, as our NoSQL database uses a pure Dart API that is easy to work with and can be integrated in minutes. Plus: We built a data synchronization solution that allows you to choose which objects to sync when and keep data easily and efficiently in sync across devices.

Features

🏁 High performance - superfast response rates enabling real-time applications.
🪂 ACID compliant - Atomic, Consistent, Isolated, Durable.
💻 Multiplatform - Android, iOS, macOS, Linux, Windows, any POSIX-system.
🌱 Scalable - grows with your app, handling millions of objects with ease.
💚 Sustainable - frugal on CPU, Memory and battery / power use, reducing CO2 emmissions.

🔗 Relations - object links / relationships are built-in.
💐 Queries - filter data as needed, even across relations.
🦮 Statically typed - compile time checks & optimizations.
📃 Schema migration - change your model with confidence.

Oh, and there is one more thing...

😮 Data Sync - keeps data in sync offline or online, between devices and servers.

Getting Started

Dependencies

Add these to your pubsec.yaml:

dependencies:
  objectbox: ^1.6.2
  objectbox_flutter_libs: any

dev_dependencies:
  build_runner: ^2.0.0
  objectbox_generator: any

First steps

  1. Define an entity class
@Entity()
class Person {
  int id;
 
  String firstName;
  String lastName;
 
  Person({this.id = 0, required this.firstName, required this.lastName});
}
  1. Run dart run build_runner build to generate the binding code -> objectbox.g.dart

  2. Create the ObjectBox store of your app

import 'objectbox.g.dart';
final store = openStore();
  1. Get a Box class
final box = store.box<Person>();
  1. Have fun using the Box functions, e.g. put, get, remove, query, as shown in the Demo code above.

Further steps

For more details about using ObjectBox in your Flutter/Dart app, head over to

How does ObjectBox compare to other solutions?

  • ObjectBox is fast. Have a look at our benchmarks below, or test it for yourself
  • It's a full NoSQL SQLite alternative with intuitive Dart APIs you'll love 💙
  • It comes with an out-of-the-box Data Sync, making it an effective self-hosted Firebase alternative

Flutter Database Performance Benchmarks

We tested across the four main database operations, CRUD (create, read, update, delete). Each test was run multiple times and executed manually outside of the measured time. Data preparation and evaluation were done outside of the measured time.

Here are the benchmarks for ObjectBox vs sqflite vs Hive 👇

You can run these yourself using our objectbox-dart-performance Flutter benchmark app.

Do you 💙 ObjectBox?

We strive to bring joy to Flutter developers and appreciate all kind of feedback, both positive and negative.

What do you love? What's amiss? Where do you struggle in everyday app development? --> Please fill in this 2-minute Anonymous Feedback Form.

We're looking forward to receiving your comments and requests:

  • Add GitHub issues
  • Upvote issues you find important by hitting the 👍/+1 reaction button
  • Fill in the feedback form to help us improve our products
  • Drop us a line on Twitter via @ObjectBox_io
  • ⭐ us on GitHub, if you like what you see or give us a 👍 on pub.dev

Thank you! 🙏

Keep in touch: For general news on ObjectBox, check our blog!

Contributing

Do you want to check out the ObjectBox code itself? E.g. see in action, run tests, or even contribute code? Great! Clone/check out this repository and run this to generate code and get you started quickly:

./tool/init.sh

Also, make sure to have a look at the contribution guidelines - we are looking forward to your contribution.

Packages

This repository holds all ObjectBox Dart/Flutter packages as separate directories:

There's also a separate repository benchmarking objectbox (and other databases) in Flutter: objectbox-dart-performance. And another one testing and comparing the performance of our FlatBuffers fork vs the upstream version: flatbuffers-benchmark.

Other languages/bindings

ObjectBox supports multiple platforms and languages:

  • Java Database (+ Kotlin): runs on Android, desktop, and servers.
  • Swift Database: build fast mobile apps for iOS and macOS.
  • Go Database: great for data-driven tools and embedded server applications.
  • C / C++ Database: native speed with zero copy access to FlatBuffer objects.

License

Copyright 2019-2022 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.