https://github.com/golangtoolkits/go-postgres
A simple mockable postgres db interface
https://github.com/golangtoolkits/go-postgres
database go golang postgres postgresql postgresql-database
Last synced: 2 months ago
JSON representation
A simple mockable postgres db interface
- Host: GitHub
- URL: https://github.com/golangtoolkits/go-postgres
- Owner: GolangToolKits
- License: mit
- Created: 2023-05-11T00:05:50.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-11T23:43:00.000Z (about 3 years ago)
- Last Synced: 2025-08-11T06:35:30.983Z (11 months ago)
- Topics: database, go, golang, postgres, postgresql, postgresql-database
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-postgres
A simple mockable postgres db interface
[](https://goreportcard.com/report/github.com/GolangToolKits/go-postgres)
```go
mm := &PgDB{
Host: "localhost",
Port: "5432",
User: "test",
Password: "test",
Database: "test",
}
m := mm.New()
m.Connect()
//Insert requires RETURNING id on end of prepared statement query
//Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
m.Insert(query, args...)
m.Update(query, args...)
m.Get(query, args...)
m.GetList(query, args...)
m.Delete(query, args...)
```
## Also Supports Transactions
```go
mm := &PgDB{
Host: "localhost",
Port: "5432",
User: "test",
Password: "test",
Database: "test",
}
m := mm.New()
m.Connect()
tr := m.BeginTransaction()
//Insert requires RETURNING id on end of prepared statement query
//Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
tr.Insert(query, args...)
tr.Update(query, args...)
tr.Get(query, args...)
tr.GetList(query, args...)
tr.Delete(query, args...)
tr.Commit()
//Or
tr.Rollback()
```