# GoSQLX

### Parse SQL at the speed of Go
[](https://go.dev)
[](https://github.com/ajitpratap0/GoSQLX/releases)
[](LICENSE)
[](http://makeapullrequest.com)
[](https://gosqlx.dev)
[](https://marketplace.visualstudio.com/items?itemName=ajitpratap0.gosqlx)
[](https://mcp.gosqlx.dev/health)
[](https://glama.ai/mcp/servers/ajitpratap0/GoSQLX)
[](https://github.com/marketplace/actions/gosqlx-lint-action)
[](https://github.com/ajitpratap0/GoSQLX/actions)
[](https://goreportcard.com/report/github.com/ajitpratap0/GoSQLX)
[](https://pkg.go.dev/github.com/ajitpratap0/GoSQLX)
[](https://github.com/ajitpratap0/GoSQLX)
[](https://securityscorecards.dev/viewer/?uri=github.com/ajitpratap0/GoSQLX)
**[๐ Try the Playground](https://gosqlx.dev/playground/)** ยท **[๐ Read the Docs](https://gosqlx.dev/docs/)** ยท **[๐ Get Started](docs/GETTING_STARTED.md)** ยท **[๐ Benchmarks](https://gosqlx.dev/benchmarks/)**
| **1.38M+ ops/sec** | **<1ฮผs latency** | **85% SQL-99** | **8 dialects** | **0 race conditions** |
|:---:|:---:|:---:|:---:|:---:|
## What is GoSQLX?
GoSQLX is a **production-ready SQL parsing SDK** for Go. It tokenizes, parses, and generates ASTs from SQL with zero-copy optimizations and intelligent object pooling - handling **1.38M+ operations per second** with sub-microsecond latency.
```go
// v1.15+ recommended entry point: ParseTree returns an opaque Tree,
// so you don't need to import pkg/sql/ast just to get started.
tree, _ := gosqlx.ParseTree(ctx, "SELECT u.name, COUNT(*) FROM users u JOIN orders o ON u.id = o.user_id GROUP BY u.name",
gosqlx.WithDialect("postgresql"))
fmt.Println("Tables:", tree.Tables())
fmt.Println(tree.Format(gosqlx.WithIndent(2), gosqlx.WithUppercaseKeywords(true)))
```
### Why GoSQLX?
- **Not an ORM** - a parser. You get the AST, you decide what to do with it.
- **Not slow** - zero-copy tokenization, sync.Pool recycling, no allocations on hot paths.
- **Not limited** - PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, ClickHouse. CTEs, window functions, MERGE, set operations.
- **Not just a library** - CLI, VS Code extension, GitHub Action, MCP server, WASM playground, Python bindings.
## Get Started in 60 Seconds
```bash
go get github.com/ajitpratap0/GoSQLX
```
```go
package main
import (
"fmt"
"github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
)
func main() {
ctx := context.Background()
// ParseTree (v1.15+) is the recommended entry point. It returns an
// opaque handle with built-in helpers โ no need to import pkg/sql/ast.
tree, err := gosqlx.ParseTree(ctx, "SELECT id, name FROM users WHERE active = true",
gosqlx.WithDialect("postgresql"))
if err != nil {
// Sentinel errors work with errors.Is
if errors.Is(err, gosqlx.ErrSyntax) {
log.Fatalf("syntax error: %v", err)
}
log.Fatal(err)
}
fmt.Println("Tables:", tree.Tables())
fmt.Println(tree.Format(gosqlx.WithIndent(2), gosqlx.WithUppercaseKeywords(true)))
// Walk the AST โ typed walkers avoid the type-assertion dance:
tree.WalkSelects(func(s *ast.SelectStatement) bool {
fmt.Printf(" SELECT with %d columns\n", len(s.Columns))
return true
})
// The legacy Parse/Format/Validate API still works for v1.x code.
// See docs/MIGRATION.md for the Tree migration guide.
}
```
## Install Everywhere
|
### ๐ฆ Go Library
```bash
go get github.com/ajitpratap0/GoSQLX
```
### ๐ฅ๏ธ CLI Tool
```bash
go install github.com/ajitpratap0/GoSQLX/cmd/gosqlx@latest
gosqlx validate "SELECT * FROM users"
gosqlx format query.sql
gosqlx lint query.sql
```
|
### ๐ป VS Code Extension
```bash
code --install-extension ajitpratap0.gosqlx
```
Bundles the binary - zero setup. [Learn more โ](https://gosqlx.dev/vscode/)
### ๐ค MCP Server (AI Integration)
```bash
claude mcp add --transport http gosqlx \
https://mcp.gosqlx.dev/mcp
```
7 SQL tools in Claude, Cursor, or any MCP client. [Guide โ](https://gosqlx.dev/docs/mcp_guide/)
|
## Features at a Glance
โก ParserZero-copy tokenizer Recursive descent parser Full AST generation Multi-dialect engine |
๐ก๏ธ AnalysisSQL injection scanner 30 lint rules (L001โL030) 20 optimizer rules Metadata extraction |
๐ง ToolingAST-based formatter Query transforms API VS Code extension GitHub Action |
๐ Multi-DialectPostgreSQL ยท MySQL ยท MariaDB SQL Server ยท Oracle SQLite ยท Snowflake ยท ClickHouse |
๐ค AI-ReadyMCP server (7 tools) Public remote endpoint Streamable HTTP |
๐งช Battle-Tested20K+ concurrent ops Zero race conditions ~85% SQL-99 compliance |
## Documentation
| | Resource | Description |
|---|---|---|
| ๐ | **[gosqlx.dev](https://gosqlx.dev)** | Website with interactive playground |
| ๐ | **[Getting Started](https://gosqlx.dev/docs/getting_started/)** | Parse your first SQL in 5 minutes |
| ๐ | **[Usage Guide](https://gosqlx.dev/docs/usage_guide/)** | Comprehensive patterns and examples |
| ๐ | **[API Reference](https://gosqlx.dev/docs/api_reference/)** | Complete API documentation |
| ๐ฅ๏ธ | **[CLI Guide](https://gosqlx.dev/docs/cli_guide/)** | Command-line tool reference |
| ๐ | **[SQL Compatibility](https://gosqlx.dev/docs/sql_compatibility/)** | Dialect support matrix |
| ๐ค | **[MCP Guide](https://gosqlx.dev/docs/mcp_guide/)** | AI assistant integration |
| ๐๏ธ | **[Architecture](https://gosqlx.dev/docs/architecture/)** | System design deep-dive |
| ๐ | **[Benchmarks](https://gosqlx.dev/benchmarks/)** | Performance data and methodology |
| ๐ | **[Release Notes](https://gosqlx.dev/blog/)** | What's new in each version |
## Contributing
GoSQLX is built by contributors like you. Whether it's a bug fix, new feature, documentation improvement, or just a typo - every contribution matters.
```bash
git clone https://github.com/ajitpratap0/GoSQLX.git && cd GoSQLX
task check # fmt โ vet โ lint โ test (with race detection)
```
1. **Fork & branch** from `main`
2. **Write tests** - we use TDD and require race-free code
3. **Run `task check`** - must pass before PR
4. **Open a PR** - we review within 24 hours
๐ [Contributing Guide](CONTRIBUTING.md) ยท ๐ [Code of Conduct](CODE_OF_CONDUCT.md) ยท ๐๏ธ [Governance](GOVERNANCE.md)
## Who's Using GoSQLX?
GoSQLX is downloaded and cloned by developers worldwide -- 595 unique cloners in just 14 days. If you're using GoSQLX in your project or organization, we'd love to hear about it!
| Project / Company | Use Case |
|---|---|
| *Your project here* | [Add yourself via PR](https://github.com/ajitpratap0/GoSQLX/edit/main/README.md) or [tell us in Discussions](https://github.com/ajitpratap0/GoSQLX/discussions) |
Using GoSQLX at work? Building something cool with it? Share your story in [GitHub Discussions](https://github.com/ajitpratap0/GoSQLX/discussions) -- it helps the community grow and motivates continued development.
## Community
## License
Apache License 2.0 - see [LICENSE](LICENSE) for details.
---
Built with โค๏ธ by the GoSQLX community
**[gosqlx.dev](https://gosqlx.dev)** ยท **[Playground](https://gosqlx.dev/playground/)** ยท **[Docs](https://gosqlx.dev/docs/)** ยท **[MCP Server](https://mcp.gosqlx.dev/mcp)** ยท **[VS Code](https://marketplace.visualstudio.com/items?itemName=ajitpratap0.gosqlx)**
If GoSQLX helps your project, consider giving it a โญ