Interface for database drivers.
Methods
-
booleanLiteral(val)
-
Get Boolean SQL literal.
Parameters:
Name Type Description val* The ES value. Returns:
String representing Boolean true or false in SQL.- Type
- string
-
booleanToNull(expr)
-
Make SQL expression that evaluates the specified SQL expression and resolves into SQL
TRUEor SQL NULL if the result is true or false respectively.Parameters:
Name Type Description exprstring The Boolean SQL expression to evaluate. Returns:
SQL expression that evaluates toTRUEorNULL.- Type
- string
-
buildDeleteWithJoins(fromTableName, fromTableAlias [, refTables] [, filterExpr] [, filterExprParen])
-
Construct a SQL
DELETEstatement that can have aWHEREclause that uses columns from other joined tables. Note, that the statement still deletes rows only from a single table.Parameters:
Name Type Argument Description fromTableNamestring Name of the table, from which to delete. fromTableAliasstring Alias for the fromTableNameused in the join conditions and theWHEREclause.refTablesArray.<Object> <optional>
Array of descriptors of reference tables joined to the fromTableNametable and used in theWHEREclause.Properties
Name Type Description tableNamestring Reference table name. tableAliasstring Reference table alias used in the join condition and the WHEREclause.joinConditionstring Boolean SQL expression for the reference table join condition. filterExprstring <optional>
Boolean SQL expression for the WHEREclause. The expression may usefromTableAliasand aliases of the reference tables to refer to the corresponding tables.filterExprParenboolean <optional>
trueindicates that if thefilterExpris included in a logical conjunction (the "AND" Boolean operation), it needs to be enclosed in parenthesis.Returns:
The resultingDELETEstatement.- Type
- string
-
buildLockTables( [exclusiveLockTables] [, sharedLockTables])
-
Construct statement for placing transaction-scoped full table locks. Not all databases support it (e.g. MySQL supports explicit table locks but they are not transaction-scoped but session-scoped).
Parameters:
Name Type Argument Description exclusiveLockTablesArray.<string> <optional>
List of tables to lock in exclusive mode. sharedLockTablesArray.<string> <optional>
List of tables to lock in shared mode. Throws:
-
If the database does not support it.
- Type
- external:Error
Returns:
Statement to run to place the requested locks.- Type
- string
-
-
buildUpdateWithJoins(updateTableName, updateTableAlias, sets [, refTables] [, filterExpr] [, filterExprParen])
-
Construct a SQL
UPDATEstatement that can have aWHEREclause that uses columns from other joined tables. Note, that the statement still updates rows of only a single table.Parameters:
Name Type Argument Description updateTableNamestring Name of the table to update. updateTableAliasstring Alias for the updateTableNameused in the join conditions and theWHEREclause.setsArray.<Object> The "set" statements, one for each column. Properties
Name Type Description columnNamestring Name of a column in the updateTableNametable.valuestring SQL value expression to set in the column. refTablesArray.<Object> <optional>
Array of descriptors of reference tables joined to the updateTableNametable and used in theWHEREclause.Properties
Name Type Description tableNamestring Reference table name. tableAliasstring Reference table alias used in the join condition and the WHEREclause.joinConditionstring Boolean SQL expression for the reference table join condition. filterExprstring <optional>
Boolean SQL expression for the WHEREclause. The expression may useupdateTableAliasand aliases of the reference tables to refer to the corresponding tables.filterExprParenboolean <optional>
trueindicates that if thefilterExpris included in a logical conjunction (the "AND" Boolean operation), it needs to be enclosed in parenthesis.Returns:
The resultingUPDATEstatement.- Type
- string
-
buildUpsert(tableName, insertColumns, insertValues, uniqueColumn, sets)
-
Build a SQL statement that performs an "upsert" operation.
Parameters:
Name Type Description tableNamestring Name of the table for the update/insert. insertColumnsstring Comma-separated list of columns for the INSERTstatement.insertValuesstring Comma-separated list of values for the INSERTstatement'sVALUESclause.uniqueColumnstring Name of the column that has the unique constraint that is expected to be violated on the insert attempt. setsstring Comma-separated list of column/value assignments for the UPDATEstatement'sSETclause.Returns:
The resulting SQL statement.- Type
- string
-
castToString(expr)
-
Make SQL expression that converts the specified SQL expression to string.
Parameters:
Name Type Description exprstring The SQL expression to convert to string. Returns:
SQL expression that evaluates to a string value.- Type
- string
-
coalesce(exprs)
-
Make SQL expression that evaluates to the result of the first of the specified SQL expressions that is not
NULL, orNULLif all evaluate toNULL.Parameters:
Name Type Argument Description exprsstring <repeatable>
SQL expressions to evaluate. Returns:
SQL expression that evaluates to the first non-NULL.- Type
- string
-
commitTransaction(connection, handler)
-
Commit transaction on the specified database connection.
Parameters:
Name Type Description connection* Driver-specific database connection object. handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
connect(source, handler)
-
Acquire database connection.
Parameters:
Name Type Description source* Driver-specific database connections source. handlerObject Connection result handler. Properties
Name Type Description onSuccessfunction Function that gets called when the connection is acquired. The connection is passed to it as the only argument. onErrorfunction Function that gets called when connection could not be acquired. The error is passed to is as the only argument. -
createVersionTableIfNotExists(connection, tableName, itemNames, handler)
-
Create special table used to track versions if it does not exist yet. The table has three columns:
name(varchar 64, primary key),modified_on(timestamp) andversion(unsigned integer). Also make sure that the table contains rows for every item name. The method creates and populates the table using correct locking so that multiple instances can be attempting to do it concurrently.Parameters:
Name Type Description connection* Driver-specific database connection object. tableNamestring Table name. itemNamesIterable.<string> Item names to make sure are represented in the table. handlerObject The operation result handler. Properties
Name Type Argument Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. The handler must ensure that the database connection is destroyed if the error is reported. tracefunction <optional>
Function that gets called before the method sends a SQL command to the database. The command SQL is passed to the function as its only argument. -
executeInsert(connection, statement, handler [, idColumn])
-
Execute specified
INSERTstatement.Parameters:
Name Type Argument Description connection* Driver-specific database connection object. statementstring The INSERTstatement to execute.handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. If idColumnargument is provided, the function gets the inserted record id as its only argument.onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. idColumnstring <optional>
Name of the auto-generated id column in the table. If specified, the result promise will resovle to the generated id value. -
executeQuery(connection, statement, handler)
-
Execute specified statement on the specified database connection. The statement may be returning a result set.
Parameters:
Name Type Description connection* Driver-specific database connection object. statementstring The statement to execute. handlerObject The operation result handler. Properties
Name Type Argument Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. onHeaderfunction <optional>
Function that gets called when the SELECTquery result set descriptor is received from the database. The function receives a single argument, which is an array of strings corresponding to the column names in the result set.onRowfunction <optional>
Function that gets called when the SELECTquery result set row is received from the database. The function gets a single argument, which, depending on the driver, can be an array of values, one for each column, or an object with column names as the keys and the corresponding values as the values. -
executeUpdate(connection, statement, handler)
-
Execute specified statement on the specified database connection. The statement is intended to modify data (such as
UPDATEandDELETEstatements).Parameters:
Name Type Description connection* Driver-specific database connection object. statementstring The statement to execute. handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. The function gets the number of affected rows as its only argument. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
getSessionVariable(connection, varName, type, handler)
-
Get server-side session variable.
Parameters:
Name Type Description connection* Driver-specific database connection object. varNamestring Variable name. typestring Expected variable type: "number", "boolean" or "string". handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. The function receives the variable value as its only argument. If the variable is not set, undefinedis passed to the function.onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
makeRangedSelect(selectStmt, offset, limit)
-
Make specified
SELECTstatement ranged.Parameters:
Name Type Description selectStmtstring The SELECTstatement to make ranged.offsetnumber Zero-based number of the first row in the range. limitnumber Maximum number of rows in the range. Returns:
RangedSELECTstatement.- Type
- string
-
makeSelectWithLocks(selectStmt [, exclusiveLockTables] [, sharedLockTables])
-
Make the specified
SELECTstatement explicitely lock involved rows.Parameters:
Name Type Argument Description selectStmtstring The SELECTstatement.exclusiveLockTablesArray.<Object> <optional>
Descriptors of tables to lock in exclusive mode. Descriptors have two properties: tableNameandtableAlias.sharedLockTablesArray.<Object> <optional>
Descriptors of tables to lock in shared mode. Descriptors have two properties: tableNameandtableAlias.Returns:
SELECTstatement based on the provided one that places the requested locks. If provided table lists were empty, the original query is returned unchanged. -
nullableConcat(exprs)
-
Make SQL expression that concatenates the specified string SQL expressions and evaluates to
NULLif any of them isNULL.Parameters:
Name Type Argument Description exprsstring <repeatable>
String SQL expressions to concatenate. Returns:
SQL expression that concatenates the specified string SQL expressions.- Type
- string
-
patternMatch(expr, pattern, invert, caseSensitive)
-
Make Boolean SQL expression that matches the specified character value expression against a
LIKEpattern.Parameters:
Name Type Description exprstring SQL character expression to match. patternstring SQL expression for the LIKEpattern.invertboolean trueto test if the value does not match the pattern.caseSensitiveboolean trueto make the test case-sensitive.Returns:
Boolean SQL expression for the test.- Type
- string
-
regexpMatch(expr, regexp, invert, caseSensitive)
-
Make Boolean SQL expression that matches the specified character value expression against a regular expression.
Parameters:
Name Type Description exprstring SQL character expression to match. regexpstring SQL expression for the regular expression. invertboolean trueto test if the value does not match the regular expression.caseSensitiveboolean trueto make the test case-sensitive.Returns:
Boolean SQL expression for the test.- Type
- string
-
releaseConnection(source, connection [, err])
-
Release database connection previously acquired using the connect() method.
Parameters:
Name Type Argument Description source* Driver-specific database connections source. connection* The connection to release. errexternal:Error <optional>
Optional error object if the connection is being released after a database error, in which case the connection is destroyed. -
rollbackTransaction(connection, handler)
-
Roll back transaction on the specified database connection.
Parameters:
Name Type Description connection* Driver-specific database connection object. handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
safeLabel(label)
-
Get SQL fragment that can be used as a column label in a
SELECTclause from the specified string.Parameters:
Name Type Description labelstring The ES string to use as a column label. Returns:
SQL fragment for the label.- Type
- string
-
safeLikePatternFromString(str)
-
Make necessary escapes in the specified string to make it safe to use as a SQL
LIKEcondition pattern.Parameters:
Name Type Description strstring The ES string to make safe to use as a pattern. Returns:
The string with all the necessary escapes.- Type
- string
-
selectIntoAnchorTable(connection, anchorTableName, topTableName, idColumnName, idExpr, statementStump, handler)
-
Load the results of a
SELECTquery that is used to select record ids into a temporary anchor table. The resulting table will have two columns: "id" for the record ids returned by theSELECTquery, and "ord" with sequential numbers reflecting the order, in which theSELECTquery returned the ids.Parameters:
Name Type Description connection* Driver-specific database connection object. anchorTableNamestring Name of the anchor table to use. Must be unique for the transaction. topTableNamestring Name of the top table in the SELECTquery. This is the table that contains the ids.idColumnNamestring Name of the column in topTableNametable that contains the ids being loaded into the anchor table.idExprstring SQL value expression for the ids returned by the SELECTquery.statementStumpstring The SELECTquery with "{*}" placeholder in the place of the select list.handlerObject The operation result handler. Properties
Name Type Argument Description onSuccessfunction Function that gets called upon operation success. The function receives two arguments: the name of the anchor table and the number of ids loaded into the anchor table. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. tracefunction <optional>
Function that gets called before the method sends a SQL command to the database. The command SQL is passed to the function as its only argument. -
setSessionVariable(connection, varName, valueExpr, handler)
-
Set server-side session variable.
Parameters:
Name Type Description connection* Driver-specific database connection object. varNamestring Variable name. valueExprstring SQL expression for the variable value. handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
sql(val)
-
Get SQL for the specified ES value.
Parameters:
Name Type Description val* The ES value. If object, toString()is called on it and the result is returned as is. Ifnull, string "NULL" is returned.Returns:
String representing the value in SQL, ornullif the value cannot be represented in SQL (includesundefined,NaN,Infinityand arrays).- Type
- string
-
startTransaction(connection, handler)
-
Start transaction on the specified database connection.
Parameters:
Name Type Description connection* Driver-specific database connection object. handlerObject The operation result handler. Properties
Name Type Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. -
stringLeftPad(expr, width, pad)
-
Make SQL expression that pads the specified string SQL expression with the specified character on the left until the specified length is achieved.
Parameters:
Name Type Description exprstring The string SQL expression. widthnumber Minimum resulting string length to achieve with padding. padstring The character to use as the padding. Returns:
SQL expression that pads the string on the left.- Type
- string
-
stringLength(expr)
-
Make SQL expression that gets the string length for the specified string SQL expression.
Parameters:
Name Type Description exprstring The string SQL expression. Returns:
SQL expression that gets the string length.- Type
- string
-
stringLiteral(val)
-
Get string SQL literal.
Parameters:
Name Type Description valstring The ES string. Returns:
String representing the string in SQL.- Type
- string
-
stringLowercase(expr)
-
Make SQL expression that converts the specified string SQL expression to lower case.
Parameters:
Name Type Description exprstring The string SQL expression. Returns:
SQL expression that converts the string to lower case.- Type
- string
-
stringSubstring(expr, from [, len])
-
Make SQL expression for getting a substring of the specified string SQL expression.
Parameters:
Name Type Argument Description exprstring SQL string expression. fromnumber | string Zero-based first character to include in the substring. If not number, assumed to be a SQL expression. lennumber | string <optional>
Optional maximum length of the substring. If not number, assumed to be a SQL expression. If not specified, the end of the string is assumed. Returns:
SQL expression for the substring.- Type
- string
-
stringUppercase(expr)
-
Make SQL expression that converts the specified string SQL expression to upper case.
Parameters:
Name Type Description exprstring The string SQL expression. Returns:
SQL expression that converts the string to upper case.- Type
- string
-
supportsRowLocksWithAggregates()
-
Tell if the underlying database supports explicit row locking in
SELECTqueries with aggregates (e.g. MySQL) or not (e.g. PostgreSQL).Returns:
trueif supported.- Type
- boolean
-
updateVersionTable(connection, tableName, itemNames, modificationTimestamp, handler)
-
Update versions tracking table.
Parameters:
Name Type Description connection* Driver-specific database connection object. tableNamestring Table name. itemNamesArray.<string> Names of the items to update. modificationTimestampstring Modification timestamp. handlerObject The operation result handler. Properties
Name Type Argument Description onSuccessfunction Function that gets called upon operation success. onErrorfunction Function that gets called upon operation failure. The function receives a single argument with the error object. tracefunction <optional>
Function that gets called before the method sends a SQL command to the database. The command SQL is passed to the function as its only argument.