Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Commit cd23966

Browse files
author
C
committed
stats.go with Create() method
1 parent 598a0b4 commit cd23966

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

postgresql/stats.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package postgresql
2+
3+
import (
4+
"github.com/benchttp/worker/stats"
5+
)
6+
7+
func (s StatsService) Create(stats stats.Stats, statsId, userId, tag string) error {
8+
tx, err := s.db.Begin()
9+
if err != nil {
10+
return err
11+
}
12+
13+
insertIntoStatsDescriptor, err := tx.Prepare(`INSERT INTO public.stats_descriptor(id, user_id, tag, finished_at) VALUES($1, $2, $3, '2022-03-03 17:36:38-02')`)
14+
if err != nil {
15+
tx.Rollback()
16+
return ErrPreparingStmt
17+
}
18+
defer insertIntoStatsDescriptor.Close()
19+
20+
if _, err = insertIntoStatsDescriptor.Exec(statsId, userId, tag); err != nil {
21+
tx.Rollback()
22+
return ErrExecutingPreparedStmt
23+
}
24+
err = tx.Commit()
25+
if err != nil {
26+
tx.Rollback()
27+
return err
28+
}
29+
return nil
30+
}

0 commit comments

Comments
 (0)