The API uses JSON requests to describe database operations.
A request contains the controller and action to execute, along with the information required by the query builder.
This document describes the request structure and the fields currently used by the query layer.
For practical requests, see Query Examples.
{
"controller": "Query",
"action": "select",
"table": "CustomerTable",
"columns": [
"Cust_Name",
"Phone"
]
}| Field | Type | Description |
|---|---|---|
controller |
string | Controller that handles the request |
action |
string | Action to execute |
table |
string/object | Main table used by the query |
columns |
array | Columns or expressions to select |
where |
array | Filtering conditions |
joins |
array | JOIN definitions |
groupBy |
array | GROUP BY columns |
having |
array | HAVING conditions |
orderBy |
array | Result ordering |
page |
integer | Requested page |
pageSize |
integer | Number of rows per page |
The exact accepted structure is determined by the current query builder and validation layer. Do not add fields to a request unless they are supported by the implementation.
Identifies the controller that should process the request.
Example:
{
"controller": "Query"
}A normal query request uses:
{
"controller": "Query"
}Identifies the operation to execute.
Example:
{
"action": "select"
}The controller and action are normally supplied together:
{
"controller": "Query",
"action": "select"
}Defines the main table used by the query.
Simple form:
{
"table": "CustomerTable"
}When aliases are supported by the request structure, the table can also carry an alias.
Example:
{
"table": {
"name": "CustomerTable",
"alias": "C"
}
}Use the structure supported by the current request builder.
Defines the columns returned by the query.
Simple columns:
{
"columns": [
"Cust_Name",
"Phone",
"City"
]
}Qualified columns can be used when working with table names or aliases:
{
"columns": [
"C.Cust_Name"
]
}A column can be given an output alias.
Example:
{
"columns": [
{
"column": "Cust_Name",
"alias": "CustomerName"
}
]
}The resulting SQL is conceptually:
SELECT
Cust_Name AS CustomerName
FROM CustomerTable;The query builder supports function-based expressions.
Example:
{
"columns": [
{
"function": "SUM",
"column": "Amount",
"alias": "TotalAmount"
}
]
}The resulting SQL is conceptually:
SELECT
SUM(Amount) AS TotalAmount
FROM SalesTable;The current query implementation includes aggregate functions such as:
COUNT
SUM
AVG
MIN
MAX
UPPER
LOWER
LTRIM
RTRIM
TRIM
LEN
YEAR
MONTH
DAY
DATEPART
DATENAME
GETDATE
ABS
ROUND
CEILING
FLOOR
POWER
SQRT
EXP
LOG
Refer to Query Examples for usage examples.
where defines filtering conditions.
A condition is represented using:
left
operator
right
Example:
{
"where": [
{
"left": {
"column": "Status"
},
"operator": "=",
"right": "Active"
}
]
}Conceptually:
WHERE Status = 'Active'Multiple conditions can be supplied through the where array.
Example:
{
"where": [
{
"left": {
"column": "Status"
},
"operator": "=",
"right": "Active"
},
{
"left": {
"column": "City"
},
"operator": "=",
"right": "Bangalore"
}
]
}The exact logical combination of conditions should follow the behavior implemented by the current query builder.
The query builder validates operators before they are used in generated SQL.
Common SQL comparison operators include:
=
<>
!=
>
<
>=
<=
Additional operators should only be used when supported by the current implementation.
The query builder supports structured expressions.
Example:
{
"expression": {
"left": {
"column": "Amount"
},
"operator": "+",
"right": 100
}
}Expressions can be used where the query builder accepts expression objects.
JOIN definitions are supplied through joins.
Example:
{
"joins": [
{
"type": "INNER",
"table": "InvoiceTable",
"on": {
"left": "CustomerTable.Cust_ID",
"right": "InvoiceTable.Cust_ID"
}
}
]
}Conceptually:
INNER JOIN InvoiceTable
ON CustomerTable.Cust_ID = InvoiceTable.Cust_IDThe query builder supports JOIN types defined by its validation rules.
Common examples are:
INNER
LEFT
RIGHT
Use the exact JOIN type accepted by the current implementation.
Aliases allow tables to be referenced using shorter qualified names.
Example:
{
"table": {
"name": "CustomerTable",
"alias": "C"
}
}A column can then be referenced as:
C.Cust_Name
Aliases are especially useful when multiple tables contain columns with the same name.
groupBy defines the columns used for grouping.
Example:
{
"groupBy": [
"City"
]
}Combined example:
{
"columns": [
"City",
{
"function": "SUM",
"column": "Amount",
"alias": "TotalSales"
}
],
"groupBy": [
"City"
]
}Conceptually:
SELECT
City,
SUM(Amount) AS TotalSales
FROM SalesTable
GROUP BY City;having applies conditions to grouped results.
Example:
{
"having": [
{
"left": {
"function": "SUM",
"column": "Amount"
},
"operator": ">",
"right": 50000
}
]
}Conceptually:
HAVING SUM(Amount) > 50000HAVING is normally used together with GROUP BY.
orderBy controls the result ordering.
Example:
{
"orderBy": [
{
"column": "Cust_Name",
"direction": "ASC"
}
]
}Descending order:
{
"orderBy": [
{
"column": "Cust_Name",
"direction": "DESC"
}
]
}Supported directions are:
ASC
DESC
Pagination is controlled using:
page
pageSize
Example:
{
"page": 2,
"pageSize": 25
}The query layer calculates the required offset.
The current SQL Server implementation uses SQL Server pagination syntax internally.
Conceptually:
ORDER BY ...
OFFSET ... ROWS
FETCH NEXT ... ROWS ONLYThe client only needs to provide the page information.
Values used by query conditions are passed through the query execution layer.
The execution layer supports prepared ODBC statements.
Conceptually:
JSON Request
|
v
Query Builder
|
+-- SQL
|
+-- Values
|
v
Prepared Statement
|
v
ODBC Execute
This keeps values separate from the generated SQL where prepared execution is used.
The following combines several query components:
{
"controller": "Query",
"action": "select",
"table": "SalesTable",
"columns": [
"City",
{
"function": "SUM",
"column": "Amount",
"alias": "TotalSales"
}
],
"where": [
{
"left": {
"column": "Status"
},
"operator": "=",
"right": "Completed"
}
],
"groupBy": [
"City"
],
"having": [
{
"left": {
"function": "SUM",
"column": "Amount"
},
"operator": ">",
"right": 50000
}
],
"orderBy": [
{
"column": "TotalSales",
"direction": "DESC"
}
],
"page": 1,
"pageSize": 20
}The request is validated before execution.
Validation can cover:
- Request structure
- Tables
- Columns
- Functions
- Operators
- JOINs
- Aliases
- Sort directions
- Query properties
Invalid requests should be rejected before they reach the database.
This document describes the request contract.
It does not describe how the SQL is internally generated or executed.
For internal implementation details, see:
For HTTP usage, see:
For copy/paste requests, see:
For database connection settings, see: