ballerina/sql package

Primitives Summary

Type Description

Type Definitions

Type Values Description
Direction OUT | INOUT | IN
The direction of the parameter.

IN - IN parameters are used to send values to stored procedures.
OUT - OUT parameters are used to get values from stored procedures.
INOUT - INOUT parameters are used to send values and get values from stored procedures.
Param
SQLType VARCHAR | VARBINARY | TINYINT | TIMESTAMP | TIME | STRUCT | SMALLINT | REFCURSOR | REAL | NVARCHAR | NUMERIC | NCLOB | NCHAR | LONGVARCHAR | LONGVARBINARY | LONGNVARCHAR | INTEGER | FLOAT | DOUBLE | DECIMAL | DATETIME | DATE | CLOB | CHAR | BOOLEAN | BLOB | BIT | BINARY | BIGINT | ARRAY
The SQL Datatype of the parameter.

VARCHAR - Small, variable-length character string.
CHAR - Small, fixed-length character string.
LONGVARCHAR - Large, variable-length character string.
NCHAR - Small, fixed-length character string with unicode support.
LONGNVARCHAR - Large, variable-length character string with unicode support.

BIT - Single bit value that can be zero or one, or nil.
BOOLEAN - Boolean value either True or false.
TINYINT - 8-bit integer value which may be unsigned or signed.
SMALLINT - 16-bit signed integer value which may be unsigned or signed.
INTEGER - 32-bit signed integer value which may be unsigned or signed.
BIGINT - 64-bit signed integer value which may be unsigned or signed.

NUMERIC - Fixed-precision and scaled decimal values.
DECIMAL - Fixed-precision and scaled decimal values.
REAL - Single precision floating point number.
FLOAT - Double precision floating point number.
DOUBLE - Double precision floating point number.

BINARY - Small, fixed-length binary value.
BLOB - Binary Large Object.
LONGVARBINARY - Large, variable-length binary value.
VARBINARY - Small, variable-length binary value.

CLOB - Character Large Object.
NCLOB - Character large objects in multibyte national character set.

DATE - Date consisting of day, month, and year.
TIME - Time consisting of hours, minutes, and seconds.
DATETIME - Both DATE and TIME with additional a nanosecond field.
TIMESTAMP - Both DATE and TIME with additional a nanosecond field.

ARRAY - Composite data value that consists of zero or more elements of a specified data type.
STRUCT - User defined structured type, consists of one or more attributes.
REFCURSOR - Cursor value.

Annotations

Name Attachement Points Data Type Description

Objects Summary

Object Description
Parameter
CallParam represents a parameter for the SQL call action where OUT or INOUT parameter is required.
PoolOptions
Represents the properties which are used to configure DB connection pool.

Endpoints Summary

Endpoint Description

Functions Summary

Return Type Function and Description
close(CallerActions callerActions)
    The close action implementation for SQL connector to shutdown the connection pool.

Global Variables

Name Data Type Description
DIRECTION_IN Direction
DIRECTION_INOUT Direction
DIRECTION_OUT Direction
TYPE_ARRAY SQLType
TYPE_BIGINT SQLType
TYPE_BINARY SQLType
TYPE_BIT SQLType
TYPE_BLOB SQLType
TYPE_BOOLEAN SQLType
TYPE_CHAR SQLType
TYPE_CLOB SQLType
TYPE_DATE SQLType
TYPE_DATETIME SQLType
TYPE_DECIMAL SQLType
TYPE_DOUBLE SQLType
TYPE_FLOAT SQLType
TYPE_INTEGER SQLType
TYPE_LONGNVARCHAR SQLType
TYPE_LONGVARBINARY SQLType
TYPE_LONGVARCHAR SQLType
TYPE_NCHAR SQLType
TYPE_NCLOB SQLType
TYPE_NUMERIC SQLType
TYPE_NVARCHARR SQLType
TYPE_REAL SQLType
TYPE_REFCURSOR SQLType
TYPE_SMALLINT SQLType
TYPE_STRUCT SQLType
TYPE_TIME SQLType
TYPE_TIMESTAMP SQLType
TYPE_TINYINT SQLType
TYPE_VARBINARY SQLType
TYPE_VARCHAR SQLType

public object Parameter

