From c82febdf327ebe71017b4736732f2994d5e7f928 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Mon, 20 Feb 2017 11:00:42 -0500 Subject: [PATCH] 1.1.1 --- README.md | 9 +++++---- lib/mongo_service.dart | 17 ++++++++++++++++- pubspec.yaml | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3cb4fe3..a15029d8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_mongo -[![version 1.1.0](https://img.shields.io/badge/pub-1.1.0-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo) +[![version 1.1.1](https://img.shields.io/badge/pub-1.1.1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo) [![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master)](https://travis-ci.org/angel-dart/mongo) MongoDB-enabled services for the Angel framework. @@ -10,14 +10,15 @@ Add the following to your `pubspec.yaml`: ```yaml dependencies: - angel_mongo: ^1.0.0-dev + angel_mongo: ^1.0.0 ``` # Usage -This library exposes three main classes: `Model`, `MongoService` and `MongoTypedService`. +This library exposes two main classes: `MongoService` and `MongoTypedService`. ## Model -`Model` is class with no real functionality; however, it represents a basic MongoDB document, and your services should host inherited classes. +`Model` is class with no real functionality; however, it represents a basic document, and your services should host inherited classes. +Other Angel service providers host `Model` as well, so you will easily be able to modify your application if you ever switch databases. ```dart class User extends Model { diff --git a/lib/mongo_service.dart b/lib/mongo_service.dart index b8a8219c..6874c3d1 100644 --- a/lib/mongo_service.dart +++ b/lib/mongo_service.dart @@ -3,9 +3,16 @@ part of angel_mongo.services; /// Manipulates data from MongoDB as Maps. class MongoService extends Service { DbCollection collection; + + /// If set to `true`, clients can remove all items by passing a `null` `id` to `remove`. + /// + /// `false` by default. + final bool allowRemoveAll; final bool debug; - MongoService(DbCollection this.collection, {this.debug: true}) : super(); + MongoService(DbCollection this.collection, + {this.allowRemoveAll: false, this.debug: true}) + : super(); _jsonify(Map doc, [Map params]) { Map result = {}; @@ -110,6 +117,14 @@ class MongoService extends Service { @override Future remove(id, [Map params]) async { + if (id == null || + id == 'null' && + (allowRemoveAll == true || + params?.containsKey('provider') != true)) { + await collection.remove(null); + return {}; + } + var result = await read(id, params); try { diff --git a/pubspec.yaml b/pubspec.yaml index ba351e7c..e1b8d031 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_mongo -version: 1.1.0 +version: 1.1.1 description: MongoDB-enabled services for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_mongo