This document contains practical examples demonstrating how to use the Generic SQL API Framework.
Each example includes:
- JSON Request
- Generated SQL
- Expected Response where applicable
These examples are intended as a quick reference for developers integrating applications with the API.
For the complete JSON request structure, see JSON Request Reference.
For the HTTP API itself, see API.
{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name",
"Phone"
]
}SELECT
Cust_Name,
Phone
FROM CustomerTable;{
"success": true,
"rowsReturned": 2,
"data": [
{
"Cust_Name": "ABC Traders",
"Phone": "9876543210"
},
{
"Cust_Name": "XYZ Enterprises",
"Phone": "9988776655"
}
]
}{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name",
"City"
],
"where": [
{
"column": "City",
"operator": "=",
"value": "Bangalore"
}
]
}SELECT
Cust_Name,
City
FROM CustomerTable
WHERE City = ?;The value is passed separately to the prepared statement.
{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name",
"Balance"
],
"orderBy": [
{
"column": "Balance",
"direction": "DESC"
}
]
}SELECT
Cust_Name,
Balance
FROM CustomerTable
ORDER BY Balance DESC;{
"controller": "Query",
"action": "select",
"table": "SalesTable",
"columns": [
"City",
{
"function": "COUNT",
"column": "InvoiceNo",
"alias": "Invoices"
}
],
"groupBy": [
"City"
]
}SELECT
City,
COUNT(InvoiceNo) AS Invoices
FROM SalesTable
GROUP BY City;{
"controller": "Query",
"action": "select",
"table": "SalesTable",
"columns": [
"City",
{
"function": "SUM",
"column": "Amount",
"alias": "TotalSales"
}
],
"groupBy": [
"City"
],
"having": [
{
"function": "SUM",
"column": "Amount",
"operator": ">",
"value": 100000
}
]
}SELECT
City,
SUM(Amount) AS TotalSales
FROM SalesTable
GROUP BY City
HAVING SUM(Amount) > ?;The value is passed separately to the prepared statement.
{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"CustomerTable.Cust_Name",
"InvoiceTable.InvoiceNo"
],
"joins": [
{
"type": "INNER",
"table": "InvoiceTable",
"on": {
"left": "CustomerTable.Cust_ID",
"right": "InvoiceTable.Cust_ID"
}
}
]
}SELECT
CustomerTable.Cust_Name,
InvoiceTable.InvoiceNo
FROM CustomerTable
INNER JOIN InvoiceTable
ON CustomerTable.Cust_ID = InvoiceTable.Cust_ID;{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name"
],
"pagination": {
"page": 2,
"pageSize": 20
}
}The SQL Server query uses pagination based on the requested page and page size.
Conceptually:
SELECT
Cust_Name
FROM CustomerTable
ORDER BY <column>
OFFSET 20 ROWS
FETCH NEXT 20 ROWS ONLY;The actual generated SQL depends on the query builder's ordering and pagination requirements.
{
"controller": "Query",
"action": "select",
"table": "SalesTable",
"columns": [
{
"function": "SUM",
"column": "Amount",
"alias": "TotalSales"
},
{
"function": "AVG",
"column": "Amount",
"alias": "AverageSales"
}
]
}SELECT
SUM(Amount) AS TotalSales,
AVG(Amount) AS AverageSales
FROM SalesTable;{
"controller": "Query",
"action": "select",
"table": "SalesTable",
"columns": [
"City",
{
"function": "SUM",
"column": "Amount",
"alias": "TotalSales"
}
],
"where": [
{
"column": "Status",
"operator": "=",
"value": "Completed"
}
],
"groupBy": [
"City"
],
"having": [
{
"function": "SUM",
"column": "Amount",
"operator": ">",
"value": 50000
}
],
"orderBy": [
{
"column": "TotalSales",
"direction": "DESC"
}
],
"pagination": {
"page": 1,
"pageSize": 10
}
}This request combines:
WHERE
|
v
GROUP BY
|
v
HAVING
|
v
ORDER BY
|
v
PAGINATION
It is useful as an example of combining multiple query components in a single request.
The API request can combine filtering and sorting without requiring separate endpoints.
{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name",
"City",
"Balance"
],
"where": [
{
"column": "City",
"operator": "=",
"value": "Bangalore"
}
],
"orderBy": [
{
"column": "Balance",
"direction": "DESC"
}
]
}SELECT
Cust_Name,
City,
Balance
FROM CustomerTable
WHERE City = ?
ORDER BY Balance DESC;Values supplied through conditions are represented as parameters in generated SQL.
For example:
{
"where": [
{
"column": "City",
"operator": "=",
"value": "Bangalore"
}
]
}can produce:
WHERE City = ?The actual value is supplied separately during query execution.
This allows the database execution layer to use prepared ODBC statements instead of directly inserting request values into the SQL string.
The examples demonstrate the following request components:
| Component | Purpose |
|---|---|
controller |
Selects the controller |
action |
Selects the operation |
table |
Defines the main table |
columns |
Defines selected columns and expressions |
where |
Filters rows |
joins |
Joins tables |
groupBy |
Groups results |
having |
Filters grouped results |
orderBy |
Sorts results |
pagination |
Controls result pagination |
Examples for additional operations will be added when those features are implemented.
Planned areas include:
- INSERT
- UPDATE
- DELETE
- UPSERT
- Stored Procedures
- Transactions
These should only be documented as supported examples after the corresponding backend functionality is implemented.
These examples demonstrate the query capabilities currently documented for the Generic SQL API Framework.
The examples should always match the request structure implemented by the current query builder and validation layer.
When the API contract changes, update this document together with JSON Request Reference.