5.3.5 Mynode

This class is used to generate and obtain information about sessions (Session objects). To create an instance, use the Node.js require() function with the driver name, like this:

var nosql = require("mysql-js");

ConnectionProperties can be used to retrieve or set the connection properties for a given session. You can obtain a complete set of of default connection properties for a given adapter using the ConnectionProperties constructor, shown here, with the name of the adapter (a string) used as the value of nameOrProperties:

ConnectionProperties(nameOrProperties);

You can also create your own ConnectionProperties object by supplying a list of property names and values to a new ConnectionProperties object in place of the adapter name. Then you can use this object to set the connection properties for a new session, as shown here:

  
var NdbConnectionProperties = {
  "implementation" : "ndb",

  "ndb_connectstring" : "localhost:1186",
  "database"          : "test",
  "mysql_user"        : "root",
  
  "ndb_connect_retries" : 4,
  "ndb_connect_delay"   : 5,
  "ndb_connect_verbose" : 0,
  
  "linger_on_close_msec": 500,
  "use_ndb_async_api"   : false,

  "ndb_session_pool_min" : 4,
  "ndb_session_pool_max" : 100,
};

var sharePath = '/usr/local/mysql/share/nodejs';      // path to share/nodejs
var nosql = require(sharePath);         
var dbProperties = nosql.ConnectionProperties(NdbConnectionProperties);  

It is also possible to obtain an object with the adapter's default connection properties, after which you can update a selected number of these properties, then use the modified object to set connection properties for the session, as shown here:

var sharePath = '/usr/local/mysql/share/nodejs';      // path to share/nodejs
var spi   = require(sharePath + "/Adapter/impl/SPI"); // under share/nodejs

var serviceProvider         = spi.getDBServiceProvider('ndb');
var NdbConnectionProperties = serviceProvider.getDefaultConnectionProperties();

NdbConnectionProperties.mysql_user = 'nodejs_user';
NdbConnectionProperties.database   = 'my_nodejs_db';

var dbProperties = nosql.ConnectionProperties(NdbConnectionProperties);

The ConnectionProperties object includes the following properties:

The TableMapping constructor is also visible as a top-level function. You can get the mapping either by name, or by using an existing mapping:

TableMapping(tableName);

TableMapping(tableMapping);
openSession(properties, mappings, Function(err, Session) callback);

Connect to the data source and get a Session in the callback function. This is equivalent to calling connect() (see later in this section), and then calling getSession() on the SessionFactory that is returned in the callback function.

Note

Executing this method could result in connections being made to many other nodes on the network, waiting for them to become ready, and making multiple requests to them. You should avoid opening new sessions unnecessarily for this reason.

The implementation member of the properties object determines the implementation of the Session.

If mappings is undefined, null, or an empty array, no mappings are loaded or validated. In this case, any required mappings are loaded and validated when needed during execution. If mappings contains a string or a constructor function, the metadata for the table (or mapped table) is loaded from the database and validated against the requirements of the mapping.

Multiple tables and constructors may be passed to openSession() as elements in an array.

connect(properties, mappings, Function(err, SessionFactory) callback);

Connect to the data source to obtain a SessionFactory in the callback function. In order to obtain a Session, you must then call getSession() on this SessionFactory, whose implementation is determined by the implementation member of the properties object.

If mappings is undefined, null, or an empty array, no mappings are loaded or validated. In this case, any required mappings are loaded and validated when needed. If mappings contains a string or a constructor function, the metadata for the table (or mapped table) is loaded from the database and validated against the requirements of the mapping.

Multiple tables and constructors may be passed as elements in an array.

Array getOpenSessionFactories()

Get an array of all the SessionFactory objects that have been created by this module.

Note

The following functions are part of the public API but are not intended for application use. They form part of the contract between Mynode and SessionFactory.

  • Connection()

  • getConnectionKey()

  • getConnection()

  • newConnection()

  • deleteFactory()