1.1.1
This commit is contained in:
parent
627e954526
commit
c82febdf32
3 changed files with 22 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_mongo
|
# 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)
|
[![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.
|
MongoDB-enabled services for the Angel framework.
|
||||||
|
@ -10,14 +10,15 @@ Add the following to your `pubspec.yaml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_mongo: ^1.0.0-dev
|
angel_mongo: ^1.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
This library exposes three main classes: `Model`, `MongoService` and `MongoTypedService<T>`.
|
This library exposes two main classes: `MongoService` and `MongoTypedService<T>`.
|
||||||
|
|
||||||
## Model
|
## 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
|
```dart
|
||||||
class User extends Model {
|
class User extends Model {
|
||||||
|
|
|
@ -3,9 +3,16 @@ part of angel_mongo.services;
|
||||||
/// Manipulates data from MongoDB as Maps.
|
/// Manipulates data from MongoDB as Maps.
|
||||||
class MongoService extends Service {
|
class MongoService extends Service {
|
||||||
DbCollection collection;
|
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;
|
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]) {
|
_jsonify(Map doc, [Map params]) {
|
||||||
Map result = {};
|
Map result = {};
|
||||||
|
@ -110,6 +117,14 @@ class MongoService extends Service {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future remove(id, [Map params]) async {
|
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);
|
var result = await read(id, params);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_mongo
|
name: angel_mongo
|
||||||
version: 1.1.0
|
version: 1.1.1
|
||||||
description: MongoDB-enabled services for the Angel framework.
|
description: MongoDB-enabled services for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_mongo
|
homepage: https://github.com/angel-dart/angel_mongo
|
||||||
|
|
Loading…
Reference in a new issue