connection_pool 0.1.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 63

Connection Pool

Build Status Pub version

A very simple generic connection pool.

Example: How to build a MongoDB connection pool, and use it in a Redstone.dart app

import 'package:redstone/server.dart' as app;
import 'package:connection_pool/connection_pool.dart';
import 'package:mongo_dart/mongo_dart.dart';

/**
 * A MongoDB connection pool
 *
 */
class MongoDbPool extends ConnectionPool<Db> {

  String uri;

  MongoDbPool(String this.uri, int poolSize) : super(poolSize);

  @override
  void closeConnection(Db conn) {
    conn.close();
  }

  @override
  Future<Db> openNewConnection() {
    var conn = new Db(uri);
    return conn.open().then((_) => conn);
  }
}

/**
 * Retrieve and release a connection from the pool.
 */
app.Interceptor(r'/.*')
dbInterceptor(MongoDbPool pool) {

  //get a connection
  pool.getConnection().then((managedConnection) {

    //save the connection in the attributes map
    app.request.attributes["conn"] = managedConnection.conn;

    app.chain.next(() {
      if (app.chain.error is ConnectionException) {
        //if a connection is lost, mark it as invalid, so the pool can reopen it
        //in the next request
        pool.releaseConnection(managedConnection, markAsInvalid: true);
      } else {
        //release the connection
        pool.releaseConnection(managedConnection);
      }
    });

  });
}

//To use a connection, just retrieve it from the attributes map
@app.Route('/service')
service(@app.Attr() Db conn) {
  ...
}


main() {

  app.setupConsoleLog();

  //create a connection pool
  var mongodbUri = "mongodb://localhost/database";
  var poolSize = 3;

  app.addModule(new Module()
    ..bind(MongoDbPool, toValue: new MongoDbPool(mongoDbUri, poolSize)));

  app.start();
}

##v0.1.2

  • Added changelog
  • Added release / close connection

##v0.1.0+2

  • Fix pubspec.yaml
  • Fix example

##v0.1.0

  • First release

1. Depend on it

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


dependencies:
  connection_pool: "^0.1.2"

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 packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:connection_pool/connection_pool.dart';
        
Version Uploaded Documentation Archive
0.1.2 Jul 30, 2016 Go to the documentation of connection_pool 0.1.2 Download connection_pool 0.1.2 archive
0.1.1 Jul 30, 2016 Go to the documentation of connection_pool 0.1.1 Download connection_pool 0.1.1 archive
0.1.0+2 May 31, 2014 Go to the documentation of connection_pool 0.1.0+2 Download connection_pool 0.1.0+2 archive
0.1.0+1 May 31, 2014 Go to the documentation of connection_pool 0.1.0+1 Download connection_pool 0.1.0+1 archive
0.1.0 May 31, 2014 Go to the documentation of connection_pool 0.1.0 Download connection_pool 0.1.0 archive

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:connection_pool/connection_pool.dart.

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.

  • 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.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use connection_pool.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.4.0 <2.0.0
Dev dependencies
test >=0.12.0 <0.13.0