GoSQLX

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2025 License: MIT

README ยถ

GoSQLX

GoSQLX Logo

โšก High-Performance SQL Parser for Go โšก

Go Version Release PRs Welcome

Tests Go Report Card GoDoc

GitHub Stars GitHub Forks GitHub Watchers

Production-ready, high-performance SQL parsing SDK for Go
Zero-copy tokenization โ€ข Object pooling โ€ข Multi-dialect support โ€ข Unicode-first design

๐Ÿš€ Installation โ€ข โšก Quick Start โ€ข ๐Ÿ“š Documentation โ€ข ๐Ÿ’ก Examples โ€ข ๐Ÿ“Š Benchmarks

User Guide API Docs Discussions Report Bug


๐ŸŽฏ 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
๐ŸŽฏ Performance Highlights (v1.0.0)
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

Contributors Issues Pull Requests Downloads Last Commit Commit Activity

๐Ÿ“ฆ 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
Guide Description
API Reference Complete API documentation with examples
Usage Guide Detailed patterns and best practices
Architecture System design and internal architecture
Troubleshooting Common issues and solutions
๐Ÿš€ Getting Started
Document Purpose
Production Guide Deployment and monitoring
SQL Compatibility Dialect support matrix
Security Analysis Security assessment
Examples Working code examples

๐Ÿ’ป 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()
}

๐Ÿ“Š Performance

๐ŸŽฏ v1.0.0 Performance Improvements
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
Performance Characteristics
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
  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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.

๐Ÿค Community & Support

Join Our Community

GitHub Discussions GitHub Issues

Get Help
Channel Purpose Response Time
๐Ÿ› Bug Reports Report issues Community-driven
๐Ÿ’ก Feature Requests Suggest improvements Community-driven
๐Ÿ’ฌ Discussions Q&A, ideas, showcase Community-driven
๐Ÿ”’ Security Report vulnerabilities Best effort

๐Ÿ‘ฅ Contributors

Core Team
Contributors
How to Contribute

We love your input! We want to make contributing as easy and transparent as possible.

Contributing Guide Code of Conduct Start Contributing

Quick Contribution Guide
  1. ๐Ÿด Fork the repo
  2. ๐Ÿ”จ Make your changes
  3. โœ… Ensure tests pass (go test -race ./...)
  4. ๐Ÿ“ Update documentation
  5. ๐Ÿš€ Submit a PR

๐ŸŽฏ 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

Using GoSQLX in production? Let us know!

๐Ÿ“ˆ Project Metrics

Performance Benchmarks
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

Full Roadmap

๐Ÿ’– Support This Project

If GoSQLX helps your project, please consider:

Star This Repo

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

Star Us Fork Me Watch

Copyright ยฉ 2024 GoSQLX. All rights reserved.

Directories ยถ

Path Synopsis
examples
cmd command
sql-formatter command
sql-validator command
pkg
metrics
Package metrics provides production performance monitoring for GoSQLX
Package metrics provides production performance monitoring for GoSQLX
sql/monitor
Package monitor provides performance monitoring and metrics collection for GoSQLX
Package monitor provides performance monitoring and metrics collection for GoSQLX
sql/tokenizer
Package tokenizer provides a high-performance SQL tokenizer with zero-copy operations
Package tokenizer provides a high-performance SQL tokenizer with zero-copy operations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL