dart_mongo_lite 0.0.3+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

A library for Dart developers.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

A simple usage example:

void main() {
  var db = Database('resources/db');

  var dialogsCollection = db['dialogs'];
  var triggersCollection = db['triggers'];

  print('Dropped ${dialogsCollection.drop()} dialogs');
  print('Dropped ${triggersCollection.drop()} triggers');

  dialogsCollection.insertMany([
    {'dialog': 'Ciao!'},
    {'dialog': 'Salve!'}
  ]);
  triggersCollection.insertMany([
    {'trigger': 'Ciao'},
    {'trigger': 'Salve'}
  ]);

  var dialog = dialogsCollection.findOneAs((d) => Dialog.fromJson(d), filter: {'dialog': 'Ciao!'});
  print(dialog.dialog);

  var trigger = triggersCollection.findOneAs((t) => Trigger.fromJson(t), filter: {'trigger': 'Salve'});
  print(trigger.trigger);
}

0.0.1 #

  • Initial version, created by Kaikyu Lotus

0.0.2 #

  • Implemented updated and modify

0.0.3 #

  • Added a synchronization mechanism to load file changes before updating the file;
  • Minor fixes

0.0.3+1 #

  • Fixed a bug where update filter never matches

0.0.3+2 #

  • Removed disk sync since no one must edit the file manually Anyway since someone probably wants to do that, the sync() method can be called publicly.

0.0.3+3 #

  • Added delete

example/dart_mongo_lite_example.dart

import 'package:dart_mongo_lite/dart_mongo_lite.dart';

class Dialog {
  String dialog;
  String value;

  Dialog(this.dialog, this.value);

  factory Dialog.fromJson(Map<String, dynamic> json) {
    if (json == null) return null;
    return Dialog(json['dialog'], json['value']);
  }
}

class Trigger {
  String trigger;
  String value;

  Trigger(this.trigger, this.value);

  factory Trigger.fromJson(Map<String, dynamic> json) {
    if (json == null) return null;
    return Trigger(json['trigger'], json['value']);
  }
}

void main() {
  var db = Database('resources/db');

  var dialogsCollection = db['dialogs'];
  var triggersCollection = db['triggers'];

  print('Dropped ${dialogsCollection.drop()} dialogs');
  print('Dropped ${triggersCollection.drop()} triggers');

  dialogsCollection.insertMany([
    {'dialog': 'Ciao!', 'id': 1},
    {'dialog': 'Salve!', 'id': 0}
  ]);
  triggersCollection.insertMany([
    {'trigger': 'Ciao', 'id': 1},
    {'trigger': 'Salve', 'id': 0},
    {'trigger': 'Salve', 'id': 0}
  ]);

  var done = triggersCollection.modify({'id': 0}, {'trigger': 'Salveeee trigger!'});
  print(done ? 'Trigger updated!' : 'Trigger not updated...');

  done = dialogsCollection.modify({'id': 1}, {'dialog': 'Salveeee dialog!'});
  print(done ? 'Dialog updated!' : 'Dialog not updated...');

  var dialog = dialogsCollection.findOneAs((d) => Dialog.fromJson(d), filter: {'dialog': 'Salveeee dialog!'});
  print(dialog?.dialog);

  var trigger = triggersCollection.findOneAs((t) => Trigger.fromJson(t), filter: {'trigger': 'Salveeee trigger!'});
  print(trigger?.trigger);

  var ok = triggersCollection.delete({'id': 0});
  print(ok);
  print(triggersCollection.find());

}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_mongo_lite: ^0.0.3+3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


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

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

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:dart_mongo_lite/dart_mongo_lite.dartpackage:dart_mongo_lite/src/dart_mongo_lite_base.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:dart_mongo_lite/dart_mongo_lite.dartpackage:dart_mongo_lite/src/dart_mongo_lite_base.dartdart:io

Health suggestions

Format lib/dart_mongo_lite.dart.

Run dartfmt to format lib/dart_mongo_lite.dart.

Format lib/src/dart_mongo_lite_base.dart.

Run dartfmt to format lib/src/dart_mongo_lite_base.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0