Client: Client

Isolated

Represents a MySQL database client.

Constructor

Initializes the MySQL Client.

init (string host, string? user, string? password, string? database, int port, Options? options, ConnectionPool? connectionPool)
  • host string "localhost"
  • Hostname of the MySQL server

  • user string? ()
  • If the MySQL server is secured, the username

  • password string? ()
  • The password of the MySQL server for the provided username

  • database string? ()
  • The name of the database

  • port int 3306
  • Port number of the MySQL server

  • options Options? ()
  • MySQL database options

  • connectionPool ConnectionPool? ()
  • The sql:ConnectionPool to be used for the connection. If there is no connectionPool provided, the global connection pool (shared by all clients) will be used

Remote Methods

query

Executes the query, which may return multiple results.

queryRow

Executes the query, which is expected to return at most one row of the result.

execute

Executes the SQL query.

batchExecute

Executes an SQL query with multiple sets of parameters in a batch.

call

Executes an SQL query, which calls a stored procedure.

Methods

close

Closes the MySQL client and shuts down the connection pool.

query

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

Executes the query, which may return multiple results.

Parameters

  • sqlQuery ParameterizedQuery
  • The SQL query such as `SELECT * from Album WHERE name=${albumName}`

  • rowType typedesc<record {}> (default <>)
  • The typedesc of the record to which the result needs to be returned

Return Type

(stream<rowType, Error?>)

Stream of records in the rowType type

queryRow

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

Executes the query, which is expected to return at most one row of the result. If the query does not return any results, sql:NoRowsError is returned.

Parameters

  • sqlQuery ParameterizedQuery
  • The SQL query such as `SELECT * from Album WHERE name=${albumName}`

  • returnType typedesc<anydata> (default <>)
  • The typedesc of the record to which the result needs to be returned. It can be a basic type if the query result contains only one column

Return Type

(returnType | Error)

Result in the returnType type or an sql:Error

execute

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

Executes the SQL query. Only the metadata of the execution is returned (not the results from the query).

Parameters

  • sqlQuery ParameterizedQuery
  • The SQL query such as `DELETE FROM Album WHERE artist=${artistName}`

Return Type

(ExecutionResult | Error)

Metadata of the query execution as an sql:ExecutionResult or an sql:Error

batchExecute

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

Executes an SQL query with multiple sets of parameters in a batch. Only the metadata of the execution is returned (not results from the query). If one of the commands in the batch fails (except syntax error), the sql:BatchExecuteError will be deferred until the remaining commands are completed.

Parameters

Return Type

(ExecutionResult[ ] | Error)

Metadata of the query execution as an sql:ExecutionResult[] or an sql:Error

call

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

Executes an SQL query, which calls a stored procedure. This may or may not return results.

Parameters

  • rowTypes typedesc<record {}>[ ] (default [])
  • typedesc array of the records to which the results need to be returned

Return Type

(ProcedureCallResult | Error)

Summary of the execution and results are returned in an sql:ProcedureCallResult, or an sql:Error

close

function close() returns Error?
Isolated Function

Closes the MySQL client and shuts down the connection pool.

Return Type

(Error?)

Possible sql:Error when closing the client