Naomi itself is a singleton. It's what you get when you load "naomi" into Node.js, i.e.
var naomi = require('naomi');
Naomi is extensible. It allows registering external database engines to handle different database types, e.g.
var naomi = require('naomi');
var mysql = require('naomi-mysql');
naomi.register('mysql', mysql);
Once you have a database engine registered, you may use it to create a database instance, e.g.
var db = naomi.create('mysql', {
// connection properties
});
#register(identifier, engine)
Registers the supplied database engine under the designated identifier.
identifier
(string) database engine identifier, e.g. "mysql", "postgres".engine
(Class<Database>) a Naomi Database.
var naomi = require('naomi');
var mysql = require('naomi-mysql');
// register mysql database class under "foobar"
naomi.register('foobar', mysql);
The engine id is merely a string; you can call it whatever you want, e.g. "foobar" or "quux". It makes more sense, however, to name it according to the underlying database engine, e.g. "mysql" for MySQL.
Creates and returns a new Database instance of the designated engine.
identifier
(string) database engine identifier, e.g. "mysql", "postgres".connectionProperties
(Object) connection properties specific to the database engine (optional).
connectionProperties.database
(string) the name of the database schemaconnectionProperties.host
(string) the hostname of the database server (optional, defaults to "localhost")connectionProperties.port
(number) the port of the database server (optional, defaults to 3306)connectionProperties.user
(string) the user to access the database (optional, defaults to "root")connectionProperties.password
(string) ] the password to access the database (optional, defaults to "" - empty string)connectionProperties.connectionLimit
(number) maximum number of connections to maintain in the internal pool (optional, defaults to 10)
Returns a new Database instance.
var naomi = require('naomi');
var mysql = require('naomi-mysql');
naomi.register('mysql', mysql);
var db = naomi.create('mysql', {
host: process.env.MYSQL_HOST,
port: parseInt(process.env.MYSQL_PORT, 10),
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE
});
Alias of naomi#create().