-
Notifications
You must be signed in to change notification settings - Fork 110
/
rate_limits.sql.go
57 lines (51 loc) · 1.13 KB
/
rate_limits.sql.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
50
51
52
53
54
55
56
57
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.24.0
// source: rate_limits.sql
package dbsqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const upsertRateLimit = `-- name: UpsertRateLimit :one
INSERT INTO "RateLimit" (
"tenantId",
"key",
"limitValue",
"value",
"window"
) VALUES (
$1::uuid,
$2::text,
$3::int,
$3::int,
COALESCE($4::text, '1 minute')
) ON CONFLICT ("tenantId", "key") DO UPDATE SET
"limitValue" = $3::int,
"window" = COALESCE($4::text, '1 minute')
RETURNING "tenantId", key, "limitValue", value, "window", "lastRefill"
`
type UpsertRateLimitParams struct {
Tenantid pgtype.UUID `json:"tenantid"`
Key string `json:"key"`
Limit int32 `json:"limit"`
Window pgtype.Text `json:"window"`
}
func (q *Queries) UpsertRateLimit(ctx context.Context, db DBTX, arg UpsertRateLimitParams) (*RateLimit, error) {
row := db.QueryRow(ctx, upsertRateLimit,
arg.Tenantid,
arg.Key,
arg.Limit,
arg.Window,
)
var i RateLimit
err := row.Scan(
&i.TenantId,
&i.Key,
&i.LimitValue,
&i.Value,
&i.Window,
&i.LastRefill,
)
return &i, err
}