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.

153 lines
3.6 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: channels.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. "github.com/lib/pq"
  7. )
  8. const deleteChannel = `-- name: DeleteChannel :exec
  9. DELETE FROM data_channel WHERE name=$1
  10. `
  11. func (q *Queries) DeleteChannel(ctx context.Context, name string) error {
  12. _, err := q.db.ExecContext(ctx, deleteChannel, name)
  13. return err
  14. }
  15. const insertChannel = `-- name: InsertChannel :exec
  16. INSERT INTO data_channel (name, logged, hub, event_name, location_name)
  17. VALUES (
  18. $1::text,
  19. $2::boolean, $3::boolean,
  20. $4::text, $5::text
  21. )
  22. `
  23. type InsertChannelParams struct {
  24. Name string `json:"name"`
  25. Logged bool `json:"logged"`
  26. Hub bool `json:"hub"`
  27. EventName string `json:"event_name"`
  28. LocationName string `json:"location_name"`
  29. }
  30. func (q *Queries) InsertChannel(ctx context.Context, arg InsertChannelParams) error {
  31. _, err := q.db.ExecContext(ctx, insertChannel,
  32. arg.Name,
  33. arg.Logged,
  34. arg.Hub,
  35. arg.EventName,
  36. arg.LocationName,
  37. )
  38. return err
  39. }
  40. const selectChannelByName = `-- name: SelectChannelByName :one
  41. SELECT name, logged, hub, event_name, location_name FROM data_channel WHERE name = $1 LIMIT 1
  42. `
  43. func (q *Queries) SelectChannelByName(ctx context.Context, name string) (DataChannel, error) {
  44. row := q.db.QueryRowContext(ctx, selectChannelByName, name)
  45. var i DataChannel
  46. err := row.Scan(
  47. &i.Name,
  48. &i.Logged,
  49. &i.Hub,
  50. &i.EventName,
  51. &i.LocationName,
  52. )
  53. return i, err
  54. }
  55. const selectChannels = `-- name: SelectChannels :many
  56. SELECT name, logged, hub, event_name, location_name FROM data_channel
  57. WHERE ($1::bool = false OR name = ANY($2::text[]))
  58. AND ($3::bool = false OR logged = $4)
  59. AND ($5::bool = false OR event_name = $6)
  60. AND ($7::bool = false OR location_name = $8)
  61. ORDER BY name
  62. LIMIT $9::int
  63. `
  64. type SelectChannelsParams struct {
  65. FilterName bool `json:"filter_name"`
  66. Names []string `json:"names"`
  67. FilterLogged bool `json:"filter_logged"`
  68. Logged bool `json:"logged"`
  69. FilterEventName bool `json:"filter_event_name"`
  70. EventName string `json:"event_name"`
  71. FilterLocationName bool `json:"filter_location_name"`
  72. LocationName string `json:"location_name"`
  73. LimitSize int32 `json:"limit_size"`
  74. }
  75. func (q *Queries) SelectChannels(ctx context.Context, arg SelectChannelsParams) ([]DataChannel, error) {
  76. rows, err := q.db.QueryContext(ctx, selectChannels,
  77. arg.FilterName,
  78. pq.Array(arg.Names),
  79. arg.FilterLogged,
  80. arg.Logged,
  81. arg.FilterEventName,
  82. arg.EventName,
  83. arg.FilterLocationName,
  84. arg.LocationName,
  85. arg.LimitSize,
  86. )
  87. if err != nil {
  88. return nil, err
  89. }
  90. defer rows.Close()
  91. items := []DataChannel{}
  92. for rows.Next() {
  93. var i DataChannel
  94. if err := rows.Scan(
  95. &i.Name,
  96. &i.Logged,
  97. &i.Hub,
  98. &i.EventName,
  99. &i.LocationName,
  100. ); err != nil {
  101. return nil, err
  102. }
  103. items = append(items, i)
  104. }
  105. if err := rows.Close(); err != nil {
  106. return nil, err
  107. }
  108. if err := rows.Err(); err != nil {
  109. return nil, err
  110. }
  111. return items, nil
  112. }
  113. const updateChannel = `-- name: UpdateChannel :exec
  114. UPDATE data_channel
  115. SET logged=$1::boolean,
  116. hub=$2::boolean,
  117. event_name=$3::text,
  118. location_name=$4::text
  119. WHERE name=$5::text
  120. `
  121. type UpdateChannelParams struct {
  122. Logged bool `json:"logged"`
  123. Hub bool `json:"hub"`
  124. EventName string `json:"event_name"`
  125. LocationName string `json:"location_name"`
  126. Name string `json:"name"`
  127. }
  128. func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) error {
  129. _, err := q.db.ExecContext(ctx, updateChannel,
  130. arg.Logged,
  131. arg.Hub,
  132. arg.EventName,
  133. arg.LocationName,
  134. arg.Name,
  135. )
  136. return err
  137. }