Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mackee/go-sqlla
Type safe, reflect free, generative SQL Builder + ORM-like methods
https://github.com/mackee/go-sqlla
go golang orm query-builder sql
Last synced: 16 days ago
JSON representation
Type safe, reflect free, generative SQL Builder + ORM-like methods
- Host: GitHub
- URL: https://github.com/mackee/go-sqlla
- Owner: mackee
- License: mit
- Created: 2015-08-23T08:01:46.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T02:31:36.000Z (2 months ago)
- Last Synced: 2024-09-09T03:44:32.755Z (2 months ago)
- Topics: go, golang, orm, query-builder, sql
- Language: Go
- Homepage:
- Size: 506 KB
- Stars: 44
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sqlla
Type safe, reflect free, generative SQL Builder## INSTALL
```
$ go install github.com/mackee/go-sqlla/v2/cmd/sqlla@latest
```## SYNOPSIS
**person.go**:
```go
package table//go:generate sqlla
//+table: person
type Person struct {
ID uint64 `db:"id"`
FirstName string `db:"first_name"`
LastName string `db:"last_name"`
}
```Run generate:
```
$ ls
person.go
$ go generate
$ ls
person.go person_auto.go
```Same package as the person.go:
```goimport (
"database/sql"
"log"_ "github.com/mattn/go-sqlite3"
)func main() {
db, err := sql.Open("sqlite3", "./foo.db")
if err != nil {
log.Fatalf("failed connect database: %s", err)
}q := NewPersonSQL().Select().ID(uint64(1))
query, args, err := q.ToSql()
if err != nil {
log.Fatalf("query build error: %s", err)
}row := db.QueryRow(query, args...)
var id uint64
var firstName, lastName string
err = row.Scan(&id, &firstName, &lastName)
if err != nil {
log.Fatalf("query exec error: %s", err)
}
log.Printf("id=%d, first_name=%s, last_name=%s", id, firstName, lastName)
}
```