Manual Reference Source Test
import Database from 'pop-api/src/middleware/Database.js'
public class | source

Database

Class for setting up a database connection.

Test:

Constructor Summary

Public Constructor
public

constructor(PopApi: PopApi, options: Object)

Create a new Database object.

Member Summary

Public Members
public

The name of the database.

public

The port of the database.

public

The host of the server of the database.

public

The password of the database.

public

The username of the database.

Method Summary

Public Methods
public

Connection and configuration of the database.

public

Disconnect from the database.

public

exportFile(collection: string, outputFile: string): Promise<string, undefined>

Export a JSON file collection.

public

importFile(collection: string, jsonFile: string): Promise<string, undefined>

Import a JSON file collection.

Public Constructors

public constructor(PopApi: PopApi, options: Object) source

Create a new Database object.

Params:

NameTypeAttributeDescription
PopApi PopApi
  • nullable: false

The PopApi instance to bind the database to.

options Object
  • nullable: false

The options for the database.

options.database string
  • nullable: false

The arguments to be parsed by

options.hosts Array<string>
  • optional
  • default: ['localhost']
  • nullable: false

The hosts for the database connection.

options.dbPort number
  • optional
  • default: 27017
  • nullable: false

The port for the database connection.

options.username string
  • optional
  • nullable: true

The username for the database connection.

options.password string
  • optional
  • nullable: true

The password for the database connection.

Throw:

TypeError

'database' is a required option for the Database middleware!

Test:

Public Members

public database: string source

The name of the database. Default is the package name with the environment mode.

public dbPort: number source

The port of the database. Default is 27017.

public hosts: Array source

The host of the server of the database. Default is ['localhost'].

public password: string source

The password of the database. By default this is left empty.

public username: string source

The username of the database. By default this is left empty.

Public Methods

public connect(): Promise<undefined, Error> source

Connection and configuration of the database.

Return:

Promise<undefined, Error>

The promise to connect to the database.

Test:

public disconnect(): Promise<undefined, Error> source

Disconnect from the database.

Return:

Promise<undefined, Error>

The promise to disconnect from the database.

Test:

public exportFile(collection: string, outputFile: string): Promise<string, undefined> source

Export a JSON file collection.

Params:

NameTypeAttributeDescription
collection string
  • nullable: false

The collection to export.

outputFile string
  • nullable: false

The path of the output file of the export.

Return:

Promise<string, undefined>

The promise to export a collection.

Test:

public importFile(collection: string, jsonFile: string): Promise<string, undefined> source

Import a JSON file collection.

Params:

NameTypeAttributeDescription
collection string
  • nullable: false

The collection to import.

jsonFile string
  • nullable: false

The JSON file to import.

Return:

Promise<string, undefined>

The promise to import a collection.

Test: