Manager

Manager

The database(s) manager entry point that autogenerates/manages SQL execution functions from underlying SQL statement files. Vendor-specific implementations should implement typedefs.Dialect and pass the class or module path into the constructor as conf.db.dialects.myDialectClassOrModulePath. See README.md for more details about SQL related features. A manager will contain the following properties:

  • db - The database accessible object where all of the constructed connections reside. For example
  • db.<CONN_NAME> - There will be a property assigned for each database connection configured during construction. For example, when <CONN_NAME> is myConn, the manager instance will be accessible via manager.db.myConn.
  • db.<CONN_NAME>.<PREPARED_FUNC_PATHS> The generated SQL executable typedefs.SQLERPreparedFunction(s). Assuming a <CONN_NAME> of myConn and a path of /db/myConn/read.my.table.sql, the accessible typedefs.SQLERPreparedFunction may be accessible via db.myConn.read.my.table().
  • db.<CONN_NAME>.beginTransaction - A function that accepts a single typedefs.SQLERTransactionOptions that begins a transaction for a given database connection pool.

Constructor

new Manager(conf, cacheopt, loggingopt)

Creates a new database manager. Vendor-specific implementations should have constructors that accept properties defined by typedefs.Dialect.

Source:
Parameters:
Name Type Attributes Description
conf typedefs.SQLERConfigurationOptions

The configuration options

cache typedefs.SQLERCache <optional>

the typedefs.SQLERCache like instance that will handle the logevity of the SQL statement before the SQL statement is re-read from the SQL file

logging function | Boolean <optional>

the function(dbNames) that will return a name/dialect specific function(obj1OrMsg [, obj2OrSubst1, ..., obj2OrSubstN])) that will handle database logging. Pass true to use the console. Omit to disable logging altogether.

Members

(static) OPERATION_TYPES

Source:

(static) POSITIONAL_BINDS_REGEXP

Source:

Methods

(static) namedBindSequence(sql, count) → {Array.<String>}

Duplicates a SQL statement by sequentially incrementing named bind parameters by appending an increacing numeric count to each bind parameter

Source:
Parameters:
Name Type Description
sql String

The SQL statement that contains the bind names that will be sequenced

count Integer

The total number of duplicates to make

Returns:
Type:
Array.<String>

The SQL statements that have been duplicated with sequentially numeric suffixes

Example
Manager.namedBindSequence('SELECT * FROM EXAMPLE X WHERE X.A = :a AND X.B = :b AND X.C = :c', 2);
// produces:
[
  'SELECT * FROM EXAMPLE X WHERE X.A = :a1 AND X.B = :b1 AND X.C = :c1',
  'SELECT * FROM EXAMPLE X WHERE X.A = :a2 AND X.B = :b2 AND X.C = :c2'
]

(async) addConnection(conn, privopt, cacheopt, loggingopt, returnErrorsopt) → {typedefs.SQLEROperationResults}

Adds a connection configuration to the manager and initializes the database connection

Source:
Parameters:
Name Type Attributes Description
conn typedefs.SQLERConnectionOptions

The connection options that will be added to the manager

priv typedefs.SQLERPrivateOptions <optional>

The private options that contain the connection credentials that should match priv[conn.id]. When omitted, an attempt to use the private options passed into the constructor to make a privPassedIntoConstructor[conn.id] match.

cache typedefs.SQLERCache <optional>

the typedefs.SQLERCache like instance that will handle the logevity of the SQL statement before the SQL statement is re-read from the SQL file

logging function | Boolean <optional>

the function(dbNames) that will return a name/dialect specific function(obj1OrMsg [, obj2OrSubst1, ..., obj2OrSubstN])) that will handle database logging. Pass true to use the console. Omit to disable logging altogether.

returnErrors Boolean <optional>

Truthy to return errors, otherwise, any encountered errors will be thrown

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the truthy result from the dialect initialization for the given connection (or the errors when return errors flag is set)

(async) close() → {typedefs.SQLEROperationResults}

Closes all database pools/connections/etc.

Source:
Returns:
Type:
typedefs.SQLEROperationResults

The results

generateCacheKey(dialect, connName, methodName, ext) → {String}

Generates a key used for caching SQL methods

Source:
Parameters:
Name Type Description
dialect String

The database dialect

connName String

The connection name

methodName String

The SQL method name

ext String

The SQL file extension

Returns:
Type:
String

The key used for caching

(async) getCacheKey(path, connName) → {String}

Gets a cache key for a given absolute path to an SQL file

Source:
Parameters:
Name Type Description
path String

The absolute path to the SQL file

connName String

The connection name to get the cache key for

Returns:
Type:
String

The cache key for the given path

(async) init(returnErrorsopt) → {typedefs.SQLEROperationResults}

Initializes the configured database connections

Source:
Parameters:
Name Type Attributes Description
returnErrors Boolean <optional>

Truthy to return errors, otherwise, any encountered errors will be thrown

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the truthy result from the dialect initialization for the given connection (or the errors when return errors flag is set)

(async) preparedFunctionCount(…connNamesopt) → {typedefs.SQLEROperationResults}

Gets the number of prepared SQL functions on either all the connections used by the manager or on the specified connection names.

Source:
Parameters:
Name Type Attributes Description
connNames String <optional>
<repeatable>

The connection names to perform the check on (defaults to all connections)

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the number of generated prepared SQL functions for the given connection

(async) scan(removeOrphansopt, …connNames) → {typedefs.SQLEROperationResults}

Scans directories/subdirectories for SQL files and generates prepared functions on either all the connections used by the manager or on the specified connection names.

Source:
Parameters:
Name Type Attributes Default Description
removeOrphans Boolean <optional>
true

Truthy to remove orphaned prepared functions that no longer have an SQL file associated with them

connNames String <repeatable>

The connection names to scan for SQL files for when generating prepared functions

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the number of SQL prepared functions for the given connection

(async) setCache(cacheopt, isTransferopt, …connNames) → {typedefs.SQLEROperationResults}

Sets the caching mechanism that will be used that will determine the frequency of reading SQL source files. Omit the connection names to set the cache on all connections used by the manager.

Source:
Parameters:
Name Type Attributes Description
cache typedefs.SQLERCache <optional>

the typedefs.SQLERCache like instance that will handle the logevity of the SQL statement before the SQL statement is re-read from the SQL file

isTransfer Boolean <optional>

Truthy when the passed cache is present and any existing SQL (either cached or non-cached) should be transferred to it (if any)

connNames String <repeatable>

The connection names to set the cache for

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the number of cached keys transferred for the given connection

(async) state(optsopt, …connNamesopt) → {typedefs.SQLEROperationResults}

Composes the typedefs.SQLERState on either all the connections used by the manager or on the specified connection names.

Source:
Parameters:
Name Type Attributes Description
opts typedefs.SQLEROperationOptions <optional>

The typedefs.SQLEROperationOptions to use

connNames String <optional>
<repeatable>

The connection names to perform the check on (defaults to all connections)

Returns:
Type:
typedefs.SQLEROperationResults

The results, each result[connectionName] containing the typedefs.SQLERState for the given connection


9.0.0 (2021-08-18)

Full Changelog

Breaking Changes:

Features: