-
Notifications
You must be signed in to change notification settings - Fork 0
Validation Engine
The Generic SQL API Framework includes a built-in validation engine that verifies every request before executing a SQL query. This helps prevent invalid requests, improve reliability, and reduce runtime errors.
Every request follows this validation process:
Client Request
│
▼
JSON Validation
│
▼
Query Validation
│
▼
Parameter Validation
│
▼
Security Checks
│
▼
Execute SQL
│
▼
Return Response
The framework first validates the incoming JSON request.
Example:
{
"query": "customers"
}Checks performed:
- Request is valid JSON
- Required properties exist
- Property names are valid
- Request is not empty
The framework verifies that the requested SQL file exists.
Example:
{
"query": "customers"
}The framework checks:
queries/customers.sql
If the file does not exist:
{
"success": false,
"message": "Query file not found."
}Parameterized queries require matching input values.
SQL:
SELECT *
FROM CustomerTable
WHERE CustomerID = :CustomerID;JSON:
{
"query": "customer_by_id",
"parameters": {
"CustomerID": 101
}
}If a required parameter is missing:
{
"success": false,
"message": "Missing required parameter: CustomerID"
}The framework validates parameter types before execution.
Example:
{
"parameters": {
"CustomerID": "ABC"
}
}If the query expects an integer, validation fails.
The framework validates pagination values.
Example:
{
"pagination": {
"page": 1,
"pageSize": 50
}
}Validation rules:
- Page must be greater than 0
- Page size must be greater than 0
- Maximum page size depends on framework configuration
Example:
{
"sorting": {
"column": "CustomerName",
"direction": "ASC"
}
}Checks:
- Column exists
- Direction is either ASC or DESC
Example:
{
"filters": {
"City": "Bangalore"
}
}Validation includes:
- Allowed filter fields
- Supported operators
- Valid values
Before executing SQL, the framework performs security checks such as:
- Preventing SQL injection through parameterized queries
- Rejecting invalid or malformed requests
- Restricting execution to registered SQL files
Successful validation:
{
"success": true
}Validation error:
{
"success": false,
"message": "Validation failed."
}- Always use parameterized queries.
- Validate user input before sending requests.
- Use meaningful parameter names.
- Keep SQL queries simple and maintainable.
- Test validation scenarios during development.
Now that you understand request validation, continue with:
- Query Examples
- Response Format
- Error Handling
- Framework Architecture