.database()
Access:
public

This is the database manager class. With this class you can select the database driver, connect to the driver and get a specific database.

Summary

Name
Description
Closes the connection to the database.
Connects to the database.
Returns the specified database.
Changes the database driver.

Functions

.close()
Access:
public
Summary:
Closes the connection to the database.

This function lets you close the connection to the database. This is done to close unneeded connections to relieve stress, since they are a pretty expensive resource. The function will return a promise that is called when the database has been closed.

Examples

cerus.database("test").close();
// -> closes the connection to the database

Returns

Type
Promise
Description
This function returns a promise.
.connect(domain, [options])
Access:
public
Summary:
Connects to the database.

This function lets the driver connect to the database. How the driver connects to the database depends on the driver. If your connecting to a local database, often you can use "localhost" as domain to connect. This function returns a promise that will continue depending on the events returned by the driver.

Parameters

Name
Type
Description
domain
String
The domain to connect to.
[options]
Object

Examples

cerus.database().connect("localhost");
// -> connects to the database at localhost

Returns

Type
Promise
Description
This function returns a promise.
.database(name)
Access:
public
Summary:
Returns the specified database.

This function will return the specified database. Read more about databases {@link database.database.constructor here}.

Parameters

Name
Type
Description
name
String
The name of the database to return.

Returns

Type
Class
Description
The database class.
.driver(name)
Access:
public
Summary:
Changes the database driver.

With this function you can select the driver the database manager will use. The driver is the module that is used to interact with the database. This module depends on what you're using, like MySQL or MongoDB. The function will automatically load the driver and if the driver is unknown it will throw an error.

Parameters

Name
Type
Description
name
String
The name of the driver.