jaguar_mongo 2.2.0

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

jaguar_mongo

A MongoDB interceptor for Jaguar.

Usage

Creating the pool

Create an instance of MongoPool. Supply essential database configuration. By default, MongoPool builds on a SharedPool. Supply minPoolSize and maxPoolSize to control the pool size.

final mongoPool = MongoPool('mongodb://localhost:27017/test');

Getting and using connection

Use injectInterceptor method of MongoPool to get a connection to MongoDB. injectInterceptor automatically releases the connection after the request has been serviced or if an exception occurs.

  @GetJson()
  Future<List> readAll(Context ctx) async {
     Db db = await mongoPool.injectInterceptor(ctx); // Get [Db]
    // Use Db to fetch items
    return await (await db.collection('contact').find()).toList();
  }

Changelog

2.1.2

  • Simplified the example

2.1.1

  • Architecture
  • Introducing MongoPool

example/main.dart

library jaguar_mongo.example;

import 'dart:async';
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:mongo_dart/mongo_dart.dart';

import 'package:jaguar_mongo/jaguar_mongo.dart';

/// Mongo Pool
final mongoPool = MongoPool('mongodb://localhost:27018/test');

@Controller(path: '/contact')
class ContactApi {
  @GetJson()
  Future<List> readAll(Context ctx) async {
    Db db = await mongoPool.injectInterceptor(ctx); // Get [Db]
    // Use Db to fetch items
    return await (await db.collection('contact').find()).toList();
  }

  @PostJson()
  Future<List> add(Context ctx) async {
    Map body = await ctx.bodyAsJsonMap();
    Db db = await mongoPool.injectInterceptor(ctx);
    await db.collection('contact').insert(body);
    return await (await db.collection('contact').find()).toList();
  }
}

main(List<String> args) async {
  final server = Jaguar(port: 10000);
  server.add(reflect(ContactApi()));
  server.log.onRecord.listen(print);
  await server.serve(logRequests: true);
}

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_mongo: ^2.2.0

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:jaguar_mongo/jaguar_mongo.dart';
  
Version Uploaded Documentation Archive
2.2.0 Aug 15, 2018 Go to the documentation of jaguar_mongo 2.2.0 Download jaguar_mongo 2.2.0 archive
2.1.4 Aug 8, 2018 Go to the documentation of jaguar_mongo 2.1.4 Download jaguar_mongo 2.1.4 archive
2.1.2 Jul 8, 2018 Go to the documentation of jaguar_mongo 2.1.2 Download jaguar_mongo 2.1.2 archive
2.1.1 Jul 8, 2018 Go to the documentation of jaguar_mongo 2.1.1 Download jaguar_mongo 2.1.1 archive
1.3.1 Feb 2, 2018 Go to the documentation of jaguar_mongo 1.3.1 Download jaguar_mongo 1.3.1 archive
1.2.14 Feb 1, 2018 Go to the documentation of jaguar_mongo 1.2.14 Download jaguar_mongo 1.2.14 archive
1.2.5 Jan 13, 2018 Go to the documentation of jaguar_mongo 1.2.5 Download jaguar_mongo 1.2.5 archive
1.1.5 Jan 11, 2018 Go to the documentation of jaguar_mongo 1.1.5 Download jaguar_mongo 1.1.5 archive
0.6.0 Nov 4, 2017 Go to the documentation of jaguar_mongo 0.6.0 Download jaguar_mongo 0.6.0 archive
0.5.1 Jul 9, 2017 Go to the documentation of jaguar_mongo 0.5.1 Download jaguar_mongo 0.5.1 archive

All 21 versions...

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

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

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, other

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

Suggestions

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
conn_pool ^2.1.6 2.1.6
jaguar ^2.2.4 2.2.5
mongo_dart ^0.3.2 0.3.3
Transitive dependencies
async 2.0.8
auth_header 2.1.2
bson 0.3.2
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
fixnum 0.10.8
http_server 0.9.8
jaguar_common 2.1.4
logging 0.11.3+2
mime 0.9.6+2
mongo_dart_query 0.3.2
more 1.10.1
path 1.6.2
path_tree 2.2.2
pool 1.3.6
stack_trace 1.9.3
typed_data 1.1.6
uuid 1.0.3
Dev dependencies
http any
jaguar_reflect ^2.2.0
jaguar_resty ^2.6.2
test ^1.3.0