Raw SQL queries

We're developing January, a comprehensive platform that enables you to build, integrate, test, and deploy APIs all in one place.Try it for free in the playground and have an API that you can share in seconds.

Building on the work we did with custom action, we've now added support for raw SQL queries in the database extension (PostgreSQL).

workflow('GetUserProfileWorkflow', {
tag: 'users',
trigger: trigger.http({
method: 'post',
path: '/',
}),
actions: {
addUser: trigger =>
action.database.sql({
query: `
SELECT * FROM users
WHERE email = '${trigger.body.email}'
JOIN profiles ON users.id = profiles.userId
`,
}),
},
});

Only select statements are supported and you may use the semantic actions like action.database.insert and others for other operations.

You don't have to worry about SQL injection attacks, as the query will be serialized using tag functions before being executed.

The above action will essentially be converted to:

const serialized = sql`
SELECT * FROM users
WHERE email = '${email}'
JOIN profiles ON users.id = profiles.userId`;
dataSource.query(serialized.sql, serialized.values);
We're gathering insights around API development and looking forward for your contribution in the survey.
Reading Time
1 min read