isar 3.0.0-dev.10 isar: ^3.0.0-dev.10 copied to clipboard
Extremely fast, easy to use, and fully async NoSQL database for Flutter.
Isar Database
Quickstart • Documentation • Sample Apps • Support & Ideas • Pub.dev
Isar [ee-zahr]:
- River in Bavaria, Germany.
- Crazy fast database that is a joy to use.
Features #
- 💙 Made for Flutter. Easy to use, no config, no boilerplate
- 🚀 Highly scalable The sky is the limit (pun intended)
- 🍭 Feature rich. Composite & multi-entry indexes, query modifiers, JSON support etc.
- ⏱ Asynchronous. Parallel query operations & multi-isolate support by default
- 🦄 Open source. Everything is open source and free forever!
Isar can do much more (and we are just getting started)
- 🕵️ Full-text search. Make searching fast and fun
- 📱 Multiplatform. iOS, Android, Desktop and FULL WEB SUPPORT!
- 🧪 ACID semantics. Rely on database consistency
- 💃 Static typing. Compile-time checked and autocompleted queries
- ✨ Beautiful documentation. Readable, easy to understand and ever improving
Join the Telegram group for discussion and check out the CONTRIBUTING.md doc.
If you want to say thank you, star us on GitHub and like us on pub.dev 🙌💙
Quickstart #
Holy smokes you're here! Let's get started on using the coolest Flutter database out there...
1. Add to pubspec.yaml #
dependencies:
isar: 3.0.0-dev.8
isar_flutter_libs: 3.0.0-dev.8 # contains Isar Core
dev_dependencies:
isar_generator: 3.0.0-dev.8
build_runner: any
2. Annotate a Collection #
part 'email.g.dart';
@collection
class Email {
Id id = Isar.autoIncrement;
String? title;
List<Recipient>? recipients;
Status? status;
}
@embedded
class Recipient {
String? name;
String? address;
}
enum Status with IsarEnum<String> {
draft,
sending,
sent;
@override
String get value => name;
}
3. Open a database instance #
final isar = await Isar.open([EmailSchema]);
4. Query the database #
final emails = await isar.emails.filter()
.titleContains('awesome', caseSensitive: false)
.sortByDateDesc()
.limit(10)
.findAll();
Isar Inspector #
The Isar Inspector allows you to inspect the Isar instances & collections of your app in real time. You can execute queries, switch between instances and sort the data.
CRUD operations #
All basic crud operations are available via the IsarCollection.
final newPost = Post()..title = 'Amazing new database';
await isar.writeTxn(() {
newPost.id = await isar.posts.put(newPost); // insert & update
});
final existingPost = await isar.posts.get(newPost.id!); // get
await isar.writeTxn(() {
await isar.posts.delete(existingPost.id!); // delete
});
Queries #
Isar has a powerful query language that allows you to make use of your indexes, filter distinct objects, use complex and()
, or()
and .xor()
groups, query links and sort the results.
final usersWithPrefix = isar.users
.where()
.nameStartsWith('dan') // use index
.limit(10)
.findAll()
final usersLivingInMunich = isar.users
.filter()
.ageGreaterThan(32)
.or()
.addressMatches('*Munich*', caseSensitive: false) // address containing 'munich' (case insensitive)
.optional(
shouldSort, // only apply if shouldSort == true
(q) => q.sortedByAge(),
)
.findAll()
Links #
You can easily define relationships between objects. In Isar they are called links and backlinks:
@collection
class Teacher {
Id? id;
late String subject;
@Backlink(to: 'teacher')
final students = IsarLinks<Student>();
}
@collection
class Student {
Id? id;
late String name;
final teacher = IsarLink<Teacher>();
}
Watchers #
With Isar database, you can watch Collections, Objects, or Queries. A watcher is notified after a transaction commits successfully and the target actually changes. Watchers can be lazy and not reload the data or they can be non-lazy and fetch new results in the background.
Stream<void> collectionStream = isar.posts.watchLazy;
Stream<List<Post>> queryStream = databasePosts.watch();
queryStream.listen((newResult) {
// do UI updates
})
Benchmarks #
Benchmarks only give a rough idea of the performance of a database but as you can see, Isar database is quite fast 😇
If you are interested in more benchmarks or want to check how Isar performs on your device you can run the benchmarks yourself.
Unit tests #
If you want to use Isar database in unit tests or Dart code, call await Isar.initializeIsarCore(download: true)
before using Isar in your tests.
Isar will automatically download the correct binary for your platform. You can also pass a libraries
map to adjust the download location for each platform.
Make sure to use flutter test -j 1
to avoid tests running in parallel. This would break the automatic download.
Contributors ✨ #
Thanks goes to these wonderful people:
Hamed H. 💻 🚧 |
JT ⚠️ 🐛 |
Peyman 🐛 💻 |
Simon Leier 🐛 💻 📖 ⚠️ 💡 |
blendthink 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!
License #
Copyright 2022 Simon Leier
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.