Skip to content
⚡Blazing fast, Flexible, SQL Query Builder for Go
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
benchmark
internal
stmt
.codecov.yml
.gitignore
LICENSE
README.md
aliases.go
aliases_test.go
comparisoner.go
comparisoner_test.go
conjunction.go
conjunction_test.go
go.mod
go.sum
options.go
order_by.go
order_by_test.go
sqb.go
sqb_test.go
utils_for_test.go

README.md

sqb - SQL Query Builder

⚡ Blazing fast, Flexible, SQL Query Builder for Go

GoDoc CircleCI codecov Go Report Card

Synopsis

When used normally

const sqlstr = "SELECT * FROM tables WHERE ?"
builder := sqb.New(sqlstr).Bind(sqb.Eq("category", 1))
query, args, err := builder.Build()
// query => "SELECT * FROM tables WHERE category = ?",
// args  => []interface{}{1}
When you want to use build cache
const sqlstr = "SELECT * FROM tables WHERE ? AND ?"
cached := sqb.New(sqlstr).Bind(sqb.Eq("category", 1))

for _, col := range columns {
    builder := cached.Bind(sqb.Eq(col, "value"))
    query, args, err  := builder.Build()
    // query => "SELECT * FROM tables WHERE category = ? AND " + col + " = ?",
    // args  => []interface{}{1, "value"}
}
Error case
const sqlstr = "SELECT * FROM tables WHERE ? OR ?"
builder := sqb.New(sqlstr).Bind(sqb.Eq("category", 1))
query, args, err  := builder.Build()
// query => "",
// args  => nil
// err   => "number of bindVars exceeds replaceable statements"

Install

Use go get to install this package.

go get -u github.com/Code-Hex/sqb
You can’t perform that action at this time.