GoSQLX
๐ฏ Overview
GoSQLX is a high-performance SQL parsing library designed for production use. It provides zero-copy tokenization, intelligent object pooling, and comprehensive SQL dialect support while maintaining a simple, idiomatic Go API.
โจ Key Features
- ๐ Blazing Fast: 2.2M ops/sec, 8M tokens/sec processing speed
- ๐พ Memory Efficient: 60-80% reduction through intelligent object pooling
- ๐ Thread-Safe: Race-free, linear scaling to 128+ cores
- ๐ Unicode Support: Complete UTF-8 support for international SQL
- ๐ง Multi-Dialect: PostgreSQL, MySQL, SQL Server, Oracle, SQLite
- ๐ Zero-Copy: Direct byte slice operations, < 200ns latency
- ๐๏ธ Production Ready: Battle-tested with 0 race conditions detected
2.2M |
8M |
184ns |
60-80% |
Ops/sec |
Tokens/sec |
Latency |
Memory Saved |
+47% faster than previous version โข Linear scaling to 128 cores โข Zero race conditions
๐ Project Stats
๐ฆ Installation
go get github.com/ajitpratap0/GoSQLX
Requirements:
- Go 1.19 or higher
- No external dependencies
๐ Quick Start
Basic Usage
package main
import (
"fmt"
"log"
"github.com/ajitpratap0/GoSQLX/pkg/sql/tokenizer"
)
func main() {
// Get tokenizer from pool (always return it!)
tkz := tokenizer.GetTokenizer()
defer tokenizer.PutTokenizer(tkz)
// Tokenize SQL
sql := "SELECT id, name FROM users WHERE age > 18"
tokens, err := tkz.Tokenize([]byte(sql))
if err != nil {
log.Fatal(err)
}
// Process tokens
fmt.Printf("Generated %d tokens\n", len(tokens))
for _, token := range tokens {
fmt.Printf(" %s (line %d, col %d)\n",
token.Token.Value,
token.Start.Line,
token.Start.Column)
}
}
Advanced Example with AST
package main
import (
"fmt"
"github.com/ajitpratap0/GoSQLX/pkg/sql/tokenizer"
"github.com/ajitpratap0/GoSQLX/pkg/sql/parser"
)
func AnalyzeSQL(sql string) error {
// Tokenize
tkz := tokenizer.GetTokenizer()
defer tokenizer.PutTokenizer(tkz)
tokens, err := tkz.Tokenize([]byte(sql))
if err != nil {
return fmt.Errorf("tokenization failed: %w", err)
}
// Parse to AST
p := parser.NewParser()
defer p.Release()
ast, err := p.Parse(convertTokens(tokens))
if err != nil {
return fmt.Errorf("parsing failed: %w", err)
}
// Analyze AST
fmt.Printf("Statement type: %T\n", ast)
return nil
}
๐ Documentation
๐ Comprehensive Guides
๐ Getting Started
๐ Quick Links
๐ป Examples
Multi-Dialect Support
// PostgreSQL with array operators
sql := `SELECT * FROM users WHERE tags @> ARRAY['admin']`
// MySQL with backticks
sql := "SELECT `user_id`, `name` FROM `users`"
// SQL Server with brackets
sql := "SELECT [user_id], [name] FROM [users]"
Unicode and International SQL
// Japanese
sql := `SELECT "ๅๅ", "ๅนด้ฝข" FROM "ใฆใผใถใผ"`
// Russian
sql := `SELECT "ะธะผั", "ะฒะพะทัะฐัั" FROM "ะฟะพะปัะทะพะฒะฐัะตะปะธ"`
// Arabic
sql := `SELECT "ุงูุงุณู
", "ุงูุนู
ุฑ" FROM "ุงูู
ุณุชุฎุฏู
ูู"`
// Emoji support
sql := `SELECT * FROM users WHERE status = '๐'`
Concurrent Processing
func ProcessConcurrently(queries []string) {
var wg sync.WaitGroup
for _, sql := range queries {
wg.Add(1)
go func(query string) {
defer wg.Done()
// Each goroutine gets its own tokenizer
tkz := tokenizer.GetTokenizer()
defer tokenizer.PutTokenizer(tkz)
tokens, _ := tkz.Tokenize([]byte(query))
// Process tokens...
}(sql)
}
wg.Wait()
}
Metric |
Previous |
v1.0.0 |
Improvement |
Throughput |
1.5M ops/s |
2.2M ops/s |
+47% โ
|
Token Processing |
5M tokens/s |
8M tokens/s |
+60% โ
|
Concurrency |
Limited |
Linear to 128 cores |
โ โ
|
Memory Usage |
Baseline |
60-80% reduction |
-70% โ
|
Latency (p99) |
1ฮผs |
184ns |
-82% โ
|
Latest Benchmark Results
BenchmarkTokenizer/SimpleSQL-16 965,466 1,238 ns/op 1,585 B/op 20 allocs/op
BenchmarkTokenizer/ComplexSQL-16 92,636 13,078 ns/op 13,868 B/op 159 allocs/op
BenchmarkTokenizer/Concurrent-128-16 639,093 1,788 ns/op 10,735 B/op 88 allocs/op
BenchmarkParser/SimpleSelect-16 6,330,259 185 ns/op 536 B/op 9 allocs/op
BenchmarkParser/ParallelSelect-16 8,175,652 154 ns/op 536 B/op 9 allocs/op
BenchmarkThroughput/200_goroutines-16 3,144,678 381 ns/op 2,189,740 ops/sec
BenchmarkTokensPerSecond-16 733,141 1,619 ns/op 8,032,114 tokens/sec
Metric |
Value |
Details |
Throughput |
2.2M ops/sec |
200 concurrent goroutines |
Token Rate |
8M tokens/sec |
Sustained processing |
Latency |
< 200ns |
Simple queries (p50) |
Memory |
1.6KB/query |
Simple SQL with pooling |
Scaling |
Linear to 128 |
Perfect concurrency |
Pool Efficiency |
95%+ hit rate |
Effective reuse |
See PERFORMANCE_REPORT.md for detailed analysis.
๐งช Testing
# Run all tests with race detection
go test -race ./...
# Run benchmarks
go test -bench=. -benchmem ./...
# Generate coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run specific test suites
go test -v ./pkg/sql/tokenizer/
go test -v ./pkg/sql/parser/
๐๏ธ Project Structure
GoSQLX/
โโโ pkg/
โ โโโ models/ # Core data structures
โ โ โโโ token.go # Token definitions
โ โ โโโ location.go # Position tracking
โ โโโ sql/
โ โโโ tokenizer/ # Lexical analysis
โ โ โโโ tokenizer.go
โ โ โโโ pool.go
โ โโโ parser/ # Syntax analysis
โ โ โโโ parser.go
โ โ โโโ expressions.go
โ โโโ ast/ # Abstract syntax tree
โ โ โโโ nodes.go
โ โ โโโ statements.go
โ โโโ keywords/ # SQL keywords
โโโ examples/ # Usage examples
โ โโโ cmd/
โ โโโ example.go
โ โโโ example_test.go
โโโ docs/ # Documentation
โ โโโ API_REFERENCE.md
โ โโโ USAGE_GUIDE.md
โ โโโ ARCHITECTURE.md
โ โโโ TROUBLESHOOTING.md
โโโ tools/ # Development tools
๐ ๏ธ Development
Prerequisites
- Go 1.19+
- Make (optional, for Makefile targets)
- golint, staticcheck (for code quality)
Building
# Build the project
make build
# Run quality checks
make quality
# Run all tests
make test
# Clean build artifacts
make clean
Code Quality
# Format code
go fmt ./...
# Vet code
go vet ./...
# Run linter
golint ./...
# Static analysis
staticcheck ./...
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
Development Guidelines
- Write tests for new features
- Ensure all tests pass with race detection
- Follow Go idioms and best practices
- Update documentation for API changes
- Add benchmarks for performance-critical code
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Roadmap
Phase 1: Foundation (Q3 2024) - v1.1.0
- โ
Common Table Expressions (CTEs) with RECURSIVE
- โ
Complete JOIN support (LEFT/RIGHT/FULL OUTER)
- โ
Set operations (UNION/EXCEPT/INTERSECT)
- โ
Comprehensive subquery support
- โ
Standardized error handling
Phase 2: Advanced Features (Q4 2024) - v1.2.0
- ๐ Window functions (OVER, PARTITION BY)
- ๐ Transaction control (BEGIN/COMMIT/ROLLBACK)
- ๐ Views and materialized views
- ๐ Streaming parser API
- ๐ AST transformation framework
Phase 3: Dialect Specialization (Q1 2025) - v2.0.0
- ๐ PostgreSQL arrays, JSONB, custom types
- ๐ MySQL-specific syntax and functions
- ๐ SQL Server T-SQL extensions
- ๐ Multi-dialect parser with auto-detection
Phase 4: Intelligence Layer (Q2 2025) - v2.1.0
- ๐ Query optimization suggestions
- ๐ Security vulnerability detection
- ๐ Performance analysis and hints
- ๐ Schema validation
๐ Full Architectural Review & Roadmap

