A high-performance SQL INSERT statement parser that processes large SQL files and outputs the data in various formats.
- Processes large SQL files with INSERT statements
- Memory-efficient batch processing
- Parallel processing with configurable worker count
- Multiple output formats:
- JSON
- JSONL
- CSV
- Text
- Buffered I/O for optimal performance
- Configurable batch size and worker count via environment variables
git clone https://github.com/githubesson/sqlparser
cd sqlparser
go build cmd/sqlparser/main.go
sqlparser [-format=txt|csv|json|jsonl] [-output=filename] [-workers=N] <sqlfile>
-format
: Output format (default: txt)txt
: Human-readable text formatcsv
: CSV format with headersjson
: JSON format with table structurejsonl
: JSON lines format with table structure
-output
: Output file path (default: stdout)-workers
: Number of worker threads (default: 1)-all
: Export all tables (default: false)<sqlfile>
: Input SQL file containing INSERT statements
The application can be configured using environment variables in a .env
file:
BATCH_SIZE=100000 # Number of rows to process in each batch
WORKER_COUNT=1 # Default number of worker threads
- Process SQL file and output as JSON:
sqlparser -format=json -output=output.json input.sql
- Process SQL file with 4 workers and output as CSV:
sqlparser -format=csv -workers=4 -output=output.csv input.sql
- Process SQL file and print to console in text format:
sqlparser input.sql
- Process SQL file and output as JSON lines:
sqlparser -format=jsonl -output=output.json input.sql
The parser is optimized for performance through:
- Batch processing to manage memory usage
- Parallel processing with configurable worker count
- Buffered I/O operations
- Memory pooling for row data
- Efficient string handling
Table: users
Row 1:
id: 1
name: John Doe
email: [email protected]
Table:,users
Row,id,name,email
1,1,John Doe,[email protected]
[
{
"table_name": "users",
"rows": [
{
"row_number": 1,
"data": {
"id": "1",
"name": "John Doe",
"email": "[email protected]"
}
}
]
}
]
{"table_name": "users", "rows": [{"row_number": 1, "data": {"id": "1", "name": "John Doe", "email": "[email protected]"}}]}
{"table_name": "users", "rows": [{"row_number": 2, "data": {"id": "2", "name": "John Doe", "email": "[email protected]"}}]}
This project is licensed under the MIT License - see the LICENSE file for details.