패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.1+1

objectdb

Dart 및 Flutter용 지속 가능한 내장형 문서 기반 NoSQL 데이터베이스입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
171
좋아요
113
Pub 점수
130

패키지 설치

flutter pub add objectdb

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

ObjectDB는 Dart 및 Flutter 애플리케이션을 위한 지속 가능한 내장형 문서 기반 NoSQL 데이터베이스입니다. JSON과 유사한 문서를 사용하여 로컬 데이터 저장을 가능하게 하며 별도의 서버 없이 완전한 CRUD 작업을 지원합니다. 단순성과 성능을 위해 설계되어 모바일, 웹, 데스크톱 등 주요 모든 플랫폼에서 작동합니다. ObjectDB는 데이터 지속성과 스키마 진화를 자동으로 처리하므로 오프라인 우선 앱에 신뢰할 수 있는 로컬 저장소가 필요한 경우 이상적입니다.

사용 사례

  • 오프라인 우선 모바일 앱
  • Flutter 앱에서의 로컬 데이터 저장
  • 크로스 플랫폼 데이터 지속성
  • 로컬 데이터베이스를 사용한 프로토타이핑
  • 간단한 문서 기반 데이터 모델링

주요 기능

  • 임베디드 및 제로 구성
  • 모든 플러터 플랫폼을 지원합니다
  • JSON 유사 문서 저장
  • 자동 지속성
  • 스키마 없는 설계

적합한 대상

  • 경량 로컬 저장소를 찾는 개발자
  • 오프라인 기능이 필요한 앱
  • 외부 데이터베이스 종속성 회피 프로젝트
  • 빠른 프로토타이핑
  • 소규모에서 중규모 데이터 세트

고려 사항

  • 대규모 또는 고병렬 시나리오에 적합하지 않습니다
  • 완전한 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

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.