https://github.com/johejo/sqlbuilder
A very simple SQL builder
https://github.com/johejo/sqlbuilder
go golang sql sqlbuilder
Last synced: 10 months ago
JSON representation
A very simple SQL builder
- Host: GitHub
- URL: https://github.com/johejo/sqlbuilder
- Owner: johejo
- License: mit
- Created: 2020-06-10T14:23:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-26T21:03:52.000Z (over 3 years ago)
- Last Synced: 2024-12-29T19:59:26.246Z (12 months ago)
- Topics: go, golang, sql, sqlbuilder
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlbuilder
[](https://github.com/johejo/sqlbuilder/actions?query=workflow%3Aci)
[](https://pkg.go.dev/github.com/johejo/sqlbuilder)
[](https://codecov.io/gh/johejo/sqlbuilder)
[](https://goreportcard.com/report/github.com/johejo/sqlbuilder)
## Description
Package sqlbuilder provides minimal functionality for building raw queries.
## Example
```go
package sqlbuilder_test
import (
"fmt"
"github.com/johejo/sqlbuilder"
)
func ExampleBuilder() {
var b sqlbuilder.Builder
b.Append("SELECT * FROM test_user WHERE id = ? ", 1) // with trailing space
b.Append("AND name = ?", "John") // without trailing space
b.Append(" ORDER BY name LIMIT ?, ?", 0, 10) // with space at the beginning
q, args := b.Build()
fmt.Println(q)
fmt.Println(args)
// Output:
// SELECT * FROM test_user WHERE id = ? AND name = ? ORDER BY name LIMIT ?, ?
// [1 John 0 10]
}
func ExampleBulkBuilder() {
b, err := sqlbuilder.NewBulkBuilder("INSERT INTO tbl_name (a,b,c) VALUES (?)")
if err != nil {
panic(err)
}
if err := b.Bind("A", "B", "C"); err != nil {
panic(err)
}
if err := b.Bind("AA", "BB", "CC"); err != nil {
panic(err)
}
q, args := b.Build()
fmt.Println(q)
fmt.Println(args)
// Output:
// INSERT INTO tbl_name (a,b,c) VALUES (?,?,?),(?,?,?)
// [A B C AA BB CC]
}
```
## License
MIT
## Author
Mitsuo Heijo (@johejo)