SQL Generator
Using the endpoint
Use the SQL endpoint to integrate SQL generation in your own applications. For example, you can use it to add a natural language interface to your own database.
POST https://app.text2sql.co/api/v1/sql
Authentication
Set the following headers when making requests to the endpoint:
{
"Content-Type": "application/json",
"Authorization": "Bearer <API_KEY>"
}
Replace the API_KEY with your own generated key.
Input
The endpoint expects the following inputs to be provided:
{
"query": string,
"dialect": string,
"tables": Tables[],
}
You specify the SQL dialect you want outputting as one of the following:
- ansi_sql for ANSI SQL
- pg_sql for Postgres SQL
- t_sql for Transact SQL
- bq_sql for Bigquery
- snowflake_sql for Snowflake
Tables are specified using the following structure:
// Table
{
"name": string,
"columns": string[],
}
Output
The SQL endpoint will return your generated SQL in the following format:
{
"data": {
"id": string,
"sql": string,
"dialect": string
}
}
SQL Converter beta
Using the endpoint
Use the SQL endpoint to run SQL conversions in your own applications. For example, you can use it to speed up your database migrations by converting your existing SQL queries to your target dialect.
POST https://app.text2sql.co/api/v1/convert
Authentication
Set the following headers when making requests to the endpoint:
{
"Content-Type": "application/json",
"Authorization": "Bearer <API_KEY>"
}
Replace the API_KEY with your own generated key.
Input
The endpoint expects the following inputs to be provided:
{
"query": string,
"fromDialect": string, // The dialect to convert from
"toDialect": string, // The dialect to convert to i.e. the output dialect
}
Specify both the from and to dialect using the following codes:
- ansi_sql for ANSI SQL
- pg_sql for Postgres SQL
- t_sql for Transact SQL
- bq_sql for Bigquery
- snowflake_sql for Snowflake
Output
The SQL endpoint will return your converted SQL in the following format:
{
"data": {
"id": string,
"sql": string,
"dialect": string
}
}