Sql Query Builder for Go
sqb.go is a sql query builder for Go. It is inspired by ssibrahimbas/query typescript package.
Generally, adding parameters to a query is a tedious task. You have to write a lot of code to add parameters to a query. This package aims to make it easier to add parameters to a query.
go get gitlab.com/ssibrahimbas/sqb.go
package main
import (
"fmt"
"gitlab.com/ssibrahimbas/sqb.go"
)
func main() {
query := sqb_go.QB.Table("my_table").GetAll()
fmt.Println(query) // SELECT * FROM my_table
}
Contributions are always welcome!
▸ Table(tables
: ...string): Sqb
Name | Type | Description |
---|---|---|
tables |
...string | You can pass multiple tables. |
Sqb
query := sqb_go.QB.Table("my_table").GetAll()
fmt.Println(query) // SELECT * FROM my_table
▸ Select(columns
: ...string): Sqb
Name | Type | Description |
---|---|---|
columns |
...string | You can pass multiple columns. |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").GetAll()
fmt.Println(query) // SELECT id, name FROM my_table
▸ GroupConcat(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").GroupConcat("name").GetAll()
fmt.Println(query) // SELECT id, name, GROUP_CONCAT(name) FROM my_table
▸ Least(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").Least("name").GetAll()
fmt.Println(query) // SELECT id, name, LEAST(name) FROM my_table
▸ Max(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").Max("name").GetAll()
fmt.Println(query) // SELECT id, name, MAX(name) FROM my_table
▸ Min(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").Min("name").GetAll()
fmt.Println(query) // SELECT id, name, MIN(name) FROM my_table
▸ Sum(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("id", "name").Sum("price").GetAll()
fmt.Println(query) // SELECT id, name, SUM(price) FROM my_table
▸ Count(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("name").Count("id").GetAll()
fmt.Println(query) // SELECT name, COUNT(id) FROM my_table
▸ Avg(column
: string): Sqb
Name | Type | Description |
---|---|---|
column |
string |
Sqb
query := sqb_go.QB.Table("my_table").Select("name").Avg("price").GetAll()
fmt.Println(query) // SELECT name, AVG(price) FROM my_table