Skip to content

Commit 8610c82

Browse files
committed
update docs
1 parent e116858 commit 8610c82

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
11
# go-postgres
22
A simple mockable postgres db interface
33

4+
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/GolangToolKits/go-postgres)](https://goreportcard.com/report/github.com/GolangToolKits/go-postgres)
6+
7+
```go
8+
9+
mm := &PgDB{
10+
Host: "localhost",
11+
Port: "5432",
12+
User: "test",
13+
Password: "test",
14+
Database: "test",
15+
}
16+
m := mm.New()
17+
m.Connect()
18+
//Insert requires RETURNING id on end of prepared statement query
19+
//Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
20+
m.Insert(query, args...)
21+
m.Update(query, args...)
22+
m.Get(query, args...)
23+
m.GetList(query, args...)
24+
m.Delete(query, args...)
25+
26+
```
27+
28+
## Also Supports Transactions
29+
30+
```go
31+
mm := &PgDB{
32+
Host: "localhost",
33+
Port: "5432",
34+
User: "test",
35+
Password: "test",
36+
Database: "test",
37+
}
38+
m := mm.New()
39+
m.Connect()
40+
tr := m.BeginTransaction()
41+
//Insert requires RETURNING id on end of prepared statement query
42+
//Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
43+
tr.Insert(query, args...)
44+
tr.Update(query, args...)
45+
tr.Get(query, args...)
46+
tr.GetList(query, args...)
47+
tr.Delete(query, args...)
48+
tr.Commit()
49+
//Or
50+
tr.Rollback()
51+
52+
53+
```

0 commit comments

Comments
 (0)