index
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 exampledb.<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.
Kind: global class
- Manager
- new Manager(conf, [cache], [logging])
- instance
- .addConnection(conn, [priv], [cache], [logging], [returnErrors]) ⇒
typedefs.SQLEROperationResults - .init([returnErrors]) ⇒
typedefs.SQLEROperationResults - .state([opts], [...connNames]) ⇒
typedefs.SQLEROperationResults - .preparedFunctionCount([...connNames]) ⇒
typedefs.SQLEROperationResults - .close() ⇒
typedefs.SQLEROperationResults - .scan([removeOrphans], ...connNames) ⇒
typedefs.SQLEROperationResults - .setCache([cache], [isTransfer], ...connNames) ⇒
typedefs.SQLEROperationResults - .getCacheKey(path, connName) ⇒
String - .generateCacheKey(dialect, connName, methodName, ext) ⇒
String
- .addConnection(conn, [priv], [cache], [logging], [returnErrors]) ⇒
- static
- .OPERATION_TYPES ⇒
Array.<String> - .POSITIONAL_BINDS_REGEXP ⇒
RegExp - .namedBindSequence(sql, count) ⇒
Array.<String>
- .OPERATION_TYPES ⇒
new Manager(conf, [cache], [logging])
Creates a new database manager. Vendor-specific implementations should have constructors that accept properties defined by typedefs.Dialect.
| Param | Type | Description |
|---|---|---|
| conf | typedefs.SQLERConfigurationOptions | The configuration options |
| [cache] | typedefs.SQLERCache | 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 | 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. |
manager.addConnection(conn, [priv], [cache], [logging], [returnErrors]) ⇒ typedefs.SQLEROperationResults
Adds a connection configuration to the manager and initializes the database connection
Kind: instance method of Manager
Returns: 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)
| Param | Type | Description |
|---|---|---|
| conn | typedefs.SQLERConnectionOptions | The connection options that will be added to the manager |
| [priv] | typedefs.SQLERPrivateOptions | 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 | 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 | 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 | Truthy to return errors, otherwise, any encountered errors will be thrown |
manager.init([returnErrors]) ⇒ typedefs.SQLEROperationResults
Initializes the configured database connections
Kind: instance method of Manager
Returns: 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)
| Param | Type | Description |
|---|---|---|
| [returnErrors] | Boolean | Truthy to return errors, otherwise, any encountered errors will be thrown |
manager.state([opts], [...connNames]) ⇒ typedefs.SQLEROperationResults
Composes the typedefs.SQLERState on either all the connections used by the manager or on the specified connection names.
Kind: instance method of Manager
Returns: typedefs.SQLEROperationResults - The results, each result[connectionName] containing the typedefs.SQLERState for the given connection
| Param | Type | Description |
|---|---|---|
| [opts] | typedefs.SQLEROperationOptions | The typedefs.SQLEROperationOptions to use |
| [...connNames] | String | The connection names to perform the check on (defaults to all connections) |
manager.preparedFunctionCount([...connNames]) ⇒ typedefs.SQLEROperationResults
Gets the number of prepared SQL functions on either all the connections used by the manager or on the specified connection names.
Kind: instance method of Manager
Returns: typedefs.SQLEROperationResults - The results, each result[connectionName] containing the number of generated prepared SQL functions for the given connection
| Param | Type | Description |
|---|---|---|
| [...connNames] | String | The connection names to perform the check on (defaults to all connections) |
manager.close() ⇒ typedefs.SQLEROperationResults
Closes all database pools/connections/etc.
Kind: instance method of Manager
Returns: typedefs.SQLEROperationResults - The results
manager.scan([removeOrphans], ...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.
Kind: instance method of Manager
Returns: typedefs.SQLEROperationResults - The results, each result[connectionName] containing the number of SQL prepared functions for the given connection
| Param | Type | Default | Description |
|---|---|---|---|
| [removeOrphans] | Boolean | true | Truthy to remove orphaned prepared functions that no longer have an SQL file associated with them |
| ...connNames | String | The connection names to scan for SQL files for when generating prepared functions |
manager.setCache([cache], [isTransfer], ...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.
Kind: instance method of Manager
Returns: typedefs.SQLEROperationResults - The results, each result[connectionName] containing the number of cached keys transferred for the given connection
| Param | Type | Description |
|---|---|---|
| [cache] | typedefs.SQLERCache | 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 | 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 | The connection names to set the cache for |
manager.getCacheKey(path, connName) ⇒ String
Gets a cache key for a given absolute path to an SQL file
Kind: instance method of Manager
Returns: String - The cache key for the given path
| Param | Type | Description |
|---|---|---|
| path | String | The absolute path to the SQL file |
| connName | String | The connection name to get the cache key for |
manager.generateCacheKey(dialect, connName, methodName, ext) ⇒ String
Generates a key used for caching SQL methods
Kind: instance method of Manager
Returns: String - The key used for caching
| Param | Type | Description |
|---|---|---|
| dialect | String | The database dialect |
| connName | String | The connection name |
| methodName | String | The SQL method name |
| ext | String | The SQL file extension |
Manager.OPERATION_TYPES ⇒ Array.<String>
Kind: static property of Manager
Returns: Array.<String> - The operation types
Manager.POSITIONAL_BINDS_REGEXP ⇒ RegExp
Kind: static property of Manager
Returns: RegExp - A regular expression that globally matches each named bind parameters in a SQL statement. A single capture group is defined for each parameter name (match on entire bind name syntax)
Manager.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
Kind: static method of Manager
Returns: Array.<String> - The SQL statements that have been duplicated with sequentially numeric suffixes
| Param | 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 |
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'
]