new Manager(opts)
A manager instance acts as an entry point for a group of data collections.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
opts |
object |
<optional> |
Deprecated: Use configure method to setup the instance. |
- Source:
Members
-
addReplicaSet
-
Creates new replica set.
- Source:
-
collections
-
An array containing all established data collections. Individual collections may be connected to different data stores.
- Source:
-
connections
-
A collection of predefined data store (database) connections.
- Source:
-
defaultConnection
-
Specifies the default connection for this instance. The default value is
"fs-default"
.- Source:
-
schema
-
A collection of data, index and mapping definitions. Definitions are optional in most cases.
- Source:
Methods
-
addCollection(name, connection, interceptors, schema, done) → {Manger}
-
Creates new data colledtion and adds it to this instance.
Parameters:
Name Type Argument Description name
string The name of the data collection. The name must be unique within a Manger instance.
connection
string <optional>
Specifies which connection should the collection use to store and retrieve data. If omitted the default connection will be used.
interceptors
Array <optional>
An array of interceptor function to attach to this collection.
schema
string | object <optional>
The name of a predefined schema for this colleciton or an object representing the data schema.
done
function <optional>
Optional callback that will be called when the collection is initialized.
- Source:
Returns:
- This instance.
- Type
- Manger
-
addConnection(name, provider, opts) → {Manger}
-
Adds new data sotre connection for this instance. Each connection represents a connection to a database or data storage service with specific configuration (options).
Every manager instance has one pre-initialized default connection with the following parameters:
- name: "fs-defalut"
- provider: "file-system"
- connection string: "./data" - the path is relative to the
process.cwd()
The default connection can be changed:
entree.defaultConnection = "mongo-default";
Parameters:
Name Type Description name
string The name of the connection. The name must be unique within a Manger instance.
provider
string This could be the name of a built-in data provider, e.g.
file-system
,mongodb
and etc., orrequire
module implementing custom provider.opts
string | object The configuration information for initializing data provider instances. If this argument is string, it is assumed to be a connection string. This argument is required and at least connection string must be present.
- Source:
Returns:
- This instance.
- Type
- Manger
Example
var entree = require("entree"); entree.addConnection("fs-default", "file-system", "./data"); entree.addConnection("mongo-default", "mongodb", "mongodb://localhost/entreeTest"); entree.addConnection("mongo-2", "mongodb", { connStr: "mongodb://191.168.0.100/node2" }); entree.addConnection("everlive", "everlive", { connStr: "http://api.everlive.com/v1/uZEGyZYKiSq5CTSq/", authorization: "MasterKey PqmmvlWWBF8svReW8p3mkYG9X61nus1w" });
-
addProvider(provider, name, done) → {Manger}
-
Does the same as addCollection method, but it accepts data provider instance instead of configuration.
Parameters:
Name Type Argument Description provider
Provider An instance of Provider class.
name
string The name of the data collection. The name must be unique within a Manger instance.
done
function <optional>
Optional callback that will be called when the collection is initialized.
- Source:
Returns:
- This instance.
- Type
- Manger
-
configure(opts, callback)
-
Sets up the entire infrastructure for the current Entree instance. That includes database connections, data collections, data schemas, interceptors, replica sets and shards. The configuration information can be provided either as an object argument for this method or a configuration document (file) in JSON format. For full description of the configuration format please see the Configuration tutorial.
If the
opts
argument is omitted, Entree will try to find "data-model" document in the Default Config Collection. By convention "data-model" is the default configuration file for Entree. There may be additional configuration documents as described in the Default Config Collection tutorial.This method may be called multiple times; in which case all non-overlapping settings will be appended and overlapping ones will be merged.
Parameters:
Name Type Argument Description opts
object <optional>
Object containing configuration information and additional options.
callback
function <optional>
An optional callback that will be called after the configuration is processed and all connections are initialized.
- Source:
-
createContext(context) → {Context}
-
Creates a context object that is passed as the first argument in action methods such as insert, update, select and etc. This function just wraps the original context that is passed as an argument. The wrapper is needed to properly distinguish the context from the rest of the arguments.
Execution context is used to pass arguments to interceptors and shards. For instance, authorization interceptor will require an
user
object in the context to determine the rights of the caller for the current operation.Parameters:
Name Type Description context
object The actual context.
- Source:
Returns:
- The context for the current execution;
- Type
- Context
Example
var entree = require("entree"); app.post("/items", function (req, res) { var context = entree.createContext(req.user); entree.items.insert(context, req.body, function (err, result) { if (err) { res.statusCode = 500; return res.send(err.message); } res.send(JSON.stringify(result)); }); });
-
dispose(done) → {null}
-
Closes all opened database connections, clears current state and cached data if any. The manager instance can no longer be used after dispose.
Parameters:
Name Type Description done
function An optional callback that will be called after the manager is disposed.
- Source:
Returns:
- Type
- null
-
init()
-
Alias to configure method.
- Source:
-
removeCollection(name) → {Manger}
-
Removes the specified data collection from this instance.
Parameters:
Name Type Description name
string The name of the collection to remove.
- Source:
Throws:
Will throw an error if the specified collection does not exist.Returns:
- This instance.
- Type
- Manger
-
removeConnection(name) → {Manger}
-
Removes the specified connection form this instance.
Parameters:
Name Type Description name
string The name of the connecton to remove.
- Source:
Returns:
- This instance.
- Type
- Manger
-
resolveInterceptor(name) → {module}
-
Resolves and loads the specified interception module.
Parameters:
Name Type Description name
string The name of a built-in interceptor or path to a custom interception module.
- Source:
Returns:
- An instance of interception module.
- Type
- module
Example
var entree = require("entree"), cache = enree.resolveInterceptor("cache"), stores = [ { store: "memory", max: 1000, ttl: 10 }, { store: "redis", db: 0, ttl: 100 } ], caching = cache.interception(stores, ["get", "select"]); entree.addCollection("users", [caching]); // or add interceptor at later stage entree.users.use(caching);
-
resolveProvider(name) → {Provider}
-
Resolves and loads the specified data provider type.
Parameters:
Name Type Description name
string The name of a built-in data provider or path to a custom provider module.
- Source:
Returns:
- An instance of the specified data provider.
- Type
- Provider
-
setCollections(name) → {FluentContext}
-
Configures a set of data collections using fluent interface.
Parameters:
Name Type Description name
stirng The name of the first data collection in the set.
- Source:
Returns:
- Type
- FluentContext
Example
manager .setCollections("users") .setConnection("mongo-default") .setSchema({ __name__: "user", name: String, age: Number, roles: Array }) .use(logging) .use(caching) .addCollection("comments") .setConnection("mongo-hq") .use(caching) .done(function (err) { // collections are ready to be used });