Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Code-Hex/sqb
⚡Blazing fast, Flexible, SQL Query Builder for Go
https://github.com/Code-Hex/sqb
Last synced: 11 days ago
JSON representation
⚡Blazing fast, Flexible, SQL Query Builder for Go
- Host: GitHub
- URL: https://github.com/Code-Hex/sqb
- Owner: Code-Hex
- License: mit
- Created: 2019-11-02T17:08:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T06:12:56.000Z (over 3 years ago)
- Last Synced: 2024-06-21T14:45:07.610Z (5 months ago)
- Language: Go
- Homepage:
- Size: 78.1 KB
- Stars: 17
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - sqb - ⚡Blazing fast, Flexible, SQL Query Builder for Go (Go)
README
# sqb - SQL Query Builder
> ⚡ Blazing fast, Flexible, SQL Query Builder for Go
[![GoDoc](https://godoc.org/github.com/Code-Hex/sqb?status.svg)](https://godoc.org/github.com/Code-Hex/sqb) [![CircleCI](https://circleci.com/gh/Code-Hex/sqb.svg?style=svg&circle-token=0ff0570576e90eb3a10e017f7ca1279748565daf)](https://circleci.com/gh/Code-Hex/sqb) [![codecov](https://codecov.io/gh/Code-Hex/sqb/branch/master/graph/badge.svg?token=xjioT8q5f5)](https://codecov.io/gh/Code-Hex/sqb) [![Go Report Card](https://goreportcard.com/badge/github.com/Code-Hex/sqb)](https://goreportcard.com/report/github.com/Code-Hex/sqb)
## Features
- High performance.
- Easy to use.
- Powerful, Flexible. You can define stmt for yourself.
- Supported MySQL, PostgreSQL, Spanner statement.## Synopsis
When used normally
```go
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
```go
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
```go
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
## Performance
sqb is the fastest and least-memory used among currently known SQL Query builder in the benchmark. The data of chart using simple [benchmark](https://github.com/Code-Hex/sqb/blob/a3e54e8ed6bf41df28cac174e503b15d03c76b4b/benchmark/benchmark_test.go).
![time](https://user-images.githubusercontent.com/6500104/71240191-d7e74a00-234b-11ea-8070-03ffaa8f849f.png)
![benchmark](https://user-images.githubusercontent.com/6500104/71240411-62c84480-234c-11ea-926b-d31418148d26.png)