Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zikani03/pgadvisorylock
Go library for acquiring and releasing PostgreSQL's Advisory Locks with added support for pgx.
https://github.com/zikani03/pgadvisorylock
advisory-locks golang postgresql
Last synced: 6 days ago
JSON representation
Go library for acquiring and releasing PostgreSQL's Advisory Locks with added support for pgx.
- Host: GitHub
- URL: https://github.com/zikani03/pgadvisorylock
- Owner: zikani03
- License: mit
- Created: 2021-07-06T11:18:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-20T19:25:06.000Z (about 1 year ago)
- Last Synced: 2024-06-20T12:46:04.617Z (7 months ago)
- Topics: advisory-locks, golang, postgresql
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pgadvisorylock
===Go library for acquiring and releasing [PostgreSQL's Advisory Locks](https://www.postgresql.org/docs/13/explicit-locking.html#ADVISORY-LOCKS) with added support for [pgx](https://github.com/jackc/pgx).
## Use in your project
```sh
$ go get github.com/zikani03/pgadvisorylock
```## Example Usage
```go
package mainimport (
"context"
"github.com/zikani03/pgadvisorylock"
)func main() {
// conn is *sql.DB wherever you get your flavour from
ctx := context.Context
ok, id, err := pgadvisorylock.AcquireLock(conn, ctx, "person:1")
if !ok {
panic("Failed to acquire lock")
}ok, err = pgadvisorylock.ReleaseLock(conn, ctx, id)
if !ok {
panic("Failed to release lock")
}ok, id, err = pgadvisorylock.AcquireSharedLock(conn, ctx, "person:1")
if !ok {
panic("Failed to acquire lock")
}advisoryLocks, err = pgadvisorylock.FetchAdvisoryLocks(conn, ctx)
if err != nil {
panic("Failed to fetch locks")
}for _, l := range advisoryLocks {
fmt.Printf("LockID:%s, ClassID:%s, PID:%s\n", string(l.ObjectID), string(l.ClassID), string(l.PID))
}ok, err = pgadvisorylock.ReleaseSharedLock(conn, ctx, id)
if !ok {
panic("Failed to release lock")
}
}
```---
Copyright (c) Zikani Nyirenda Mwase