|
| 1 | +# SQL Parser |
| 2 | + |
| 3 | +A high-performance SQL INSERT statement parser that processes large SQL files and outputs the data in various formats. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Processes large SQL files with INSERT statements |
| 8 | +- Memory-efficient batch processing |
| 9 | +- Parallel processing with configurable worker count |
| 10 | +- Multiple output formats: |
| 11 | + - JSON |
| 12 | + - CSV |
| 13 | + - Text |
| 14 | +- Buffered I/O for optimal performance |
| 15 | +- Configurable batch size and worker count via environment variables |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +git clone https://github.com/githubesson/sqlparser |
| 21 | +cd sqlparser |
| 22 | +go build cmd/sqlparser/main.go |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +```bash |
| 28 | +sqlparser [-format=txt|csv|json] [-output=filename] [-workers=N] <sqlfile> |
| 29 | +``` |
| 30 | + |
| 31 | +### Arguments |
| 32 | + |
| 33 | +- `-format`: Output format (default: txt) |
| 34 | + - `txt`: Human-readable text format |
| 35 | + - `csv`: CSV format with headers |
| 36 | + - `json`: JSON format with table structure |
| 37 | +- `-output`: Output file path (default: stdout) |
| 38 | +- `-workers`: Number of worker threads (default: 1) |
| 39 | +- `<sqlfile>`: Input SQL file containing INSERT statements |
| 40 | + |
| 41 | +### Environment Variables |
| 42 | + |
| 43 | +The application can be configured using environment variables in a `.env` file: |
| 44 | + |
| 45 | +```env |
| 46 | +BATCH_SIZE=100000 # Number of rows to process in each batch |
| 47 | +WORKER_COUNT=1 # Default number of worker threads |
| 48 | +``` |
| 49 | + |
| 50 | +### Examples |
| 51 | + |
| 52 | +1. Process SQL file and output as JSON: |
| 53 | +```bash |
| 54 | +sqlparser -format=json -output=output.json input.sql |
| 55 | +``` |
| 56 | + |
| 57 | +2. Process SQL file with 4 workers and output as CSV: |
| 58 | +```bash |
| 59 | +sqlparser -format=csv -workers=4 -output=output.csv input.sql |
| 60 | +``` |
| 61 | + |
| 62 | +3. Process SQL file and print to console in text format: |
| 63 | +```bash |
| 64 | +sqlparser input.sql |
| 65 | +``` |
| 66 | + |
| 67 | +## Performance Optimization |
| 68 | + |
| 69 | +The parser is optimized for performance through: |
| 70 | +- Batch processing to manage memory usage |
| 71 | +- Parallel processing with configurable worker count |
| 72 | +- Buffered I/O operations |
| 73 | +- Memory pooling for row data |
| 74 | +- Efficient string handling |
| 75 | + |
| 76 | +## Output Formats |
| 77 | + |
| 78 | +### Text Format |
| 79 | +``` |
| 80 | +Table: users |
| 81 | +Row 1: |
| 82 | + id: 1 |
| 83 | + name: John Doe |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +### CSV Format |
| 88 | +``` |
| 89 | +Table:,users |
| 90 | +Row,id,name,email |
| 91 | + |
| 92 | +``` |
| 93 | + |
| 94 | +### JSON Format |
| 95 | +```json |
| 96 | +[ |
| 97 | + { |
| 98 | + "table_name": "users", |
| 99 | + "rows": [ |
| 100 | + { |
| 101 | + "row_number": 1, |
| 102 | + "data": { |
| 103 | + "id": "1", |
| 104 | + "name": "John Doe", |
| 105 | + |
| 106 | + } |
| 107 | + } |
| 108 | + ] |
| 109 | + } |
| 110 | +] |
| 111 | +``` |
| 112 | + |
| 113 | +## License |
| 114 | + |
| 115 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments