API Docs for:
Show:

dbconn Class

Module: dbconn

Provides the database functionalities.

Methods

config

(
  • path
)

Sets the log level used to debug the sequelize library.

Parameters:

  • path String

    The file path of the static JSON configuration file.

configDbStatic

(
  • dirPath
)

Sets the static configurations to be use by database connections.f

Parameters:

  • dirPath String

    The directory path of the static JSON configuration files.

emit

(
  • ev
  • data
)

Emit an event. It's the same of nodejs events.EventEmitter.emit method.

Parameters:

  • ev String

    The name of the event

  • data Object

    The object to be emitted

getDbConfigCustCardData

(
  • The
)

Returns the configurations of customer cards.

Parameters:

  • The Return

    configurations of customer cards.

getMssqlTdsVersion

(
  • type
)
String private

Returns the TDS version for MSSQL from the database type configuration. The type has the format "mssql:TDS_VERSION", for example "mssql:7_4".

Parameters:

  • type String

    The database type expressed in the configuration file

Returns:

String:

The TDS version to be used for connection.

getStats

() Object

Returns the statistics.

Returns:

Object:

The statistics.

importModels

() private

Load all sequelize models that are present in the default directory as a file, one for each model. This method must be called after initConnections method.

incNumExecQueries

()

Increment the number of executed queries by one unit.

initConnections

() private

Initialize all database connections.

initCustCardConnections

() private

Initialize all database connections for customer cards.

initCustCardData

(
  • cb
)
private

Read database connection data for customer cards.

Parameters:

  • cb Function

    The callback function

initMssqlConn

(
  • name
  • tdsVersion
)
private

Initialize an MSSQL connection.

Parameters:

  • name String

    The customer card name

  • tdsVersion String

    The TDS version to be used in connection

initMssqlConnCustCard

(
  • data
  • tdsVersion
)
private

Initialize an MSSQL connection.

Parameters:

  • data Object

    The db connection data

    • id Number

      The db connection identifier

    • host String

      The db host

    • port Number

      The db port

    • type String

      The db type

    • user String

      The db username

    • pass String

      The db password

    • name String

      The db name

  • tdsVersion String

    The TDS version to be used in connection

initPostgresConn

(
  • name
)
private

Initialize a Postgres connection.

Parameters:

  • name String

    The customer card name

initPostgresConnCustCard

(
  • data
)
private

Initialize a Postgres connection for customer card.

Parameters:

  • data Object

    The db connection data

    • id Number

      The db connection identifier

    • host String

      The db host

    • port Number

      The db port

    • type String

      The db type

    • user String

      The db username

    • pass String

      The db password

    • name String

      The db name

isMssqlType

(
  • type
)
Boolean private

Checks if the configuration database type is MSSQL. When it is true, the type has the format "mssql:TDS_VERSION", for example "mssql:7_4".

Parameters:

  • type String

    The database type expressed in the configuration file

Returns:

Boolean:

True if the type is MSSQL.

on

(
  • type
  • cb
)
Object

Subscribe a callback function to a custom event fired by this object. It's the same of nodejs events.EventEmitter.on method.

Parameters:

  • type String

    The name of the event

  • cb Function

    The callback to execute in response to the event

Returns:

Object:

A subscription handle capable of detaching that subscription.

readCustomerCard

(
  • cb
)
private

Read "customer_card" table with all information about the customer cards: the name, the source db connection identifier, the query...

Parameters:

  • cb Function

    The callback function

reset

()

Reset the component.

setLogger

(
  • log
)
static

Set the logger to be used.

Parameters:

  • log Object

    The logger object. It must have at least three methods: info, warn and error as console object.

setReady

() private

set the component as ready.

testConnection

(
  • host
  • port
  • type
  • user
  • pass
  • name
  • cb
)

Test a connection with a database.

Parameters:

  • host String

    The host to connect to.

  • port String

    The port of the database service.

  • type String

    The DBMS type (sql, postgres, mssql, ...).

  • user String

    The username for the db connection.

  • pass String

    The password for the db connection.

  • name String

    The name of the database.

  • cb Function

    The callback function.

Properties

config

Object private

The configurations to be used by database connections.

Default: {}

custCardTemplatesData

Object private

The customer card templates data.

Default: {}

dbConfigCustCardData

Object private

The configurations to be used by database connections for customer cards.

Default: {}

dbConn

Object private

The database connections.

Default: {}

dbConnCustCard

Object private

The database connections for customer cards.

Default: {}

emitter

Object private

The event emitter.

EVT_READY

String

The name of the ready event.

Default: "ready"

EVT_RELOADED

String

The name of the reloaded event.

Default: "reloaded"

IDLOG

String private final

The module identifier used by the logger.

Default: [dbconn]

JSON_KEYS

Object private

The key names of the JSON files that contains database connection information.

Default: { CEL: "cel", POSTIT: "postit", OFFHOUR: "offhour", AMPUSERS: "ampusers", INCOMING: "incoming", VOICEMAIL: "voicemail", PHONEBOOK: "phonebook", QUEUE_LOG: "queue_log", REST_USERS: "rest_users", SMS_HISTORY: "sms_history", CALLER_NOTE: "caller_note", QUEUE_RECALL: "queue_recall", HISTORY_CALL: "history_call", OFFHOUR_FILES: "offhour_files", CTI_PHONEBOOK: "cti_phonebook", USER_SETTINGS: "user_settings", USERMAN_USERS: "userman_users", REST_CTI_PROFILES_PARAMURL: "rest_cti_profiles_paramurl" }

logger

Object private

The logger. It must have at least three methods: info, warn and error.

Default: console

logSequelize

Boolean private

True if the sequelize library will be logged. It is customized by the config method.

Default: false

models

Object private

It contains the sequelize models.

Default: {}

numExecQueries

Number private

The number of executed queries.

Default: 0

ready

Boolean private

True if the component has been started. Used to emit EVT_RELOADED instead of EVT_READY

Default: false

Events

ready

Fired when the component is ready.

reloaded

Fired when the component has been reloaded.