-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.go
49 lines (37 loc) · 981 Bytes
/
result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pgsqlxx
import (
"errors"
"github.com/jackc/pgx"
)
func ResultFromCommandTag(t pgx.CommandTag) *Result {
return &Result{affected: t.RowsAffected(), err: nil}
}
func ResultFromExec(t pgx.CommandTag, err error) *Result {
if err != nil {
return &Result{affected: 0, err: err}
}
return &Result{affected: t.RowsAffected(), err: nil}
}
// Make it fit with database/sql Result interface
type Result struct {
affected int64
err error
}
func (r *Result) LastInsertId() (int64, error) {
return 0, errors.New("pgx does not support LastInsertId, try a Query with RETURNING")
}
func (r *Result) RowsAffected() (int64, error) {
return r.affected, r.err
}
func (r *Result) RowsAffectedx() int64 {
return r.affected
}
func (r *Result) LastInsertIdx() int64 {
return 0
}
func (r *Result) RowsAffectedErr() error {
return r.err
}
func (r *Result) LastInsertIdErr() error {
return errors.New("pgx does not support LastInsertId, try a Query with RETURNING")
}