objectdb 0.1.10

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new85

ObjectDB

Pub license GitHub stars

Persistent embedded document-oriented NoSQL database for Dart and Flutter. 100% Dart.

CAUTION This plugin is still in development. Use at your own risk. 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(path);
db.open();

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

// delete documents
db.delete({'active': false});

// search documents in database
var result = await db.find({'active': true, 'name.first': 'Some'});

// 'tidy up' the db file
db.tidy();

// close db
await db.close();

Flutter

Check out this project for flutter-examples.

Methods

  • Future<ObjectDB> db.open([bool tidy = true]) opens database
  • Future<void> db.tidy() 'tidy up' 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)

delete

  • Future<int> db.delete(Map query) delete documents that match query

Query

// Match fields in subdocuments
{Op.gte: {
    'birthday.year': 18
}}

// or-operator
{Op.or:{
    'active': true,
    Op.inArray: {'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

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

Todo's

  • [x] regex match
  • [ ] encryption
  • [ ] querying arrays
  • [ ] benchmarks
  • [ ] indexing

License

See License

[0.0.1] - 2018-06-25

  • Initial release

[0.0.4] - 2018-06-25

  • Async bugfix

[0.0.6] - 2018-06-26

  • BREAKING CHANGE: make db path required parameter

[0.0.7] - 2018-06-26

  • Remove flutter dependency

[0.0.8] - 2018-06-26

  • Added ObjectId as unique _id value
  • Added methods: insertMany(), first() and last()

[0.0.9] - 2018-06-26

  • BREAKING CHANGE: Rename clean() to tidy()

[0.0.10] - 2018-06-27

  • insert() -> return object id
  • query examples in README

[0.0.11] - 2018-06-27

  • added example

[0.0.12] - 2018-06-27

  • async bugfix

[0.1.0] - 2018-06-30

  • updated docs

[0.1.1] - 2018-06-30

  • updated execution_queue

[0.1.2] - 2018-06-30

  • regex support
  • db meta

[0.1.6] - 2018-07-02

  • advanced return types

example/main.dart

import 'package:objectdb/objectdb.dart';

void main() async {
  // open db
  var db = ObjectDB('/some/path/to/file.db');
  db.open();

  // insert documents
  await db.insertMany([
    {
      "name": {"first": "Maria", "last": "Smith"},
      "age": 20,
      "active": false
    },
    {
      "name": {"first": "James", "last": "Jones"},
      "age": 32,
      "active": false
    },
  ]);

  // update documents
  db.update({"name.first": "Maria"}, {"active": true});

  // remove documents
  db.remove({
    Op.inList: {
      "name.last": ["Jones", "Miller", "Wilson"]
    },
    "active": false,
  });

  // find documents
  print(await db.find({
    Op.lte: {"age": 30}
  }));

  // close db
  await db.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  objectdb: "^0.1.10"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:objectdb/objectdb.dart';
  
Version Uploaded Documentation Archive
0.1.10 Jul 4, 2018 Go to the documentation of objectdb 0.1.10 Download objectdb 0.1.10 archive
0.1.9 Jul 2, 2018 Go to the documentation of objectdb 0.1.9 Download objectdb 0.1.9 archive
0.1.8 Jul 2, 2018 Go to the documentation of objectdb 0.1.8 Download objectdb 0.1.8 archive
0.1.7 Jul 2, 2018 Go to the documentation of objectdb 0.1.7 Download objectdb 0.1.7 archive
0.1.6 Jul 2, 2018 Go to the documentation of objectdb 0.1.6 Download objectdb 0.1.6 archive
0.1.5 Jul 1, 2018 Go to the documentation of objectdb 0.1.5 Download objectdb 0.1.5 archive
0.1.4 Jul 1, 2018 Go to the documentation of objectdb 0.1.4 Download objectdb 0.1.4 archive
0.1.3 Jun 30, 2018 Go to the documentation of objectdb 0.1.3 Download objectdb 0.1.3 archive
0.1.2 Jun 30, 2018 Go to the documentation of objectdb 0.1.2 Download objectdb 0.1.2 archive
0.1.1 Jun 30, 2018 Go to the documentation of objectdb 0.1.1 Download objectdb 0.1.1 archive

All 23 versions...

Analysis

We analyzed this package on Jul 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
71 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
85
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

Primary library: package:objectdb/objectdb.dart with components: io.

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/objectdb.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.1.2 <2.0.0
bson_objectid ^0.1.0 0.1.0
execution_queue ^0.1.3 0.1.3
Dev dependencies
test any