Execute built-ins

Perform common operations using Airplane built-ins
The Airplane SDK provides convenient wrappers for common operations such as SQL queries, REST requests, and sending Slack messages.
We've included examples of the three most common built-in operations below. To view the full list of built-ins, see Built-ins.

Query a SQL database

javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "get_user",
6
resources: ["my_sql_db"],
7
},
8
async () => {
9
const run = await airplane.sql.query(
10
"my_sql_db", // The slug of the SQL resource to query.
11
"SELECT * FROM users" // The SQL query to execute.
12
);
13
return run.output;
14
}
15
);
To learn more, read the SQL built-in reference.

Perform an API request

javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "fetch_users",
6
resources: ["my_rest_api"],
7
},
8
async (params) => {
9
const run = await airplane.rest.request(
10
"my_rest_api", // The slug of the REST resource to request.
11
"GET", // GET, POST, etc.
12
`/user?id=${params.id}` // The URL path to request.
13
);
14
return run.output;
15
}
16
);
To learn more, read the REST built-in reference.

Send a Slack message

javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "slack_on_call",
6
},
7
async (params) => {
8
await airplane.slack.message(
9
"#eng", // The Slack channel name to message.
10
`@eng-oncall: deadlock detected⁠—please review:\n${getDeadlockDesc()}`
11
);
12
}
13
);
To learn more, read the Slack built-in reference.