Object type: Client

Represents a SQL client.

Methods

query

Queries the database with the query provided by the user, and returns the result as a stream.

queryRow

Queries the database with the provided query and returns the first row as a record if the expected return type is a record.

execute

Executes the provided DDL or DML SQL query and returns a summary of the execution.

batchExecute

Executes a provided batch of parameterized DDL or DML SQL queries and returns the summary of the execution.

call

Executes a SQL stored procedure and returns the result as stream and execution summary.

close

Closes the SQL client.

query

function query(ParameterizedQuery sqlQuery, typedesc<record {}> rowType) returns stream<rowType, Error?>
Isolated Function
Remote Function

Queries the database with the query provided by the user, and returns the result as a stream.

Parameters

  • sqlQuery ParameterizedQuery
  • The query, which needs to be executed as an sql:ParameterizedQuery

  • rowType typedesc<record {}> (default <>)
  • The typedesc of the record that should be returned as a result. If this is not provided, the default column names of the query result set will be used for the record attributes

Return Type

(stream<rowType, Error?>)

Stream of records in the type of rowType

queryRow

function queryRow(ParameterizedQuery sqlQuery, typedesc<anydata> returnType) returns returnType | Error
Isolated Function
Remote Function

Queries the database with the provided query and returns the first row as a record if the expected return type is a record. If the expected return type is not a record, then a single value is returned.

Parameters

  • sqlQuery ParameterizedQuery
  • The query to be executed as an sql:ParameterizedQuery, which returns only one result row

  • returnType typedesc<anydata> (default <>)
  • The typedesc of the record/type that should be returned as a result. If this is not provided, the default column names/type of the query result set will be used

Return Type

(returnType | Error)

Result in the returnType type

execute

function execute(ParameterizedQuery sqlQuery) returns ExecutionResult | Error
Isolated Function
Remote Function

Executes the provided DDL or DML SQL query and returns a summary of the execution.

Parameters

  • sqlQuery ParameterizedQuery
  • The DDL or DML query such as INSERT, DELETE, UPDATE, etc. as an sql:ParameterizedQuery

Return Type

(ExecutionResult | Error)

Summary of the SQL update query as an sql:ExecutionResult or an sql:Error if any error occurred when executing the query

batchExecute

function batchExecute(ParameterizedQuery[ ] sqlQueries) returns ExecutionResult[ ] | Error
Isolated Function
Remote Function

Executes a provided batch of parameterized DDL or DML SQL queries and returns the summary of the execution.

Parameters

  • sqlQueries ParameterizedQuery[ ]
  • The DDL or DML queries such as INSERT, DELETE, UPDATE, etc. as an sql:ParameterizedQuery with an array of values passed in

Return Type

(ExecutionResult[ ] | Error)

Summary of the executed SQL queries as an sql:ExecutionResult[], which includes details such as affectedRowCount and lastInsertId. If one of the commands in the batch fails, this function will return an sql:BatchExecuteError. However, the driver may or may not continue to process the remaining commands in the batch after a failure. The summary of the executed queries in case of an error can be accessed as (<sql:BatchExecuteError> result).detail()?.executionResults

call

function call(ParameterizedCallQuery sqlQuery, typedesc<record {}>[ ] rowTypes) returns ProcedureCallResult | Error
Isolated Function
Remote Function

Executes a SQL stored procedure and returns the result as stream and execution summary.

Parameters

  • rowTypes typedesc<record {}>[ ] (default [])
  • The array of typedesc of the records that should be returned as a result. If this is not provided, the default column names of the query result set will be used for the record attributes

Return Type

(ProcedureCallResult | Error)

Summary of the execution is returned in an sql:ProcedureCallResult, or an sql:Error

close

function close() returns Error?
Isolated Function

Closes the SQL client.

Return Type

(Error?)

Possible error when closing the client