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

Commit c84cf7a

Browse files
author
C
committed
Change statement names
1 parent 6758db7 commit c84cf7a

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

postgresql/stats.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,52 @@ package postgresql
22

33
import (
44
"github.com/lib/pq"
5-
6-
"github.com/benchttp/worker/stats"
75
)
86

7+
type Common struct {
8+
Min float64
9+
Max float64
10+
Mean float64
11+
Median float64
12+
StdDev float64
13+
14+
Deciles [9]float64
15+
}
16+
17+
type StatusDistribution struct {
18+
Status1xx int
19+
Status2xx int
20+
Status3xx int
21+
Status4xx int
22+
Status5xx int
23+
}
24+
925
// nolint:gocognit
10-
func (s StatsService) Create(statsToStore stats.Stats, statsID, userID, tag string) error {
26+
func (s StatsService) Create(statsToStore Common, statusToStore StatusDistribution, statsID, userID, tag string) error {
1127
tx, err := s.db.Begin()
1228
if err != nil {
1329
return err
1430
}
1531

16-
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')`)
32+
insertStatsDescriptor, 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')`)
1733
if err != nil {
1834
err = tx.Rollback()
1935
if err != nil {
2036
return ErrExecutingRollback
2137
}
2238
return ErrPreparingStmt
2339
}
24-
defer insertIntoStatsDescriptor.Close()
40+
defer insertStatsDescriptor.Close()
2541

26-
if _, err = insertIntoStatsDescriptor.Exec(statsID, userID, tag); err != nil {
42+
if _, err = insertStatsDescriptor.Exec(statsID, userID, tag); err != nil {
2743
err = tx.Rollback()
2844
if err != nil {
2945
return ErrExecutingRollback
3046
}
3147
return ErrExecutingPreparedStmt
3248
}
3349

34-
insertIntoTimestats, err := tx.Prepare(`INSERT INTO public.timestats(stats_descriptor_id, min, max, mean, median, standard_deviation, deciles) VALUES
50+
insertTimestats, err := tx.Prepare(`INSERT INTO public.timestats(stats_descriptor_id, min, max, mean, median, standard_deviation, deciles) VALUES
3551
($1, $2, $3, $4, $5, $6, $7)`)
3652
if err != nil {
3753
err = tx.Rollback()
@@ -40,9 +56,9 @@ func (s StatsService) Create(statsToStore stats.Stats, statsID, userID, tag stri
4056
}
4157
return ErrPreparingStmt
4258
}
43-
defer insertIntoTimestats.Close()
59+
defer insertTimestats.Close()
4460

45-
if _, err = insertIntoTimestats.Exec(statsID, statsToStore.Min, statsToStore.Max, statsToStore.Mean, statsToStore.Median, statsToStore.StdDev, pq.Array(statsToStore.Deciles)); err != nil {
61+
if _, err = insertTimestats.Exec(statsID, statsToStore.Min, statsToStore.Max, statsToStore.Mean, statsToStore.Median, statsToStore.StdDev, pq.Array(statsToStore.Deciles)); err != nil {
4662
err = tx.Rollback()
4763
if err != nil {
4864
return ErrExecutingRollback

0 commit comments

Comments
 (0)