Skip to main content
Glama
README.md
# GoSQLX

<div align="center">

<img src="https://raw.githubusercontent.com/ajitpratap0/GoSQLX/main/.github/logo.png" alt="GoSQLX Logo" width="180"/>

### Parse SQL at the speed of Go

[![Go Version](https://img.shields.io/badge/Go-1.26+-00ADD8?style=for-the-badge&logo=go)](https://go.dev)
[![Release](https://img.shields.io/github/v/release/ajitpratap0/GoSQLX?style=for-the-badge&color=orange)](https://github.com/ajitpratap0/GoSQLX/releases)
[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge)](LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge)](http://makeapullrequest.com)

[![Website](https://img.shields.io/badge/gosqlx.dev-Website-blue?style=for-the-badge&logo=google-chrome)](https://gosqlx.dev)
[![VS Code](https://img.shields.io/visual-studio-marketplace/v/ajitpratap0.gosqlx?style=for-the-badge&logo=visual-studio-code&label=VS%20Code)](https://marketplace.visualstudio.com/items?itemName=ajitpratap0.gosqlx)
[![MCP](https://img.shields.io/badge/MCP-Remote%20Server-blue?style=for-the-badge&logo=cloud)](https://mcp.gosqlx.dev/health)
[![Glama MCP Server](https://glama.ai/mcp/servers/ajitpratap0/GoSQLX/badges/score.svg)](https://glama.ai/mcp/servers/ajitpratap0/GoSQLX)
[![Lint Action](https://img.shields.io/badge/Lint%20Action-GitHub-blue?style=for-the-badge&logo=github)](https://github.com/marketplace/actions/gosqlx-lint-action)

[![Tests](https://img.shields.io/github/actions/workflow/status/ajitpratap0/GoSQLX/test.yml?branch=main&label=Tests&style=flat-square)](https://github.com/ajitpratap0/GoSQLX/actions)
[![Go Report](https://goreportcard.com/badge/github.com/ajitpratap0/GoSQLX?style=flat-square)](https://goreportcard.com/report/github.com/ajitpratap0/GoSQLX)
[![GoDoc](https://pkg.go.dev/badge/github.com/ajitpratap0/GoSQLX?style=flat-square)](https://pkg.go.dev/github.com/ajitpratap0/GoSQLX)
[![Stars](https://img.shields.io/github/stars/ajitpratap0/GoSQLX?style=social)](https://github.com/ajitpratap0/GoSQLX)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ajitpratap0/GoSQLX/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ajitpratap0/GoSQLX)

<br/>

**[๐ŸŒ Try the Playground](https://gosqlx.dev/playground/)** &nbsp;ยท&nbsp; **[๐Ÿ“– Read the Docs](https://gosqlx.dev/docs/)** &nbsp;ยท&nbsp; **[๐Ÿš€ Get Started](docs/GETTING_STARTED.md)** &nbsp;ยท&nbsp; **[๐Ÿ“Š Benchmarks](https://gosqlx.dev/benchmarks/)**

<br/>

| **1.38M+ ops/sec** | **<1ฮผs latency** | **85% SQL-99** | **8 dialects** | **0 race conditions** |
|:---:|:---:|:---:|:---:|:---:|

</div>

<br/>

## 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.

<br/>

## 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.
}
```

<br/>

## Install Everywhere

<table>
<tr>
<td width="50%">

### ๐Ÿ“ฆ 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
```

</td>
<td width="50%">

### ๐Ÿ’ป 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/)

</td>
</tr>
</table>

<br/>

## Features at a Glance

<table>
<tr>
<td align="center" width="33%"><h3>โšก Parser</h3>Zero-copy tokenizer<br/>Recursive descent parser<br/>Full AST generation<br/>Multi-dialect engine</td>
<td align="center" width="33%"><h3>๐Ÿ›ก๏ธ Analysis</h3>SQL injection scanner<br/>30 lint rules (L001โ€“L030)<br/>20 optimizer rules<br/>Metadata extraction</td>
<td align="center" width="33%"><h3>๐Ÿ”ง Tooling</h3>AST-based formatter<br/>Query transforms API<br/>VS Code extension<br/>GitHub Action</td>
</tr>
<tr>
<td align="center"><h3>๐ŸŒ Multi-Dialect</h3>PostgreSQL ยท MySQL ยท MariaDB<br/>SQL Server ยท Oracle<br/>SQLite ยท Snowflake ยท ClickHouse</td>
<td align="center"><h3>๐Ÿค– AI-Ready</h3>MCP server (7 tools)<br/>Public remote endpoint<br/>Streamable HTTP</td>
<td align="center"><h3>๐Ÿงช Battle-Tested</h3>20K+ concurrent ops<br/>Zero race conditions<br/>~85% SQL-99 compliance</td>
</tr>
</table>

<br/>

## 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 |

<br/>

## 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)

<br/>

## 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.

<br/>

## Community

<div align="center">

**Got questions? Ideas? Found a bug?**

<a href="https://github.com/ajitpratap0/GoSQLX/discussions"><img src="https://img.shields.io/badge/๐Ÿ’ฌ_Discussions-Ask_&_Share-purple?style=for-the-badge" alt="Discussions"></a>
<a href="https://github.com/ajitpratap0/GoSQLX/issues/new/choose"><img src="https://img.shields.io/badge/๐Ÿ›_Issues-Report_&_Request-red?style=for-the-badge" alt="Issues"></a>
<a href="https://gosqlx.dev/blog/"><img src="https://img.shields.io/badge/๐Ÿ“_Blog-Release_Notes-green?style=for-the-badge" alt="Blog"></a>

</div>

<br/>

## License

Apache License 2.0 - see [LICENSE](LICENSE) for details.

---

<div align="center">

<sub>Built with โค๏ธ by the GoSQLX community</sub>

**[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)**

<br/>

If GoSQLX helps your project, consider giving it a โญ

</div>

TDQS

A4.1/5.0

Scored across 7 tools

Disambiguation5/5

Each tool targets a distinct SQL analysis function: syntax validation, AST parsing, metadata extraction, security scanning, linting, formatting, and a composite report. No overlaps exist.

Naming Consistency5/5

All tools follow a clear verb_noun pattern (e.g., validate_sql, format_sql). The one exception (extract_metadata) still uses a verb and clearly refers to SQL metadata, maintaining consistency.

Tool Count5/5

7 tools is well-scoped for SQL analysis, covering the core tasks without being too many or too few. Each tool has a clear purpose.

Completeness5/5

The tool set covers the full lifecycle of SQL analysis: validation, parsing, metadata extraction, security, linting, and formatting. The aggregate tool enhances usability. No obvious gaps for the intended domain.

Maintenance

ActivitySlowing
ResponsivenessResponsive