Get Help
๐ฅ Contributors
๐ฏ Use Cases
Industry |
Use Case |
Benefits |
๐ฆ FinTech |
SQL validation & auditing |
Fast validation, compliance tracking |
๐ Analytics |
Query parsing & optimization |
Real-time analysis, performance insights |
๐ก๏ธ Security |
SQL injection detection |
Pattern matching, threat prevention |
๐๏ธ DevTools |
IDE integration & linting |
Syntax highlighting, auto-completion |
๐ Education |
SQL learning platforms |
Interactive parsing, error explanation |
๐ Migration |
Cross-database migration |
Dialect conversion, compatibility check |
๐ Who's Using GoSQLX
๐ Project Metrics
graph LR
A[SQL Input] -->|2.2M ops/sec| B[Tokenizer]
B -->|8M tokens/sec| C[Parser]
C -->|Zero-copy| D[AST]
D -->|60-80% less memory| E[Output]
๐บ๏ธ Roadmap
Release Timeline
Version |
Status |
Release Date |
Features |
v0.9.0 |
โ
Released |
2024-01-15 |
Initial release |
v1.0.0 |
๐ Current |
2024-12-01 |
Production ready, +47% performance |
v1.1.0 |
๐ง In Progress |
Q1 2025 |
Streaming parser, plugins |
v1.2.0 |
๐ Planned |
Q2 2025 |
Query optimizer, schema validation |
v2.0.0 |
๐ฎ Future |
Q4 2025 |
Complete rewrite, AI integration |

๐ Support This Project
If GoSQLX helps your project, please consider:

Other Ways to Support
- โญ Star this repository
- ๐ฆ Tweet about GoSQLX
- ๐ Write a blog post
- ๐ฅ Create a tutorial
- ๐ Report bugs
- ๐ก Suggest features
- ๐ง Submit PRs
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ by the GoSQLX Team
Copyright ยฉ 2024 GoSQLX. All rights reserved.