Edge SQL API
The Edge SQL API provides an interface for interacting with an EdgeSQL database from Edge Functions running on the Azion Edge Platform. This document outlines the key components of the API and provides code samples for each.
Go to Edge SQL referenceDatabase
Creates a connection to an EdgeSQL database for your application. Returns a Connection type object.
Methods
Method | Description | Signature | Parameters | Return |
---|---|---|---|---|
Open | Opens a connection to the read replica of an EdgeSQL database | static async open(name) | name: string | Connection |
Connection
Represents the communication channel with a specific EdgeSQL database. This object can be obtained by opening a database.
Methods
Method | Description | Signature | Parameters | Return |
---|---|---|---|---|
Execute | Executes an SQL command | async execute(sql,params) | sql: <string> - '?' positional parameter - :<param_name> params: - Array of positional values - Dictionary of values | - |
Query | Executes an SQL command | async query(sql, params) | sql: <string> - '?' positional parameter - :<param_name> params: - Array of positional values - Dictionary of values | Rows |
Prepare | Prepares an SQL command for execution from the combination of the command and parameters | async prepare(sql,params) | sql: <string> - '?' positional parameter - :<param_name> params: - Array of positional values - Dictionary of values | Statement |
Statement
An abstraction of an SQL command, the Statement object allows for the execution of the represented command. It can be created from a Connection.prepare
command.
Methods
Method | Description | Signature | Parameters | Return |
---|---|---|---|---|
Execute | Executes an SQL command | async execute(sql, params) | sql: <string> - '?' positional parameter - :<param_name> params: - Array of positional values - Dictionary of values | - |
Query | Executes an SQL command | async query(sql, params) | sql: <string> - '?' positional parameter - :<param_name> params: - Array of positional values - Dictionary of values | Rows |
Attributes
Attribute | Description | Signature | Parameters | Return |
---|---|---|---|---|
parameterCount | Returns the number of parameters related of statement | parameterCount() | - | int32 |
parameterName | Returns the name of parameter | parameterName(index) | index: int32 | String |
columns | Returns the list of columns related of the statement | columns() | - | Object |
Rows
Represents the result set returned by an SQL query.
Methods
Method | Description | Signature | Parameters | Return |
---|---|---|---|---|
next | Returns the next line of the query response | async next() | - | <Row> or null |
Attributes
Attribute | Description | Signature | Parameters | Return |
---|---|---|---|---|
columnCount | Returns the number of columns from the query result | columnCount() | - | int32 |
columnName | Returns the column’s name | parameterName(index) | index: int32 | String |
columnType | Returns the column’s type | columnType(index) | index: int32 | int32 |
Row
Represents the set of attributes and values in a row of a result set.
Attributes
Attribute | Description | Signature | Parameters | Return |
---|---|---|---|---|
columnName | Returns the column’s name | columnName(index) | index: int32 | String |
columnType | Returns the column’s type | ColumnType(index) | index: int32 | int32 |
getValue | Returns the attribute value | getValue(index) | index: int32 | Value |
getString | Returns the attribute value as string | getString(index) | index: int32 | String |
Code sample
The code sample shown below presents a way to interact with a database and retrieve data from a table. This example uses a db called mydatabase
and the table users
.
Considering the database and table both exist, the output would be: