Isar
Flutter 易于使用且完全异步的 NoSQL 数据库
快速入门• 文档• 示例应用程序• 支持和想法• Pub.dev
Isar [ee-zahr]:
- 德国巴伐利亚州的河流。
- 疯狂的快速 NoSQL 数据库,使用起来很愉快。
Isar 数据库可以做得更多(我们才刚刚开始)
加入Telegram 组,讨论和抢先了解新版本的数据库。
如果您想说声谢谢,请在 GitHub 上为我们加注星标,并在 pub.dev 上为我们点赞🙌💙
让我们开始使用最酷的 Flutter 数据库...
dependencies:
isar: 3.0.0
isar_flutter_libs: 3.0.0 # contains Isar Core
dev_dependencies:
isar_generator: 3.0.0
build_runner: any
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,
}
final isar = await Isar.open([EmailSchema]);
final emails = await isar.emails.filter()
.titleContains('awesome', caseSensitive: false)
.sortByStatusDesc()
.limit(10)
.findAll();
Isar Inspector允许您实时检查应用程序的 Isar 实例和集合。您可以执行查询、编辑属性、在实例之间切换以及对数据进行排序。
所有基本的 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.