Skip to content

A lightweight, ORM-free SQL query builder for Go. Designed for simplicity and compatibility with `database/sql` and libraries like `sqlx`.

Notifications You must be signed in to change notification settings

MattConce/goqueryx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tests

goqueryx

A lightweight, ORM-free SQL query builder for Go. Designed for simplicity and compatibility with database/sql and libraries like sqlx.

Features

  • Simple API: Chainable methods for building SQL queries
  • Zero ORM Dependencies: Use raw SQL with your preferred driver (pgx, sqlx, database/sql, etc.)
  • SQL Injection Protection: Parameterized arguments
  • Minimalist: Pure GO, no external dependencies

Installation

go get github.com/MattConce/goqueryx/queryx

Usage with sqlx (Recommended)

type User struct {
    Id   `db:"id"`
    Name `db:"name"`
}

db := sqlx.MustConnect("mysql", "<username>:<password>@tcp(<host>:3306)/<dbname>")

qb := queryx.NewQuery().
    Select("id", "name").
    From("users").
    Where("active = ?", []any{true})

sql, args, _ := qb.Build()
sql = db.Rebind(sql)

var users []User

err := db.Select(&users, sql, args...)
if err != nil {
    panic(err)
}

Basic Usage

qb := queryx.NewQuery().
Select("id", "email").
From("users").
Where("created_at > ?", []any{"2024-01-01"}).
OrderBy("id DESC")

sql, args, _ := qb.Build()
// SQL: SELECT id, email FROM users WHERE created_at > ? ORDER BY id DESC
// Args: [2024-01-01]

TODO

  • Add support for DELETE statement

  • Support dialect-specific placeholders (e.g., $1 for PostgreSQL)

  • Add query validation for unsupported operations

  • Improve error messages for missing required clauses

License MIT. See LICENSE.

About

A lightweight, ORM-free SQL query builder for Go. Designed for simplicity and compatibility with `database/sql` and libraries like `sqlx`.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages