POST
/
v1
/
ai
/
sql
import { JigsawStack } from "jigsawstack";

const jigsawstack = JigsawStack({
  apiKey: "your-api-key",
});

const result = await jigsawstack.text_to_sql({
  prompt:
    "Generate a query to get transactions that amount exceed 10000 and sort by when created",
  sql_schema:
    "CREATE TABLE Transactions (transaction_id INT PRIMARY KEY, user_id INT NOT NULL,total_amount DECIMAL(10, 2 NOT NULL, transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,status VARCHAR(20) DEFAULT 'pending',FOREIGN KEY(user_id) REFERENCES Users(user_id))",
});
{
  "success": true,
  "sql": "SELECT t.transaction_id, t.user_id, t.total_amount, t.transaction_date, t.status FROM Transactions t WHERE t.total_amount > 10000 ORDER BY t.transaction_date NULLS LAST;"
}

Body

prompt
string
required

The prompt that will be translated to an SQL query.

sql_schema
string

The database schema where the query will be run. Not required if file_store_key is specified.

file_store_key
string

The key used to store the database schema on Jigsawstack file Storage. Not required if sql_schema is specified.

Either file_store_key or sql_schema can be provided not both.
x-api-key
string
required

Your JigsawStack API key

Response

success
boolean

Indicates whether the call was successful.

import { JigsawStack } from "jigsawstack";

const jigsawstack = JigsawStack({
  apiKey: "your-api-key",
});

const result = await jigsawstack.text_to_sql({
  prompt:
    "Generate a query to get transactions that amount exceed 10000 and sort by when created",
  sql_schema:
    "CREATE TABLE Transactions (transaction_id INT PRIMARY KEY, user_id INT NOT NULL,total_amount DECIMAL(10, 2 NOT NULL, transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,status VARCHAR(20) DEFAULT 'pending',FOREIGN KEY(user_id) REFERENCES Users(user_id))",
});
{
  "success": true,
  "sql": "SELECT t.transaction_id, t.user_id, t.total_amount, t.transaction_date, t.status FROM Transactions t WHERE t.total_amount > 10000 ORDER BY t.transaction_date NULLS LAST;"
}