# Class: SQLConnection

## vertx-sql-js/sql_connection~ SQLConnection

#### new SQLConnection()

Represents a connection to a SQL database

Source:
  - vertx-sql-js/sql_connection.js, line 34

### Methods

#### batch(sqlStatements, handler) → {SQLConnection}

Batch simple SQL strings and execute the batch where the async result contains a array of Integers.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sqlStatements` | Array.<string> | sql statement
`handler` | function | the result handler

Source:
  - vertx-sql-js/sql_connection.js, line 433

##### Returns:

Type
  SQLConnection

#### batchCallableWithParams(sqlStatement, inArgs, outArgs, handler) → {SQLConnection}

Batch a callable statement with all entries from the args list. Each entry is a batch. The size of the lists inArgs and outArgs MUST be the equal. The operation completes with the execution of the batch where the async result contains a array of Integers.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sqlStatement` | string | sql statement
`inArgs` | Array.<todo> | the callable statement input arguments
`outArgs` | Array.<todo> | the callable statement output arguments
`handler` | function | the result handler

Source:
  - vertx-sql-js/sql_connection.js, line 483

##### Returns:

Type
  SQLConnection

#### batchWithParams(sqlStatement, args, handler) → {SQLConnection}

Batch a prepared statement with all entries from the args list. Each entry is a batch. The operation completes with the execution of the batch where the async result contains a array of Integers.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sqlStatement` | string | sql statement
`args` | Array.<todo> | the prepared statement arguments
`handler` | function | the result handler

Source:
  - vertx-sql-js/sql_connection.js, line 457

##### Returns:

Type
  SQLConnection

#### call(sql, resultHandler) → {SQLConnection}

Calls the given SQL `PROCEDURE` which returns the result from the procedure.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `{call getEmpName}`.
`resultHandler` | function | the handler which is called once the operation completes. It will return a `ResultSet`.

Source:
  - vertx-sql-js/sql_connection.js, line 299

##### Returns:

Type
  SQLConnection

#### callWithParams(sql, params, outputs, resultHandler) → {SQLConnection}

Calls the given SQL `PROCEDURE` which returns the result from the procedure. The index of params and outputs are important for both arrays, for example when dealing with a prodecure that takes the first 2 arguments as input values and the 3 arg as an output then the arrays should be like:

         params = [VALUE1, VALUE2, null]
         outputs = [null, null, "VARCHAR"]

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `{call getEmpName (?, ?)}`.
`params` | todo | these are the parameters to fill the statement.
`outputs` | todo | these are the outputs to fill the statement.
`resultHandler` | function | the handler which is called once the operation completes. It will return a `ResultSet`.

Source:
  - vertx-sql-js/sql_connection.js, line 331

##### Returns:

Type
  SQLConnection

#### close(handler)

Closes the connection. Important to always close the connection when you are done so it's returned to the pool.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler called when this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 351

#### commit(handler) → {SQLConnection}

Commits all changes made since the previous commit/rollback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler called when this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 373

##### Returns:

Type
  SQLConnection

#### execute(sql, resultHandler) → {SQLConnection}

Executes the given SQL statement

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `CREATE TABLE IF EXISTS table ...`
`resultHandler` | function | the handler which is called once this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 140

##### Returns:

Type
  SQLConnection

#### getTransactionIsolation(handler) → {SQLConnection}

Attempts to return the transaction isolation level for this Connection object to the one given.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler called when this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 528

##### Returns:

Type
  SQLConnection

#### query(sql, resultHandler) → {SQLConnection}

Executes the given SQL `SELECT` statement which returns the results of the query.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
`resultHandler` | function | the handler which is called once the operation completes. It will return a `ResultSet`.

Source:
  - vertx-sql-js/sql_connection.js, line 162

##### Returns:

Type
  SQLConnection

#### querySingle(sql, handler) → {SQLOperations}

Execute a one shot SQL statement that returns a single SQL row. This method will reduce the boilerplate code by getting a connection from the pool (this object) and return it back after the execution. Only the first result from the result set is returned.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the statement to execute
`handler` | function | the result handler

Source:
  - vertx-sql-js/sql_connection.js, line 50

##### Returns:

self

Type
  SQLOperations

#### querySingleWithParams(sql, arguments, handler) → {SQLOperations}

Execute a one shot SQL statement with arguments that returns a single SQL row. This method will reduce the boilerplate code by getting a connection from the pool (this object) and return it back after the execution. Only the first result from the result set is returned.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the statement to execute
`arguments` | todo | the arguments
`handler` | function | the result handler

Source:
  - vertx-sql-js/sql_connection.js, line 75

##### Returns:

self

Type
  SQLOperations

#### queryStream(sql, handler) → {SQLConnection}

Executes the given SQL `SELECT` statement which returns the results of the query as a read stream.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
`handler` | function | the handler which is called once the operation completes. It will return a `SQLRowStream`.

Source:
  - vertx-sql-js/sql_connection.js, line 184

##### Returns:

Type
  SQLConnection

#### queryStreamWithParams(sql, params, handler) → {SQLConnection}

Executes the given SQL `SELECT` statement which returns the results of the query as a read stream.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
`params` | todo | these are the parameters to fill the statement.
`handler` | function | the handler which is called once the operation completes. It will return a `SQLRowStream`.

Source:
  - vertx-sql-js/sql_connection.js, line 230

##### Returns:

Type
  SQLConnection

#### queryWithParams(sql, params, resultHandler) → {SQLConnection}

Executes the given SQL `SELECT` prepared statement which returns the results of the query.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `SELECT * FROM table ...`.
`params` | todo | these are the parameters to fill the statement.
`resultHandler` | function | the handler which is called once the operation completes. It will return a `ResultSet`.

Source:
  - vertx-sql-js/sql_connection.js, line 207

##### Returns:

Type
  SQLConnection

#### rollback(handler) → {SQLConnection}

Rolls back all changes made since the previous commit/rollback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler called when this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 394

##### Returns:

Type
  SQLConnection

#### setAutoCommit(autoCommit, resultHandler) → {SQLConnection}

Sets the auto commit flag for this connection. True by default.

##### Parameters:

Name | Type | Description
--- | --- | ---
`autoCommit` | boolean | the autoCommit flag, true by default.
`resultHandler` | function | the handler which is called once this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 118

##### Returns:

Type
  SQLConnection

#### setOptions(options) → {SQLConnection}

Sets the desired options to be applied to the current connection when statements are executed. The options are not applied globally but applicable to the current connection. For example changing the transaction isolation level will only affect statements run on this connection and not future or current connections acquired from the connection pool. This method is not async in nature since the apply will only happen at the moment a query is run.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | the options to modify the unwrapped connection.

Source:
  - vertx-sql-js/sql_connection.js, line 102

##### Returns:

Type
  SQLConnection

#### setQueryTimeout(timeoutInSeconds) → {SQLConnection}

Sets a connection wide query timeout. It can be over written at any time and becomes active on the next query call.

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeoutInSeconds` | number | the max amount of seconds the query can take to execute.

