Logo

0x5a.live

for different kinds of informations and explorations.

GitHub - cristalhq/builq: Easily build SQL queries in Go.

Easily build SQL queries in Go. Contribute to cristalhq/builq development by creating an account on GitHub.

Visit SiteGitHub - cristalhq/builq: Easily build SQL queries in Go.

GitHub - cristalhq/builq: Easily build SQL queries in Go.

Easily build SQL queries in Go. Contribute to cristalhq/builq development by creating an account on GitHub.

Powered by 0x5a.live ๐Ÿ’—

builq

build-img pkg-img reportcard-img coverage-img version-img

Easily build queries in Go.

Rationale

The simplest way to represent SQL query is a string. But the query arguments and their indexing ($1, $2 etc) require additional attention. This tiny library helps to build queries and handles parameter indexing.

Features

  • Simple and easy.
  • Safe and fast.
  • Tested.
  • Language-agnostic.
  • Dependency-free.

See docs or GUIDE.md for more details.

Install

Go version 1.19+

go get github.com/cristalhq/builq

Example

cols := builq.Columns{"foo, bar"}

q := builq.New()
q("SELECT %s FROM %s", cols, "users")
q("WHERE active IS TRUE")
q("AND user_id = %$ OR user = %$", 42, "root")

query, args, err := q.Build()
if err != nil {
	panic(err)
}

debug := q.DebugBuild()

fmt.Println("query:")
fmt.Println(query)
fmt.Println("\nargs:")
fmt.Println(args)
fmt.Println("\ndebug:")
fmt.Println(debug)

// query:
// SELECT foo, bar FROM users
// WHERE active IS TRUE
// AND user_id = $1 OR user = $2
//
// args:
// [42 root]
//
// debug:
// SELECT foo, bar FROM 'users'
// WHERE active IS TRUE
// AND user_id = 42 OR user = 'root'

See examples: example_test.go.

License

MIT License.

GoLang Resources

are all listed below.

Resources

listed to get explored on!!

Made with โค๏ธ

to provide different kinds of informations and resources.