Global type definitions used by sqler
- Source:
Type Definitions
SQLERBindExpansionFunction(sql, bindsopt) → {String}
Expands bind variables that contain an array of values when they appear in the SQL statement. For example, an SQL statement with a section that contains
IN (:someParam)
and binds of { someParam: [1,2,3] }
would become IN (:someParam, :someParam1, :someParam2)
with binds of { someParam: 1, someParam1: 2, SomeParam2: 3 }
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sql |
String
|
The SQL to defragement |
|
binds |
Object
|
<optional> |
An object that contains the SQL parameterized |
Returns:
- Type:
-
String
The defragmented SQL
SQLERCache
The cache
client responsible for regulating the frequency in which a SQL file is read by a Manager
.
Properties:
Name | Type | Description |
---|---|---|
start |
function
|
An |
stop |
function
|
An |
get |
function
|
An
|
set |
function
|
An |
drop |
function
|
An |
- Source:
Type:
-
Object
Example
// cache options can be different depending on the needs of the implementing cache
const cacheOpts = {
"expiresIn": 60000
};
// simple interval cache for illustration purposes
const bank = { store: {}, handles: {} };
const cache = {
start: async () => {
let cached, calTtl;
for (let key in bank.handles) {
clearInterval(bank.handles[key]);
cached = bank.store.hasOwnProperty(key) ? bank.store[key] : null;
calTtl = !cached|| isNaN(cached.ttl) ? cacheOpts.expiresIn : cached.ttl;
bank.handles[key] = setInterval(() => delete bank.store[key], calTtl);
}
},
stop: async () => {
for (let key in bank.handles) {
clearInterval(bank.handles[key]);
}
},
get: async key => {
const cached = bank.store.hasOwnProperty(key) ? bank.store[key] : null;
if (cached) cached.ttl = Date.now() - cached.stored;
return Promise.resolve(cached ? JSON.parse(JSON.stringify(cached)) : cached);
},
set: async (key, val, ttl) => {
if (bank.handles[key]) clearInterval(bank.handles[key]);
const calTtl = !ttl || isNaN(ttl) ? cacheOpts.expiresIn : ttl;
bank.store[key] = { item: val, stored: Date.now(), ttl: calTtl };
bank.handles[key] = setInterval(sql => delete bank.store[key], calTtl);
return Promise.resolve();
},
drop: async () => {
if (bank.handles[key]) {
clearInterval(bank.handles[key]);
delete bank.handles[key];
}
if (bank.store[key]) delete bank.store[key];
}
};
// manager configuration
const conf = {
// other required conf options here
"db": {
"connections": [
{
// other required connection conf options here
}
]
}
};
const mgr = new Manager(conf, cache);
await mgr.init();
// use the manager to execute SQL files that will
// be refreshed/re-read every 60 seconds
// can also set the cache after Manager.init()
const setCacheResults = await mgr.setCache(cache);
SQLERConfigurationOptions
Configuration options for Manager
use
Properties:
Name | Type | Attributes | Description | |||||
---|---|---|---|---|---|---|---|---|
mainPath |
String
|
<optional> |
Root directory starting point to look for SQL files (defaults to |
|||||
privatePath |
String
|
<optional> |
Current working directory where generated files will be located (if any, defaults to |
|||||
debug |
Boolean
|
<optional> |
Truthy to turn on debugging |
|||||
univ |
SQLERUniversalOptions
|
The |
||||||
db |
Object
|
The public facing database configuration |
||||||
Name | Type | Description |
---|---|---|
dialects |
Object
|
An object that contains |
connections |
Array.<SQLERConnectionOptions>
|
The connections options that will be used. |
- Source:
Type:
-
Object
SQLERConnectionOptions
Options for connections used by Manager
Properties:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
String
|
Identifies the connection within a |
|||||||||||||||||||||||||
dialect |
String
|
The database dialect (e.g. mysql, mssql, oracle, etc.) |
|||||||||||||||||||||||||
name |
String
|
The name given to the database used as the property name on the |
|||||||||||||||||||||||||
dir |
String
|
<optional> |
name | The alternative dir where |
|||||||||||||||||||||||
version |
Float
|
<optional> |
A version that can be used for version substitutions within an SQL statement |
||||||||||||||||||||||||
service |
String
|
<optional> |
The service name defined by the underlying database (may be required depending on the implementing |
||||||||||||||||||||||||
binds |
Object
|
<optional> |
The global object that contains bind variable values that will be included in all SQL calls made under the connection for parameter |
||||||||||||||||||||||||
substitutes |
Object
|
<optional> |
Key/value pairs that define global/static substitutions that will be made in prepared statements by replacing occurances of keys with corresponding values |
||||||||||||||||||||||||
host |
String
|
<optional> |
The database host override for a value specified in |
||||||||||||||||||||||||
port |
String
|
<optional> |
The database port override for a value specified in |
||||||||||||||||||||||||
protocol |
String
|
<optional> |
The database protocol override for a value specified in |
||||||||||||||||||||||||
dateFormatter |
function
|
Boolean
|
<optional> |
A |
||||||||||||||||||||||||
driverOptions |
Object
|
<optional> |
Options passed directly into the |
||||||||||||||||||||||||
log |
Boolean
|
Array.<String>
|
<optional> |
When logging is turned on for a given |
||||||||||||||||||||||||
logError |
Boolean
|
Array.<String>
|
<optional> |
When logging is turned on for a given |
||||||||||||||||||||||||
pool |
Object
|
<optional> |
The connection pool options (overrides any |
||||||||||||||||||||||||
Name | Type | Attributes | Description |
---|---|---|---|
max |
Number
|
<optional> |
The maximum number of connections in the pool. When |
min |
Number
|
<optional> |
The minumum number of connections in the pool. When |
idle |
Number
|
<optional> |
The maximum time, in milliseconds, that a connection can be idle before being released (overrides any |
increment |
Number
|
<optional> |
The number of connections that are opened whenever a connection request exceeds the number of currently open connections.
When |
timeout |
Number
|
<optional> |
The number of milliseconds that a connection request should wait in the queue before the request is terminated
(overrides any |
alias |
String
|
<optional> |
When supported, the alias of this pool in the connection pool cache (overrides any |
- Source:
Type:
-
Object
SQLERExecErrorOptions
Options for handling any errors that occur during execution.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
handler |
function
|
<optional> |
A |
includeBindValues |
Boolean
|
<optional> |
Truthy to include the bind parameter values |
returnErrors |
Boolean
|
<optional> |
Truthy to return any errors that may occur. Otherwise, throw any errors that may occur. |
- Source:
Type:
-
Object
SQLERExecMeta
Internally generated metadata that is passed into Dialect.exec
by a Manager
for determining SQL sources.
Properties:
Name | Type | Description |
---|---|---|
name |
String
|
The composed name given to a given SQL file |
path |
String
|
The path to the SQL file |
- Source:
Type:
-
Object
SQLERExecOptions
Options that are passed to generated SQLERPreparedFunction
.
NOTE: Either transaction.commit
or trnasaction.rollback
must be invoked when autoCommit
is falsy and a valid transactionId
is supplied to ensue underlying connections are
completed and closed.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
<optional> |
A name to assign to the execution. |
|
type |
String
|
<optional> |
The type of CRUD operation that is being executed (i.e. |
|
stream |
Number
|
<optional> |
A value |
|
binds |
Object
|
<optional> |
{} | The key/value pair of binding parameters that will be bound in the SQL statement. |
autoCommit |
Boolean
|
<optional> |
true | Truthy to perform a commits the transaction at the end of the prepared function execution. NOTE: When falsy the underlying connection will remain open
until the returned |
transactionId |
String
|
<optional> |
A transaction ID returned from a prior call to |
|
prepareStatement |
Boolean
|
<optional> |
Truthy to generate or use an existing prepared statement for the SQL being executed via the |
|
dateFormatter |
function
|
Boolean
|
<optional> |
A |
|
numOfPreparedFuncs |
Number
|
The total number of |
||
driverOptions |
Object
|
<optional> |
Options that may override the |
- Source:
Type:
-
Object
SQLERExecResults
Results returned from invoking a SQLERPreparedFunction
.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
rows |
Array.<Object>
|
Array.<Stream.Readable>
|
Array.<Stream.Writable>
|
<optional> |
The execution array of model objects representing each row or |
unprepare |
function
|
<optional> |
A no-argument async function that unprepares an outstanding prepared statement. Will not be available when the |
error |
Error
|
<optional> |
Any caught error that occurred when a |
raw |
Object
|
The raw results from the execution (driver-specific execution results). |
- Source:
Type:
-
Object
SQLERInitOptions
Options that are used during initialization
Properties:
Name | Type | Description |
---|---|---|
numOfPreparedFuncs |
Number
|
The total number of |
- Source:
Type:
-
Object
SQLERInterpolateFunction(dest, source, interpolatoropt, validatoropt, onlyInterpolatedopt) → {Object}
Interpolates values from a source object to a destination object.
When a value is a string surrounded by ${}
, it will be assumed to be a interpolated property that resides on another property on the source
or an interpolated property on the interpolator
.
For example source.someProp = '${SOME_VALUE}'
will be interpreted as dest.someProp = dest.SOME_VALUE
when the interpolator
is omitted and
dest.someProp = interpolator.SOME_VALUE
when an interpolator
is specified.
Typically only used by implementing Dialect
constructors within a SQLERTrack
.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dest |
Object
|
The destination where the sources will be set (also the interpolated source when |
||
source |
Object
|
The source of the values to interpolate (e.g. |
||
interpolator |
Object
|
<optional> |
dest |
An alternative source to use for extracting interpolated values from. |
validator |
SQLERInterpolateValidationFunction
|
<optional> |
A validation function for each property/value being interpolated to determine if it will be interolated. |
|
onlyInterpolated |
Boolean
|
<optional> |
Truthy to indicate that the only values that will be set from the |
Returns:
- Type:
-
Object
The passed destination
SQLERInterpolateValidationFunction(srcPropNames, srcPropValue) → {Boolean}
A validation for validating interpolation used by a SQLERInterpolateFunction
- Source:
Parameters:
Name | Type | Description |
---|---|---|
srcPropNames |
Array.<String>
|
Property path(s) to the value being validated (e.g. |
srcPropValue |
*
|
The value being validated for interpolation |
Returns:
- Type:
-
Boolean
Flag indicating whether or not to include the interpolated property/value
SQLEROperationOptions
Options for operational methods on a Manager
(e.g. Manager.init
, Manager.state
, Manager.close
, etc.).
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
connections |
Object
|
<optional> |
An object that contains connection names as properties. Each optionally containing an object with |
executeInSeries |
Boolean
|
<optional> |
Set to truthy to execute the operation in series, otherwise executes operation in parallel. |
errorOpts |
SQLERExecErrorOptions
|
Boolean
|
<optional> |
Set to truthy to return any errors. Otherise throw any errors as they are encountered. options can also be set instead. |
- Source:
Type:
-
Object
SQLEROperationResults
Results returned from invoking an operational method on a Manager
(e.g. Manager.init
, Manager.state
, Manager.close
, etc.).
Properties:
Name | Type | Description |
---|---|---|
result |
Object
|
An object that contains a property name that matches each connection that was processed (the property value is the number of operations processed per connection). |
errors |
Array.<Error>
|
Any errors that may have occurred on the operational methods. Should only be populated when |
- Source:
Type:
-
Object
SQLERPositionalBindsFunction(sql, bindsObject, bindsArray, placeholderopt) → {String}
Converts a SQL statement that contains named bind parameters into a SQL statement that contains unnamed/positional bind parameters (using ?
).
Each bound parameter is pushed to the array in the position that corresponds to the position within the SQL statement.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sql |
String
|
The SQL statement that contains the bind parameters |
||
bindsObject |
Object
|
An object that contains the bind parameters as property names/values |
||
bindsArray |
Array
|
The array that will be populated with the bind parameters |
||
placeholder |
String
|
function
|
<optional> |
? |
Either a string value that will be used for the postional placeholder or a |
Throws:
-
Thrown when a bound parameter is not within the orgiginating SQL statement
- Type
-
Error
Returns:
- Type:
-
String
The converted SQL statement
(async) SQLERPreparedFunction(optsopt, fragsopt, errorOptsopt) → {SQLERExecResults}
Prepared functions are auto-generated async
functions that execute an SQL statement from an SQL file source.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opts |
SQLERExecOptions
|
<optional> |
The SQL execution options |
frags |
Array.<String>
|
<optional> |
Consists of any fragment segment names present in the SQL being executed that will be included in the final SQL statement. Any fragments present in the SQL source will be excluded from the final SQL statement when there is no matching fragment name. |
errorOpts |
SQLERExecErrorOptions
|
Boolean
|
<optional> |
Either the error handling options or a boolean flag indicating that any errors that occur during execution should be returned in
the |
Returns:
- Type:
-
SQLERExecResults
The execution results
SQLERPrivateOptions
Private options for global Manager
use
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
username |
String
|
<optional> |
The username to connect to the database |
password |
String
|
<optional> |
The password to connect to the database |
host |
String
|
<optional> |
The host to connect to for the database |
port |
String
|
<optional> |
The port to connect to for the database (when not included in the host) |
protocol |
String
|
<optional> |
The protocol to use when connecting to the database |
privatePath |
String
|
<optional> |
The private path set by an originating |
- Source:
Type:
-
Object
SQLERState
The current state of the managed Dialect
Properties:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
pending |
Number
|
The number of transactions that are pending |
|||||||||
connections |
Object
|
<optional> |
The connection state |
||||||||
Name | Type | Attributes | Description |
---|---|---|---|
count |
Number
|
<optional> |
The number of connections |
inUse |
Number
|
<optional> |
The number of connections that are in use |
- Source:
Type:
-
Object
SQLERStreamReadableProcessor(opts, readStream, readeropt) → {Stream.Readable}
Function that internally handles the specified SQLERExecOptions
stream
batch size and emits a batch event when the batch size
threshold has been reached on a specified stream.Readable
.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opts |
SQLERExecOptions
|
The execution options |
|
readStream |
Stream.Readable
|
The readable stream that will produce the SQL results |
|
reader |
SQLERStreamReader
|
<optional> |
The function that will process the batch read |
Returns:
- Type:
-
Stream.Readable
The readable stream that was passed
(async) SQLERStreamReader(batch) → {*}
Processes a read batch of streamed objects for a particular dialect implementation.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
batch |
Array.<Object>
|
The batch of streamed objects based upon a predefined |
Returns:
- Type:
-
*
A value that will be emitted on a readable stream.
SQLERStreamWritable(opts, writter) → {Stream.Writable}
Function that will generate a Stream.Writable
that internally handles the specified SQLERExecOptions
stream
batch size and emits
a batch event when the batch size threshold has been reached.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
opts |
SQLERExecOptions
|
The execution options |
writter |
SQLERStreamWritter
|
The function that will process the batch write |
Returns:
- Type:
-
Stream.Writable
The writable stream that will handle the sqler
internals
(async) SQLERStreamWritter(batch) → {*}
Writes a batch of streamed objects for a particular dialect implementation and returns the raw results.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
batch |
Array.<Object>
|
The batch of streamed objects based upon a predefined |
Returns:
- Type:
-
*
The raw batch execution results from the dialect execution and will be emitted on a writable stream.
SQLERTrack
A tracking mechanism that is shared between all Dialect
implementations for a given Manager
. A track provides a means to share
data, etc. from one Dialect
to another. Properties can also be added by a Dialect
for use in other Dialect
s.
Typically only used by implementing Dialect
constructors.
Properties:
Name | Type | Description |
---|---|---|
interpolate |
SQLERInterpolateFunction
|
An interpolation function that can be used by |
positionalBinds |
SQLERPositionalBindsFunction
|
A function that will convert an SQL statement with named binds into positional binds. |
bindExpansions |
SQLERBindExpansionFunction
|
A function that takes an SQL statement with named binds and expands the bind variables into an array of values when they appear in the SQL statement |
readable |
SQLERStreamReadableProcessor
|
A function that uses a specified readable stream for batching large number of read executions. |
writable |
SQLERStreamWritable
|
A function that will generate a writable stream for batching large number of write executions. |
- Source:
Type:
-
Object
SQLERTransaction
Transaction that symbolizes a unit of work performed within a Manager
connection.
Properties:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
String
|
The unique identifier for the transaction. |
||||||||||||
commit |
SQLERTransactionCommit
|
Rolls back the outstanding transaction. |
||||||||||||
rollback |
SQLERTransactionRollback
|
Commits the outstanding transaction. |
||||||||||||
state |
Object
|
The state of the transaction |
||||||||||||
Name | Type | Description |
---|---|---|
committed |
Number
|
True when the transaction has been committed. |
rolledback |
Number
|
True when the transaction has been rolledback. |
pending |
Number
|
The number of pending SQL statements executed within the scope of the given transaction that have not been committed or rolledback. |
isReleased |
Boolean
|
Truthy when the transaction has been released. |
- Source:
Type:
-
Object
(async) SQLERTransactionCommit(isReleaseopt)
Function that commits an outstanding transaction.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
isRelease |
Boolean
|
<optional> |
When truthy, releases the connection back to the connection pool after a commit has been performed. It's essential that connections be released back into the connection pool to ensure that there are enough available connections for other independent executions that use the same pool. |
SQLERTransactionOptions
Options for a SQLERTransaction
that can be passed into a manager.connectionName.beginTransaction(transactionDriverOptions)
function.
- Source:
Type:
-
Object
(async) SQLERTransactionRollback(isReleaseopt)
Function that rolls back an outstanding transaction.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
isRelease |
Boolean
|
<optional> |
When truthy, releases the connection back to the connection pool after a rollback has been performed. It's essential that connections be released back into the connection pool to ensure that there are enough available connections for other independent executions that use the same pool. |
SQLERUniversalOptions
The universal configuration that, for security and sharing purposes, remains external to an application
Properties:
Name | Type | Description |
---|---|---|
db |
Object
|
The database options that contain private sensitive configuration. Each property should correspond to a |
- Source:
Type:
-
Object