The global sql
function allows you to query external databases. Supported databases are MySQL and PostgreSQL. The function signature is:
declare const sql: (
server: string,
query: string,
args?: (string | number | boolean)[]
) => Promise<{
id?: number;
affectedRows?: number;
rows: { [k: string]: any }[];
}>;
The server
is either the name of a suitable secret, or a connection string. Examples of connection strings are:
mysql://username:password@hostname/dbname
postgres://username:password@hostname/dbname
Query parameters are provided in the query using question marks ("?"). This applies to both MySQL and PostgreSQL. You must provide the respective values in the same order to the args
parameter of the sql
function.