w

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

  1. SELECT Clauses: Each column on a new line with indentation
  2. FROM Clauses: Table names with proper indentation
  3. JOIN Clauses: JOIN conditions with appropriate indentation
  4. WHERE Clauses: Conditions with proper indentation
  5. GROUP BY: Grouping columns with indentation
  6. ORDER BY: Sorting columns with indentation

Case Conversion Rules

  1. Keywords: Convert to specified case (upper/lower/preserve)
  2. Functions: Convert function names to specified case
  3. Data Types: Convert data type names to specified case
  4. Identifiers: Preserve original case for table/column names

Line Break Rules

  1. Major Clauses: Break before SELECT, FROM, WHERE, GROUP BY, ORDER BY
  2. JOIN Clauses: Break before each JOIN type
  3. Boolean Operators: Break before AND/OR if enabled
  4. 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

  1. Invalid SQL Syntax: Malformed SQL queries
  2. Unsupported Constructs: SQL features not supported by formatter
  3. Large Queries: Queries exceeding processing limits
  4. Browser Limitations: Local storage or memory constraints

Error Recovery

  1. Syntax Validation: Basic SQL syntax checking
  2. Graceful Degradation: Partial formatting for complex queries
  3. User Feedback: Clear error messages and suggestions
  4. 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:

  1. Iframe Embedding: Embed as an iframe
  2. API Integration: Use formatting functions directly
  3. Component Integration: Include as a Vue component

Customization

  • Theme Support: Light and dark themes
  • Language Support: Multiple language options
  • Custom Styling: CSS customization options
Was this page helpful?