SQL

Perform SQL queries using the SQL built-in.

Query

Execute a SQL query against a PostgreSQL, MySQL, Microsoft SQL Server, or BigQuery resource.
typescript
Copied
1
export default airplane.task(
2
{
3
slug: "find_user_by_name",
4
// Attach SQL resource to task
5
resources: ["my_sql_db"],
6
parameters: { name: "shorttext" },
7
},
8
async (params) => {
9
const run = await airplane.sql.query<{ id: string; name: string; email: string }>(
10
// The slug of the SQL resource to query
11
"my_sql_db",
12
// SQL query to execute
13
"select * from users where name ilike :name",
14
// Query arguments
15
{ args: { name: `%${params.name}%` } }
16
);
17
return run.output.Q1;
18
}
19
);
To protect against SQL injection, it is heavily encouraged that all user-provided input is passed as a query argument. Each query argument has a unique identifier that can be referenced from the query by prepending the identifier with a semicolon. For example, the following query has a query arg identified by name:
sql
Copied
1
-- Query
2
select * from users
3
where name ilike :name;
4
-- Query Args
5
{ "name": "%colin%" }
API