isar 0.0.4 isar: ^0.0.4 copied to clipboard
Fast Cross Platform Database for Flutter & Web Apps. Supports indexes, FTS, queries etc.
Isar Database
π§ Very unstable and not ready for serious usage π§
Quickstart β’ Documentation β’ Examples β’ Support & Ideas β’ Pub.dev
Isar [ee-zahr]:
- River in Bavaria, Germany.
- Database that will make your life easier.
Features #
- β‘οΈ Launch your app instantly no matter how much data you have
- π Highly scalable from hundreds to tens of thousands of records
- π Lazy loaded. Only load data when you need it
- π Full text search. Make searching fast and fun
- π± Multiplatform. iOS, Android, Desktop and the web (soonβ’)
- π Made for Flutter. Easily use it in your Flutter app
- π§ͺ ACID semantics. Rely on consistency
- β± Asynchronous. Parallel query operations & multi-isolate support
- β οΈ Static typing with compile time checked and autocompleted queries
Schema definition #
@Collection()
class Post with IsarObject {
@ObjectId() // implicit unique index
String uuid;
@Index(stringType: StringIndexType.words, caseSensitive: false) // Search index
String title;
List<String> comments
}
CRUD operations #
All basic crud operations are available via the IsarCollection.
final newPost = Post()
..id = uuid()
..title = 'Amazing new database'
..comments = ['First'];
await isar.writeTxn((isar) {
await isar.posts.put(newPost); // insert
});
final existingPost = await isar.get(newPost.id); // get
await isar.writeTxn((isar) {
await isar.posts.delete(existingPost.id); // delete
});
Query #
Isar has a powerful query language that allows you to make use of your indexes, filter distinct objects, use complex and()
and or()
groups and sort the results.
final isar = await openIsar();
final databasePosts = isar.posts
.where()
.titleWordBeginsWith('dAtAb') // use search index
.limit(10)
.findAll()
final postsWithFirstCommentOrTitle = isar.posts
.where()
.sortedById() // use implicit ObjectId index
.filter()
.commentsAnyEqualTo('first', caseSensitive: false)
.or()
.titleEqualTo('first')
.findAll();
Watch #
With Isar you can watch Collections, Objects or Queries. A watcher is notified after a transactions commits succesfully and the target actually changes. Watchers can be lazy and not reload the data or they can be non-lazy and fetch the new results in background.
Stream<void> collectionStream = isar.posts.watch(lazy: true);
Stream<List<Post>> queryStream = databasePosts.watch(lazy: false);
queryStream.listen((newResult) {
// do UI updates
})