CallParam represents a parameter for the SQL call action where OUT or INOUT parameter is required.

Field Name Data Type Default Value Description
sqlType SQLType
  • The data type of the corresponding SQL parameter.
value any
  • Value of paramter pass into the SQL query.
direction Direction
  • Direction of the SQL Parameter OUT, or INOUT - Default value is IN.
recordType typedesc
  • In case of OUT direction, if the sqlType is REFCURSOR, this represents the record type to map a result row.

public object PoolOptions

Represents the properties which are used to configure DB connection pool.

Field Name Data Type Default Value Description
connectionInitSql string
  • SQL statement that will be executed after every new connection creation before adding it to the pool.
dataSourceClassName string
  • Name of the DataSource class provided by the JDBC driver.
autoCommit boolean true
  • Auto-commit behavior of connections returned from the pool.
isXA boolean false
  • Whether Connections are used for a distributed transaction.
maximumPoolSize int -1
  • Maximum size that the pool is allowed to reach, including both idle and in-use connections.
connectionTimeout int -1
  • Maximum number of milliseconds that a client will wait for a connection from the pool.
idleTimeout int -1
  • Maximum amount of time that a connection is allowed to sit idle in the pool.
minimumIdle int -1
  • Minimum number of idle connections that pool tries to maintain in the pool.
maxLifetime int -1
  • Maximum lifetime of a connection in the pool.
validationTimeout int -1
  • Maximum amount of time that a connection will be tested for aliveness.

public function close(CallerActions callerActions)

    The close action implementation for SQL connector to shutdown the connection pool.

Parameter Name Data Type Default Value Description
callerActions CallerActions

public type CallerActions object

The Caller actions for SQL databases.

  • <CallerActions> call(string sqlQuery, typedesc[] recordType) returns (table[] | error)

        The call action implementation for SQL connector to invoke stored procedures/functions.
    

    Parameter Name Data Type Default Value Description
    sqlQuery string
    • SQL statement to execute.
    recordType typedesc[]
    • Array of record types of the returned tables if there is any.
    Return Type Description
    table[] | error
    • table[] if there are tables returned by the call action and else nill, error will be returned if there is any error.
  • <CallerActions> select(string sqlQuery, typedesc recordType) returns (table | error)

        The select action implementation for SQL connector to select data from tables.
    

    Parameter Name Data Type Default Value Description
    sqlQuery string
    • SQL query to execute.
    recordType typedesc
    • Type of the returned table.
    Return Type Description
    table | error
    • table table returned by the sql query statement else error will be returned if there is any error.
  • <CallerActions> update(string sqlQuery) returns (int | error)

        The update action implementation for SQL connector to update data and schema of the database.
    

    Parameter Name Data Type Default Value Description
    sqlQuery string
    • SQL statement to execute.
    Return Type Description
    int | error
    • int number of rows updated by the statement and else error will be returned if there is any error.
  • <CallerActions> batchUpdate(string sqlQuery) returns (int[] | error)

        The batchUpdate action implementation for SQL connector to batch data insert.
    

    Parameter Name Data Type Default Value Description
    sqlQuery string
    • SQL statement to execute.
    Return Type Description
    int[] | error
    • int[] An array of updated row count by each of statements in batch and else error will be returned if there is any error.
  • <CallerActions> updateWithGeneratedKeys(string sqlQuery, string[] keyColumns) returns ((int,string[]) | error)

        The updateWithGeneratedKeys action implementation for SQL connector which returns the auto
        generated keys during the update action.
    

    Parameter Name Data Type Default Value Description
    sqlQuery string
    • SQL statement to execute.
    keyColumns string[]
    • Names of auto generated columns for which the auto generated key values are returned.
    Return Type Description
    (int,string[]) | error
    • A Tuple will be returned and would represent updated row count during the query exectuion, aray of auto generated key values during the query execution, in order. Else error will be returned if there is any error.
  • <CallerActions> getProxyTable(string tableName, typedesc recordType) returns (table | error)

        The getProxyTable action implementation for SQL connector which acts as a proxy for a database
        table that allows performing select/update operations over the actual database table.
    

    Parameter Name Data Type Default Value Description
    tableName string
    • The name of the table to be retrieved.
    recordType typedesc
    • The record type of the returned table.
    Return Type Description
    table | error