Skip to content

API Statement

Michael Anderson edited this page Dec 13, 2017 · 2 revisions

A Statement takes an SQL expression as a string and makes it executable or queryable against a database table.

Syntax

connection.createStatement( sql : string )

Arguments

Parameter Type Description
sql string The SQL expression used to form the statement.

Methods

query

Sends a query to the database after escaping and substituting any parameters passed in.

Syntax

statement.query( ...args: Array<any> ) => Promise<Array<any>>

Arguments

Parameter Type Description
args Array<any> A rest parameter array of values to be substituted for the ? tokens in the SQL.
The number of parameters must match the number of ? tokens.

Returns

Type Description
Promise<Array<Object>> An arry of database rows represented as JSON objects.

prepare

Prepares the statement to receive parameters.

Syntax

statement.prepare()

Returns

Type Description
void

execute

Executes a statement on the database after escaping and substituting any parameters passed in.

Syntax

statement.execute( ...args: Array<any> ) => any

Arguments

Parameter Type Description
args Array<any> A rest parameter array of values to be substituted for the ? tokens in the SQL.
The number of parameters must match the number of ? tokens.

Returns

Type Description
Promise<Any> If the underlying driver returns anything, it will be returned in a promise.
Not all drivers or databases have a return from an execute.