Statement <T>

A statement generated by Database.prepare used to prepare SQL with ? bindings

Type parameters

Name
T

Table of contents

Constructors

Properties

Methods

Constructors

constructor

• new Statement<T>(database, sql, ...params): Statement<T>

Type parameters

Name
T

Parameters

NameType
databaseDatabase
sqlstring
...paramsany[]

Returns

Statement<T>

Defined in

src/drivers/statement.ts:13

Properties

_database

• Private _database: Database

Statement belongs to this database

Defined in

src/drivers/statement.ts:25


_preparedSql

• Private Optional _preparedSql: string

The SQL statement with binding values applied

Defined in

src/drivers/statement.ts:31


_sql

• Private _sql: string

The SQL statement with ? binding placeholders

Defined in

src/drivers/statement.ts:28

Methods

all

â–¸ all(callback?): Statement<T>

Binds parameters, executes the statement and calls the callback with all result rows. The function returns the Statement object to allow for function chaining. The parameters are the same as the Statement#run function

Parameters

NameType
callback?RowsCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:121

â–¸ all(params, callback?): Statement<T>

Parameters

NameType
paramsany
callback?RowsCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:122


bind

â–¸ bind(...params): Statement<T>

Binds parameters to the prepared statement and calls the callback when done or when an error occurs. The function returns the Statement object to allow for function chaining. The first and only argument to the callback is null when binding was successful, otherwise it is the error object. Binding parameters with this function completely resets the statement object and row cursor and removes all previously bound parameters, if any. Currently bound parameters are escaped client side and turned into literals before being executed on the server.

Parameters

NameType
...paramsany[]

Returns

Statement<T>

Defined in

src/drivers/statement.ts:42


each

â–¸ each(callback?, complete?): Statement<T>

Binds parameters, executes the statement and calls the callback for each result row. The function returns the Statement object to allow for function chaining. Parameters are the same as the Database#each function.

Parameters

NameType
callback?RowCallback<T>
complete?RowCountCallback

Returns

Statement<T>

Defined in

src/drivers/statement.ts:147

â–¸ each(params, callback?, complete?): Statement<T>

Parameters

NameType
paramsany
callback?RowCallback<T>
complete?RowCountCallback

Returns

Statement<T>

Defined in

src/drivers/statement.ts:148


get

â–¸ get(callback?): Statement<T>

Binds parameters, executes the statement and retrieves the first result row. The function returns the Statement object to allow for function chaining. The parameters are the same as the Statement#run function, with the following differences: The signature of the callback is function(err, row) {}. If the result set is empty, the second parameter is undefined, otherwise it is an object containing the values for the first row.

Parameters

NameType
callback?RowCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:95

â–¸ get(params, callback?): Statement<T>

Parameters

NameType
paramsany
callback?RowCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:96


run

â–¸ run(callback?): Statement<T>

Binds parameters and executes the statement. The function returns the Statement object to allow for function chaining. If you specify bind parameters, they will be bound to the statement before it is executed. Note that the bindings and the row cursor are reset when you specify even a single bind parameter. The callback behavior is identical to the Database#run method with the difference that the statement will not be finalized after it is run. This means you can run it multiple times.

Parameters

NameType
callback?ResultsCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:66

â–¸ run(params, callback?): Statement<T>

Parameters

NameType
paramsany
callback?ResultsCallback<T>

Returns

Statement<T>

Defined in

src/drivers/statement.ts:67