773

0

Isar

Flutter 易于使用且完全异步的 NoSQL 数据库

Isar数据库

快速入门文档示例应用程序支持和想法Pub.dev

Isar [ee-zahr]:

  1. 德国巴伐利亚州的河流。
  2. 疯狂的快速 NoSQL 数据库,使用起来很愉快。

特征

  • 💙 为Flutter而生。易于使用,无需配置,无需样板
  • 🚀 高度可扩展天空是极限(双关语)
  • 🍭 功能丰富 。复合和多条目索引、查询修饰符、JSON 支持等。
  • 异步 。默认情况下并行查询操作和多隔离支持
  • 🦄 开源 。一切都是开源的,永远免费!

Isar 数据库可以做得更多(我们才刚刚开始)

  • 🕵️ 全文搜索 。让搜索快速有趣
  • 📱 多平台 。iOS、Android、桌面和完整的网络支持!
  • 🧪 酸语义 。依赖数据库一致性
  • 💃 静态typing 。编译时检查和自动完成的查询
  • 漂亮的文档 。易读、易于理解且不断改进

加入Telegram 组,讨论和抢先了解新版本的数据库。

如果您想说声谢谢,请在 GitHub 上为我们加注星标,并在 pub.dev 上为我们点赞🙌💙

快速开始

让我们开始使用最酷的 Flutter 数据库...

1.添加到pubspec.yaml

dependencies:
  isar: 3.0.0
  isar_flutter_libs: 3.0.0 # contains Isar Core

dev_dependencies:
  isar_generator: 3.0.0
  build_runner: any

2. 注释集合

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.打开一个数据库实例

final isar = await Isar.open([EmailSchema]);

4.查询数据库

final emails = await isar.emails.filter()
  .titleContains('awesome', caseSensitive: false)
  .sortByStatusDesc()
  .limit(10)
  .findAll();

Isar 数据库检查员

Isar Inspector允许您实时检查应用程序的 Isar 实例和集合。您可以执行查询、编辑属性、在实例之间切换以及对数据进行排序。

CRUD 操作

所有基本的 crud 操作都可以通过 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
});

数据库查询

Isar 数据库具有强大的查询语言,允许您使用索引、过滤不同的对象、使用复杂 and()or().xor()组、查询链接并对结果进行排序。

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()

数据库观察者

使用 Isar 数据库,您可以查看集合、对象或查询。在事务成功提交并且目标实际更改后,会通知观察者。观察者可以是惰性的并且不重新加载数据,或者它们可以是非惰性的并且在后台获取新结果。

Stream<void> collectionStream = isar.emails.watchLazy();

Stream<List<Post>> queryStream = importantEmails.watch();

queryStream.listen((newResult) {
  // do UI updates
})

基准

基准测试只能粗略了解数据库的性能,但如您所见,Isar NoSQL 数据库相当快😇

如果您对更多基准测试感兴趣或想检查 Isar 在您的设备上的表现,您可以自己运行基准测试

单元测试

如果您想在单元测试或 Dart 代码中使用 Isar 数据库,请 await Isar.initializeIsarCore(download: true)在测试中使用 Isar 之前调用。

Isar NoSQL 数据库将自动为您的平台下载正确的二进制文件。您还可以通过 libraries地图来调整每个平台的下载位置。

确保使用 flutter test -j 1以避免并行运行测试。这会破坏自动下载。

贡献者✨

非常感谢这些了不起的人:

~霜狐~ ~哈米德 H。~ ~捷通~ ~约阿希姆·诺尔~ ~莫斯科~ ~佩曼~ ~西蒙·莱尔~
~混合思维~

该数据库项目遵循所有贡献者规范。欢迎任何形式的贡献!

执照

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.