GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: counter.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. )
  7. const bumpCounter = `-- name: BumpCounter :exec
  8. UPDATE core_counter SET value = value + 1 WHERE id = $1::text AND value <= $2::int
  9. `
  10. type BumpCounterParams struct {
  11. ID string `json:"id"`
  12. Value int32 `json:"value"`
  13. }
  14. func (q *Queries) BumpCounter(ctx context.Context, arg BumpCounterParams) error {
  15. _, err := q.db.ExecContext(ctx, bumpCounter, arg.ID, arg.Value)
  16. return err
  17. }
  18. const ensureCounter = `-- name: EnsureCounter :exec
  19. INSERT INTO core_counter (id, value) VALUES ($1::text, 0) ON CONFLICT DO NOTHING
  20. `
  21. func (q *Queries) EnsureCounter(ctx context.Context, dollar_1 string) error {
  22. _, err := q.db.ExecContext(ctx, ensureCounter, dollar_1)
  23. return err
  24. }
  25. const incrementCounter = `-- name: IncrementCounter :one
  26. UPDATE core_counter SET value = value + 1 WHERE id = $1::text RETURNING value::int
  27. `
  28. func (q *Queries) IncrementCounter(ctx context.Context, dollar_1 string) (int32, error) {
  29. row := q.db.QueryRowContext(ctx, incrementCounter, dollar_1)
  30. var value int32
  31. err := row.Scan(&value)
  32. return value, err
  33. }