搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.1+1

objectdb

適用於 Dart 和 Flutter 的持久嵌入式文件導向 NoSQL 資料庫。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
167
喜歡數
113
Pub 分數
130

安裝套件

flutter pub add objectdb

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

ObjectDB 是一個持久化、嵌入式的文件導向 NoSQL 資料庫,專為 Dart 和 Flutter 應用程式設計。它支援使用類似 JSON 的文件進行本機資料儲存,並提供完整的 CRUD 操作,無需額外的伺服器。專為簡單性與效能打造,可在所有主要平台(包括行動裝置、網頁和桌面)上運作。ObjectDB 自動處理資料持久化與結構演進,非常適合需要可靠本機儲存的離線優先應用程式。

適用情境

  • 離線優先的行動應用
  • Flutter 應用中的本機資料儲存
  • 跨平台資料持久化
  • 使用本地資料庫進行原型設計
  • 簡單的基於文件的數據建模

主要特色

  • 嵌入式和零設定
  • 支援所有 Flutter 平台
  • JSON-like文件儲存
  • 自動持久化
  • 無模式設計

適合對象

  • 尋求輕量級本機儲存的開發者
  • 需要離線功能的應用
  • 專案避免外部資料庫依賴
  • 快速原型設計
  • 中小型數據集

使用建議

  • 不適用於大規模或高併發場景
  • 與完整SQL資料庫相比,查詢功能有限
  • 無內建的遠端伺服器同步功能
  • 最適合單裝置使用情境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

ObjectDB

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.

How to use

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

Storage types

// 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);

Flutter

Check out the example project.

Methods

  • Future<void> db.cleanup() cleanup the db file
  • Future<void> db.close() closes database (should be awaited to ensure all queries have been executed)
find
  • Future<List<Map>> db.find(Map query) List with all matched documents
  • Future<Map> db.first(Map query) first matched document
  • Future<Map> db.last(Map query) last matched document
insert
  • Future<ObjectId> db.insert(Map document) insert single document
  • Future<List<ObjectId>> db.insertMany(List<Map> documents) insert many documents
update
  • Future<int> db.update(Map query, Map changes, [bool replace = false]) update documents that mach query with changes (optionally replace whole document)
remove
  • Future<int> db.remove(Map query) remove documents that match query

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.

Operators

Logical
  • and (default operator on first level)
  • or
  • not
Comparison
  • lt, lte: less than, less than or equal
  • gt, gte: greater than, greater than or equal
  • inList, notInList: value in list, value not in list
Modify
  • set: set value
  • max, min: set max or min int value
  • increment, multiply: increment/multiply by
  • unset: unset key/value
  • rename: rename key
  • todo: push / 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},
});
Examples
// 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));

License

See License

所屬分類

依賴

依賴清單 3 項

  • deeply^1.2.0+1
  • execution_queue^1.2.0
  • objectid^2.0.0

原始碼儲存庫

使用此套件的專案

暫無相關資料。