API Reference
This document provides technical details about the SQL Prettify tool's functionality and implementation.
Tool Configuration
Formatting Options
The tool accepts the following configuration options:
interface FormattingOptions {
indentSize: number; // 2, 4, or 8 spaces
keywordCase: 'upper' | 'lower' | 'preserve';
uppercaseKeywords: boolean;
uppercaseFunctions: boolean;
uppercaseDataTypes: boolean;
alignCommas: boolean;
breakBeforeBooleanOperator: boolean;
}
Default Configuration
const defaultOptions: FormattingOptions = {
indentSize: 2,
keywordCase: 'upper',
uppercaseKeywords: true,
uppercaseFunctions: true,
uppercaseDataTypes: true,
alignCommas: false,
breakBeforeBooleanOperator: true,
};
Supported SQL Keywords
Data Manipulation Language (DML)
- SELECT: Query data from tables
- INSERT: Insert new records
- UPDATE: Modify existing records
- DELETE: Remove records
Data Definition Language (DDL)
- CREATE: Create database objects
- ALTER: Modify database objects
- DROP: Remove database objects
- TRUNCATE: Remove all records from a table
Data Control Language (DCL)
- GRANT: Grant permissions
- REVOKE: Revoke permissions
Transaction Control
- COMMIT: Save transaction changes
- ROLLBACK: Undo transaction changes
- SAVEPOINT: Create savepoints
Supported SQL Functions
Aggregate Functions
- COUNT: Count rows or non-null values
- SUM: Calculate sum of values
- AVG: Calculate average of values
- MIN: Find minimum value
- MAX: Find maximum value
String Functions
- UPPER: Convert to uppercase
- LOWER: Convert to lowercase
- LENGTH: Get string length
- SUBSTRING: Extract substring
- CONCAT: Concatenate strings
- TRIM: Remove leading/trailing spaces
Date/Time Functions
- NOW: Get current timestamp
- DATE: Extract date part
- TIME: Extract time part
- YEAR: Extract year
- MONTH: Extract month
- DAY: Extract day
Mathematical Functions
- ROUND: Round to specified decimal places
- FLOOR: Round down to integer
- CEIL: Round up to integer
- ABS: Get absolute value
- SQRT: Calculate square root
- POWER: Raise to power
Supported Data Types
Numeric Types
- INT: Integer values
- INTEGER: Integer values
- BIGINT: Large integer values
- SMALLINT: Small integer values
- TINYINT: Very small integer values
- DECIMAL: Fixed-point decimal
- NUMERIC: Fixed-point decimal
- FLOAT: Floating-point number
- DOUBLE: Double-precision floating-point
- REAL: Single-precision floating-point
String Types
- CHAR: Fixed-length character string
- VARCHAR: Variable-length character string
- TEXT: Large text data
- BLOB: Binary large object
Date/Time Types
- DATE: Date values
- TIME: Time values
- DATETIME: Date and time values
- TIMESTAMP: Timestamp values
Other Types
- BOOLEAN: Boolean values
- BIT: Bit values
- JSON: JSON data
Formatting Rules
Indentation Rules
- SELECT Clauses: Each column on a new line with indentation
- FROM Clauses: Table names with proper indentation
- JOIN Clauses: JOIN conditions with appropriate indentation
- WHERE Clauses: Conditions with proper indentation
- GROUP BY: Grouping columns with indentation
- ORDER BY: Sorting columns with indentation
Case Conversion Rules
- Keywords: Convert to specified case (upper/lower/preserve)
- Functions: Convert function names to specified case
- Data Types: Convert data type names to specified case
- Identifiers: Preserve original case for table/column names
Line Break Rules
- Major Clauses: Break before SELECT, FROM, WHERE, GROUP BY, ORDER BY
- JOIN Clauses: Break before each JOIN type
- Boolean Operators: Break before AND/OR if enabled
- Comma Alignment: Align commas in SELECT lists if enabled
History Management
History Record Structure
interface HistoryRecord {
id: string;
input: string;
output: string;
options: FormattingOptions;
timestamp: number;
}
History Operations
- Add Record: Automatically add new formatting records
- Delete Record: Remove specific history entries
- Clear History: Remove all history records
- Load Record: Restore SQL and options from history
Storage Limits
- Maximum Records: 50 history records
- Storage Location: Browser local storage
- Persistence: Data persists across browser sessions
Error Handling
Common Errors
- Invalid SQL Syntax: Malformed SQL queries
- Unsupported Constructs: SQL features not supported by formatter
- Large Queries: Queries exceeding processing limits
- Browser Limitations: Local storage or memory constraints
Error Recovery
- Syntax Validation: Basic SQL syntax checking
- Graceful Degradation: Partial formatting for complex queries
- User Feedback: Clear error messages and suggestions
- Fallback Options: Alternative formatting approaches
Performance Considerations
Processing Limits
- Query Size: Handles queries up to 10,000 characters
- Complexity: Supports nested queries up to 10 levels deep
- Processing Time: Typically processes queries in under 100ms
Optimization Features
- Incremental Processing: Only processes changed portions
- Caching: Caches formatting results for repeated operations
- Lazy Loading: Loads history records on demand
Browser Compatibility
Supported Browsers
- Chrome: Version 80+
- Firefox: Version 75+
- Safari: Version 13+
- Edge: Version 80+
Required Features
- ES6 Support: Arrow functions, template literals
- Local Storage: Browser local storage API
- Clipboard API: Modern clipboard access
- CSS Grid: Layout support
Integration
Embedding Options
The tool can be integrated into other applications:
- Iframe Embedding: Embed as an iframe
- API Integration: Use formatting functions directly
- Component Integration: Include as a Vue component
Customization
- Theme Support: Light and dark themes
- Language Support: Multiple language options
- Custom Styling: CSS customization options