Skip to content

9ssi7/sqb.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


sqb.go

Sql Query Builder for Go

What is it?

sqb.go is a sql query builder for Go. It is inspired by ssibrahimbas/query typescript package.

Motivation

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.

Installation

go get gitlab.com/ssibrahimbas/sqb.go

Usage

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
}

Contributing

Contributions are always welcome!

License

MIT

Documentation

Functions
Table(...)
Select(...)
GroupConcat(...)
Least(...)
Max(...)
Min(...)
Sum(...)
Count(...)
Avg(...)
InnerJoin(...)
LeftJoin(...)
RightJoin(...)
FullOuterJoin(...)
KeftOuterJoin(...)
RightOuterJoin(...)
Where(...)
OrWhere(...)
NotWhere(...)
OrNotWhere(...)
WhereNull(...)
WhereNotNull(...)
Grouped(...)
In(...)
NotIn(...)
OrIn(...)
OrNotIn(...)
FindInSet(...)
NotFindInSet(...)
OrFindInSet(...)
OrNotFindInSet(...)
Between(...)
NotBetween(...)
OrBetween(...)
OrNotBetween(...)
Like(...)
OrLike(...)
NotLike(...)
OrNotLike(...)
Limit(...)
Pagination(...)
OrderBy(...)
GroupBy(...)
Having(...)
FromQuery(...)
GetQuery(...)
Get()
GetAll()
Insert(...)
InsertMany(...)
Update(...)
UpdateMany(...)
Delete()
Analyze()
Check()
Checksum()
Optimize()
Repair()
Reset()

Table

Table(tables: ...string): Sqb

Parameters:

Name Type Description
tables ...string You can pass multiple tables.

Returns:

Sqb

Example

query := sqb_go.QB.Table("my_table").GetAll()
fmt.Println(query) // SELECT * FROM my_table

Select

Select(columns: ...string): Sqb

Parameters:

Name Type Description
columns ...string You can pass multiple columns.

Returns:

Sqb

Example

query := sqb_go.QB.Table("my_table").Select("id", "name").GetAll()
fmt.Println(query) // SELECT id, name FROM my_table

GroupConcat

GroupConcat(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

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

Least(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

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

Max(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

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

Min(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

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

Sum(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

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

Count(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

query := sqb_go.QB.Table("my_table").Select("name").Count("id").GetAll()
fmt.Println(query) // SELECT name, COUNT(id) FROM my_table

Avg

Avg(column: string): Sqb

Parameters:

Name Type Description
column string

Returns:

Sqb

Example

query := sqb_go.QB.Table("my_table").Select("name").Avg("price").GetAll()
fmt.Println(query) // SELECT name, AVG(price) FROM my_table

Releases

No releases published

Packages

No packages published

Languages