v1.2.1+1
objectdb
適用於 Dart 和 Flutter 的持久嵌入式文件導向 NoSQL 資料庫。
113喜歡 131近 30 天下載130Pub 分數
AndroidiOSWebmacOSWindowsLinux
適用於 Dart 和 Flutter 的持久嵌入式文件導向 NoSQL 資料庫。
^1.2.0^1.2.0+1^2.0.0any^1.15.0^1.11.0以下為英文專案原文快照,最新內容請造訪 GitHub。
Pub license GitHub stars Tests
Persistent embedded document-oriented NoSQL database for Dart and Flutter. 100% Dart.
Check out objectdb_flutter for reactive store listeners.
If you notice any bugs you can create an issue on GitHub. You're also welcome to contribute using pull requests. Please open an issue before spending time on any pull request.
final path = Directory.current.path + '/my.db';
// create database instance and open
final db = ObjectDB(FileSystemStorage(path));
// insert document into database
db.insert({'name': {'first': 'Some', 'last': 'Body'}, 'age': 18, 'active': true});
db.insert({'name': {'first': 'Someone', 'last': 'Else'}, 'age': 25, 'active': false});
// update documents
db.update({Op.gte: {'age': 80}}, {'active': false});
// remove documents
db.remove({'active': false});
// search documents in database
var result = await db.find({'active': true, 'name.first': 'Some'});
// cleanup the db file
db.cleanup();
// close db
await db.close();
// Universal (non-persistent)
import 'package:objectdb/src/objectdb_storage_in_memory.dart';
InMemoryStorage();
// Persist on filesystem (Flutter Mobile & Desktop)
import 'package:objectdb/src/objectdb_storage_filesystem.dart';
FileSystemStorage();
// Persist in IndexedDB (Flutter Web)
import 'package:objectdb/src/objectdb_storage_indexeddb.dart';
IndexedDBStorage(dbName);
Check out the example project.
Future<void> db.cleanup() cleanup the db fileFuture<void> db.close() closes database (should be awaited to ensure all queries have been executed)Future<List<Map>> db.find(Map query) List with all matched documentsFuture<Map> db.first(Map query) first matched documentFuture<Map> db.last(Map query) last matched documentFuture<ObjectId> db.insert(Map document) insert single documentFuture<List<ObjectId>> db.insertMany(List<Map> documents) insert many documentsFuture<int> db.update(Map query, Map changes, [bool replace = false]) update documents that mach query with changes (optionally replace whole document)Future<int> db.remove(Map query) remove documents that match query// Match fields in subdocuments
{Op.gte: {
'birthday.year': 18
}}
// or-operator
{Op.or: {
'active': true,
Op.inList: {'group': ['admin', 'moderator']}
}}
// not equal to
{Op.not: {'active': false}}
NOTE Querying arrays is not supportet yet.
and (default operator on first level)ornotlt, lte: less than, less than or equalgt, gte: greater than, greater than or equalinList, notInList: value in list, value not in listset: set valuemax, min: set max or min int valueincrement, multiply: increment/multiply byunset: unset key/valuerename: rename keypush / pull{Op.set: {'path.to.key': 'value'}} // set entry['path']['to']['key'] = 'value' (path will be created if not exists)
{Op.max: {'path.to.key': 200}} // set value 200 if value is greater than 200
{Op.min: {'path.to.key': 200}} // set value 200 if value is smaller than 200
{Op.increment: {'path.to.key': -5}} // increment value by negative 5
{Op.multiply: {'path.to.key': 2}} // multiply value by 2
{Op.unset: {'path.to.key': true}} // unset key/value at entry['path']['to']['key'] if exists
{Op.rename: {'path.to.key': 'new_key'}} // new value will be at entry['path']['to']['new_key']
db.update({
'age': RegExp('[18-20]'),
Op.gt: {'duration': 500},
}, {
Op.max: {'stats.score': 100},
Op.increment: {'stats.level': -5},
});
// query
var result = db.find({
'active': true,
Op.or: {
Op.inList: {'state': ['Florida', 'Virginia', 'New Jersey']},
Op.gte: {'age': 30},
}
});
// same as
var match = (result['active'] == true && (['Florida', 'Virginia', 'New Jersey'].contains(result['state']) || result['age'] >= 30));
See License