Skip to content

API PreparedStatement

Michael Anderson edited this page Dec 13, 2017 · 1 revision

A PreparedStatement takes an SQL expression as a string and makes it executable or queryable against a database table. A PreparedStatement is a Statement that always calls the prepare method in the constructor.

Syntax

connection.prepareStatement( 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.

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.