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.

152 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. LIMIT $9::int
  62. `
  63. type SelectChannelsParams struct {
  64. FilterName bool `json:"filter_name"`
  65. Names []string `json:"names"`
  66. FilterLogged bool `json:"filter_logged"`
  67. Logged bool `json:"logged"`
  68. FilterEventName bool `json:"filter_event_name"`
  69. EventName string `json:"event_name"`
  70. FilterLocationName bool `json:"filter_location_name"`
  71. LocationName string `json:"location_name"`
  72. LimitSize int32 `json:"limit_size"`
  73. }
  74. func (q *Queries) SelectChannels(ctx context.Context, arg SelectChannelsParams) ([]DataChannel, error) {
  75. rows, err := q.db.QueryContext(ctx, selectChannels,
  76. arg.FilterName,
  77. pq.Array(arg.Names),
  78. arg.FilterLogged,
  79. arg.Logged,
  80. arg.FilterEventName,
  81. arg.EventName,
  82. arg.FilterLocationName,
  83. arg.LocationName,
  84. arg.LimitSize,
  85. )
  86. if err != nil {
  87. return nil, err
  88. }
  89. defer rows.Close()
  90. items := []DataChannel{}
  91. for rows.Next() {
  92. var i DataChannel
  93. if err := rows.Scan(
  94. &i.Name,
  95. &i.Logged,
  96. &i.Hub,
  97. &i.EventName,
  98. &i.LocationName,
  99. ); err != nil {
  100. return nil, err
  101. }
  102. items = append(items, i)
  103. }
  104. if err := rows.Close(); err != nil {
  105. return nil, err
  106. }
  107. if err := rows.Err(); err != nil {
  108. return nil, err
  109. }
  110. return items, nil
  111. }
  112. const updateChannel = `-- name: UpdateChannel :exec
  113. UPDATE data_channel
  114. SET logged=$1::boolean,
  115. hub=$2::boolean,
  116. event_name=$3::text,
  117. location_name=$4::text
  118. WHERE name=$5::text
  119. `
  120. type UpdateChannelParams struct {
  121. Logged bool `json:"logged"`
  122. Hub bool `json:"hub"`
  123. EventName string `json:"event_name"`
  124. LocationName string `json:"location_name"`
  125. Name string `json:"name"`
  126. }
  127. func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) error {
  128. _, err := q.db.ExecContext(ctx, updateChannel,
  129. arg.Logged,
  130. arg.Hub,
  131. arg.EventName,
  132. arg.LocationName,
  133. arg.Name,
  134. )
  135. return err
  136. }