Source:
  - vertx-sql-js/sql_connection.js, line 417

##### Returns:

Type
  SQLConnection

#### setTransactionIsolation(isolation, handler) → {SQLConnection}

Attempts to change the transaction isolation level for this Connection object to the one given. The constants defined in the interface Connection are the possible transaction isolation levels.

##### Parameters:

Name | Type | Description
--- | --- | ---
`isolation` | Object | the level of isolation
`handler` | function | the handler called when this operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 507

##### Returns:

Type
  SQLConnection

#### update(sql, resultHandler) → {SQLConnection}

Executes the given SQL statement which may be an `INSERT`, `UPDATE`, or `DELETE` statement.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `INSERT INTO table ...`
`resultHandler` | function | the handler which is called once the operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 253

##### Returns:

Type
  SQLConnection

#### updateWithParams(sql, params, resultHandler) → {SQLConnection}

Executes the given prepared statement which may be an `INSERT`, `UPDATE`, or `DELETE` statement with the given parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`sql` | string | the SQL to execute. For example `INSERT INTO table ...`
`params` | todo | these are the parameters to fill the statement.
`resultHandler` | function | the handler which is called once the operation completes.

Source:
  - vertx-sql-js/sql_connection.js, line 277

##### Returns:

Type
  SQLConnection