https://github.com/daniilty/pgxquery
simple library for generating pgx queries from go struct
https://github.com/daniilty/pgxquery
Last synced: about 2 months ago
JSON representation
simple library for generating pgx queries from go struct
- Host: GitHub
- URL: https://github.com/daniilty/pgxquery
- Owner: daniilty
- Created: 2022-06-21T11:39:57.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T19:49:07.000Z (about 4 years ago)
- Last Synced: 2025-01-26T01:20:29.790Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## pqxquery library
## Add to your project
```bash
$ go get github.com/daniilty/pgxquery
```
## Usage
```golang
type user struct {
pgxquery.TableName `db:"users"` // set here the name of related table
id int `db:"id,primarykey"` // primarykey tag used for updating by in update query
name string `db:"name,omitempty"` // omitempty is used for update queries(field will be omitted if zero value)
email string `db:"email"`
}
func insertUsers(...) {
q, _ := pgxquery.GenerateNamedUpdate(&user{
id: 1,
email: "pablo@gmail.com",
})
//will result in:
//update users set email=:email where id=:id;
}
```