Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

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]:

  1. River in Bavaria, Germany.
  2. Crazy fast NoSQL database that is a joy to use.

Features

Isar database can do much more (and we are just getting started)

Join the Telegram group for discussion and sneak peaks of new versions of the db.

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

isar_version: &isar_version 3.0.2 # define the version to be used

dependencies:
  isar: *isar_version
  isar_flutter_libs: *isar_version # contains Isar Core

dev_dependencies:
  isar_generator: *isar_version
  build_runner: any

2. Annotate a Collection

part 'email.g.dart';

@collection
class Email {
  Id id = Isar.autoIncrement; // you can also use id = null to auto increment

  @Index(type: IndexType.value)
  String? title;

  List<Recipient>? recipients;

  @enumerated
  Status status = Status.pending;
}

@embedded
class Recipient {
  String? name;

  String? address;
}

enum Status {
  draft,
  sending,
  sent,
}

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)
  .sortByStatusDesc()
  .limit(10)
  .findAll();

Isar Database Inspector

The Isar Inspector allows you to inspect the Isar instances & collections of your app in real-time. You can execute queries, edit properties, switch between instances and sort the data.

CRUD operations

All basic crud operations are available via the IsarCollection.

final newEmail = Email()..title = 'Amazing new database';

await isar.writeTxn(() {
  await isar.emails.put(newEmail); // insert & update
});

final existingEmail = await isar.emails.get(newEmail.id!); // get

await isar.writeTxn(() {
  await isar.emails.delete(existingEmail.id!); // delete
});

Database Queries

Isar database 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 importantEmails = isar.emails
  .where()
  .titleStartsWith('Important') // use index
  .limit(10)
  .findAll()

final specificEmails = isar.emails
  .filter()
  .recipient((q) => q.nameEqualTo('David')) // query embedded objects
  .or()
  .titleMatches('*university*', caseSensitive: false) // title containing 'university' (case insensitive)
  .findAll()

Database 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.emails.watchLazy();

Stream<List<Post>> queryStream = importantEmails.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 NoSQL 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 NoSQL database 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.

Download and/or contribute to this package on GitHub

https://github.com/isar/isar
Exit mobile version