Skip to content

jvincek/isar-2.5.0

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PREAMBLE

This repository is not the official Isar repository. You can find it here: https://github.com/isar/isar.

It is a temporary fork, based on version 2.5.0, but with updated dependencies - https://github.com/isar/isar/tree/2.5.0.

Originally Isar supported Flutter Web, but the upgrade to version ^3.0.0 broke that feature - isar/isar#686.

As soon as Isar's author publishes an update for ^3.0.0 that restores support for Flutter Web, this fork will be discontinued and you will be encouraged to upgrade to that version and use the official packages from pub.dev - https://pub.dev/packages/isar.

This fork will not see any new features, bug fixes, or any other kind of improvement, except the minimum required to keep its dependencies up to date.

Here's what you need to add to pubspec.yaml to introduce it as a dependency:

# this is required to be able
# to use git dependencies
publish_to: 'none'

dependencies:
  isar:
    git:
      url: https://github.com/Giuspepe/isar-2.5.0
      path: packages/isar

  # for flutter:
  isar_flutter_libs: 2.5.0

dev_dependencies:
  isar_generator:
    git:
      url: https://github.com/Giuspepe/isar-2.5.0
      path: packages/isar_generator

dependency_overrides:
  isar:
    git:
      url: https://github.com/Giuspepe/isar-2.5.0
      path: packages/isar

I created this fork for my convenience and I made it public so anyone can use it. However, I do not have the competence on this package to perform maintenance tasks that exceed keeping dependencies up to date. So, the only issues I will not outright reject here are the following:

  • Out of date dependencies that are conflicting with your other dependencies.
  • Improvements based on ^2.5.0 pushed to the official repository you want merged here.

The remainder of this README is left untouched from 2.5.0, just as every other bit of documentation.

Rui Craveiro

README

Isar Database

QuickstartDocumentationSample AppsSupport & IdeasPub.dev

Isar [ee-zahr]:

  1. River in Bavaria, Germany.
  2. Database that will make your life easier.

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 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...

1. Add to pubspec.yaml

dependencies:
  isar: 2.5.0
  isar_flutter_libs: 2.5.0 # contains the binaries

dev_dependencies:
  isar_generator: 2.5.0
  build_runner: any

2. Annotate a Collection

part 'post.g.dart';

@Collection()
class Post {
  int id = Isar.autoIncrement;

  late String title;

  late DateTime date;
}

3. Open an instance

final dir = await getApplicationSupportDirectory(); // path_provider package
final isar = await Isar.open(
  schemas: [PostSchema],
  directory: dir.path,
  inspector: true, // if you want to enable the inspector for debug builds
);

4. Query the database

final posts = await isar.posts.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((isar) {
  newPost.id = await isar.posts.put(newPost); // insert & update
});

final existingPost = await isar.posts.get(newPost.id!); // get

await isar.writeTxn((isar) {
  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() and or() 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 {
    int? id;

    late String subject;

    @Backlink(to: 'teacher')
    final students = IsarLinks<Student>();
}

@Collection()
class Student {
    int? id;

    late String name;

    final teacher = IsarLink<Teacher>();
}

Watchers

With Isar, 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
})

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.

About

Isar version 2.5.0 maintenance mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 85.1%
  • C++ 6.6%
  • CMake 5.2%
  • Ruby 1.0%
  • HTML 0.9%
  • Swift 0.6%
  • Other 0.6%