Version: v1.6.0
This directory contains various examples demonstrating how to use the GoSQLX SQL parsing SDK.
Simple command-line tool showing basic tokenization and parsing:
cd cmd/
go run example.go
go test -v example_test.goGoSQLX v1.6.0 adds comprehensive PostgreSQL-specific feature support. Run these examples to see the new capabilities:
Demonstrates PostgreSQL LATERAL subquery parsing:
cd postgresql/lateral-join/
go run main.go- Basic LATERAL subqueries
- LATERAL with LEFT/CROSS JOIN
- Multiple LATERAL joins
- LATERAL with generate_series
- LATERAL with window functions
Demonstrates all PostgreSQL JSON/JSONB operators:
cd postgresql/jsonb-operators/
go run main.go- Arrow operators:
->,->> - Path operators:
#>,#>> - Containment:
@>,<@ - Key existence:
?,?|,?& - Delete path:
#-
Demonstrates SQL:2003 FILTER clause for conditional aggregation:
cd postgresql/filter-clause/
go run main.go- COUNT/SUM/AVG with FILTER
- Window functions with FILTER
- Pivot-like queries with FILTER
- FILTER with GROUPING SETS
Demonstrates PostgreSQL RETURNING clause parsing:
cd postgresql/returning-clause/
go run main.go- INSERT RETURNING
- UPDATE RETURNING
- DELETE RETURNING
- UPSERT (ON CONFLICT) with RETURNING
- CTEs with RETURNING for data archival
Demonstrates PostgreSQL DISTINCT ON clause:
go run distinct_on_example.go- Single column DISTINCT ON
- Multiple column DISTINCT ON
- DISTINCT ON with ORDER BY
Command-line SQL validation and analysis tools:
simple.go- Basic SQL syntax validationadvanced.go- Advanced SQL analysis with detailed feedback
Example of using GoSQLX linter programmatically:
cd linter-example/
go run main.goExample of SQL formatting capabilities:
cd sql-formatter/
go run main.goExample of SQL validation with error reporting:
cd sql-validator/
go run main.goDemonstrates structured error handling:
cd error-demo/
go run main.goStep-by-step examples for beginners:
cd getting-started/01-hello-world/
go run main.goIn-depth tutorials covering specific features:
01-sql-validator/- Building a SQL validator02-sql-formatter/- Building a SQL formatter
Examples of integrating GoSQLX into web applications.
Example gRPC service exposing SQL parsing capabilities over RPC.
REST API server for SQL parsing operations with JSON input/output.
All examples follow the same pattern:
package main
import (
"github.com/ajitpratap0/GoSQLX/pkg/sql/tokenizer"
"github.com/ajitpratap0/GoSQLX/pkg/sql/parser"
"github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
)
func main() {
// 1. Get tokenizer from pool
tkz := tokenizer.GetTokenizer()
defer tokenizer.PutTokenizer(tkz) // Always return to pool
// 2. Get AST from pool
astObj := ast.NewAST()
defer ast.ReleaseAST(astObj) // Always release AST
// 3. Tokenize SQL
sql := []byte("SELECT * FROM users WHERE id = 1")
tokens, err := tkz.Tokenize(sql)
if err != nil {
// Handle error
}
// 4. Parse tokens
result, err := parser.Parse(tokens)
if err != nil {
// Handle error
}
// 5. Use the AST
// ... process result ...
}# Run all example tests
go test -v ./examples/...
# Run with race detection (recommended)
go test -race ./examples/...
# Run benchmarks
go test -bench=. ./examples/...- Object Pooling: Efficient memory management with tokenizer and AST pools
- Unicode Support: Full international SQL support (see cmd/example_test.go)
- Multi-dialect: PostgreSQL, MySQL, SQL Server, Oracle, SQLite compatibility
- Error Handling: Graceful error recovery and reporting
- Performance: High-throughput parsing with minimal allocations