https://github.com/cristalhq/pgxutil
Go jackc/pgx helper to write proper transactions
https://github.com/cristalhq/pgxutil
database go golang pgx postgres transactions
Last synced: 6 months ago
JSON representation
Go jackc/pgx helper to write proper transactions
- Host: GitHub
- URL: https://github.com/cristalhq/pgxutil
- Owner: cristalhq
- License: mit
- Created: 2021-11-06T12:25:37.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-28T20:02:37.000Z (over 2 years ago)
- Last Synced: 2025-03-23T03:24:49.005Z (7 months ago)
- Topics: database, go, golang, pgx, postgres, transactions
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pgxutil
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]Go [jackc/pgx](https://github.com/jackc/pgx) helper to write proper transactions.
## Features
* Simple API.
## Install
Go version 1.17+
```
go get github.com/cristalhq/pgxutil
```## Example
```go
// create jackc/pgx pool
var pool *pgxpool.Pooldb, err := pgxutil.New(pool)
if err != nil {
panic(err)
}ctx := context.Background()
// to make transaction with a given isolation level
level := pgx.Serializable
errTx := db.InWriteTx(ctx, level, func(tx pgx.Tx) error {
// TODO: good query with tx
return nil
})
if errTx != nil {
panic(errTx)
}// to make read-only transaction with a read committed isolation level
errRead := db.InReadTx(ctx, func(tx pgx.Tx) error {
// TODO: good read-only query with tx
return nil
})
if errRead != nil {
panic(errRead)
}
```Also see examples: [examples_test.go](https://github.com/cristalhq/pgxutil/blob/main/example_test.go).
## Documentation
See [these docs][pkg-url].
## License
[MIT License](LICENSE).
[build-img]: https://github.com/cristalhq/pgxutil/workflows/build/badge.svg
[build-url]: https://github.com/cristalhq/pgxutil/actions
[pkg-img]: https://pkg.go.dev/badge/cristalhq/pgxutil
[pkg-url]: https://pkg.go.dev/github.com/cristalhq/pgxutil
[reportcard-img]: https://goreportcard.com/badge/cristalhq/pgxutil
[reportcard-url]: https://goreportcard.com/report/cristalhq/pgxutil
[coverage-img]: https://codecov.io/gh/cristalhq/pgxutil/branch/main/graph/badge.svg
[coverage-url]: https://codecov.io/gh/cristalhq/pgxutil