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.

235 lines
5.9 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: characters.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. "github.com/lib/pq"
  7. )
  8. const addCharacterNick = `-- name: AddCharacterNick :exec
  9. UPDATE data_character
  10. SET nicks=append(nicks, $1::text)
  11. WHERE id=$2::text
  12. `
  13. type AddCharacterNickParams struct {
  14. Nick string `json:"nick"`
  15. ID string `json:"id"`
  16. }
  17. func (q *Queries) AddCharacterNick(ctx context.Context, arg AddCharacterNickParams) error {
  18. _, err := q.db.ExecContext(ctx, addCharacterNick, arg.Nick, arg.ID)
  19. return err
  20. }
  21. const deleteCharacter = `-- name: DeleteCharacter :exec
  22. DELETE FROM data_character WHERE id=$1
  23. `
  24. func (q *Queries) DeleteCharacter(ctx context.Context, id string) error {
  25. _, err := q.db.ExecContext(ctx, deleteCharacter, id)
  26. return err
  27. }
  28. const insertCharacter = `-- name: InsertCharacter :exec
  29. INSERT INTO data_character (id, nicks, name, short_name, author, description, ts_vector) VALUES (
  30. $1::text, $2::text[], $3::text,
  31. $4::text, $5::text, $6::text,
  32. to_tsvector(
  33. 'english',
  34. $3::text || ' ' || $6::text || ' ' || $5::text || ' '
  35. || immutable_array_to_string(
  36. $2::text[], ' '
  37. )
  38. )
  39. )
  40. `
  41. type InsertCharacterParams struct {
  42. ID string `json:"id"`
  43. Nicks []string `json:"nicks"`
  44. Name string `json:"name"`
  45. ShortName string `json:"short_name"`
  46. Author string `json:"author"`
  47. Description string `json:"description"`
  48. }
  49. func (q *Queries) InsertCharacter(ctx context.Context, arg InsertCharacterParams) error {
  50. _, err := q.db.ExecContext(ctx, insertCharacter,
  51. arg.ID,
  52. pq.Array(arg.Nicks),
  53. arg.Name,
  54. arg.ShortName,
  55. arg.Author,
  56. arg.Description,
  57. )
  58. return err
  59. }
  60. const removeCharacterNick = `-- name: RemoveCharacterNick :exec
  61. UPDATE data_character
  62. SET nicks=array_remove(nicks, $1::text)
  63. WHERE id=$2::text
  64. `
  65. type RemoveCharacterNickParams struct {
  66. Nick string `json:"nick"`
  67. ID string `json:"id"`
  68. }
  69. func (q *Queries) RemoveCharacterNick(ctx context.Context, arg RemoveCharacterNickParams) error {
  70. _, err := q.db.ExecContext(ctx, removeCharacterNick, arg.Nick, arg.ID)
  71. return err
  72. }
  73. const selectCharacterByID = `-- name: SelectCharacterByID :one
  74. SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE id = $1::text
  75. `
  76. func (q *Queries) SelectCharacterByID(ctx context.Context, id string) (DataCharacter, error) {
  77. row := q.db.QueryRowContext(ctx, selectCharacterByID, id)
  78. var i DataCharacter
  79. err := row.Scan(
  80. &i.ID,
  81. pq.Array(&i.Nicks),
  82. &i.Name,
  83. &i.ShortName,
  84. &i.Author,
  85. &i.Description,
  86. &i.TsVector,
  87. )
  88. return i, err
  89. }
  90. const selectCharacterByName = `-- name: SelectCharacterByName :one
  91. SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE name = $1::text
  92. `
  93. func (q *Queries) SelectCharacterByName(ctx context.Context, name string) (DataCharacter, error) {
  94. row := q.db.QueryRowContext(ctx, selectCharacterByName, name)
  95. var i DataCharacter
  96. err := row.Scan(
  97. &i.ID,
  98. pq.Array(&i.Nicks),
  99. &i.Name,
  100. &i.ShortName,
  101. &i.Author,
  102. &i.Description,
  103. &i.TsVector,
  104. )
  105. return i, err
  106. }
  107. const selectCharacterByNick = `-- name: SelectCharacterByNick :one
  108. SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE nicks <@ ARRAY[$1::text]
  109. `
  110. func (q *Queries) SelectCharacterByNick(ctx context.Context, nick string) (DataCharacter, error) {
  111. row := q.db.QueryRowContext(ctx, selectCharacterByNick, nick)
  112. var i DataCharacter
  113. err := row.Scan(
  114. &i.ID,
  115. pq.Array(&i.Nicks),
  116. &i.Name,
  117. &i.ShortName,
  118. &i.Author,
  119. &i.Description,
  120. &i.TsVector,
  121. )
  122. return i, err
  123. }
  124. const selectCharacters = `-- name: SelectCharacters :many
  125. SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character
  126. WHERE ($1::bool = false OR id = ANY($2::text[]))
  127. AND ($3::bool = false OR name = ANY($4::text[]))
  128. AND ($5::bool = false OR nicks && ($6::text[]))
  129. AND ($7::bool = false OR author = $8::text)
  130. AND ($9::bool = false OR "ts_vector" @@ to_tsquery($10::text))
  131. LIMIT $11::int
  132. `
  133. type SelectCharactersParams struct {
  134. FilterID bool `json:"filter_id"`
  135. Ids []string `json:"ids"`
  136. FilterName bool `json:"filter_name"`
  137. Names []string `json:"names"`
  138. FilterNick bool `json:"filter_nick"`
  139. Nicks []string `json:"nicks"`
  140. FilterAuthor bool `json:"filter_author"`
  141. Author string `json:"author"`
  142. FilterSearch bool `json:"filter_search"`
  143. Search string `json:"search"`
  144. LimitSize int32 `json:"limit_size"`
  145. }
  146. func (q *Queries) SelectCharacters(ctx context.Context, arg SelectCharactersParams) ([]DataCharacter, error) {
  147. rows, err := q.db.QueryContext(ctx, selectCharacters,
  148. arg.FilterID,
  149. pq.Array(arg.Ids),
  150. arg.FilterName,
  151. pq.Array(arg.Names),
  152. arg.FilterNick,
  153. pq.Array(arg.Nicks),
  154. arg.FilterAuthor,
  155. arg.Author,
  156. arg.FilterSearch,
  157. arg.Search,
  158. arg.LimitSize,
  159. )
  160. if err != nil {
  161. return nil, err
  162. }
  163. defer rows.Close()
  164. items := []DataCharacter{}
  165. for rows.Next() {
  166. var i DataCharacter
  167. if err := rows.Scan(
  168. &i.ID,
  169. pq.Array(&i.Nicks),
  170. &i.Name,
  171. &i.ShortName,
  172. &i.Author,
  173. &i.Description,
  174. &i.TsVector,
  175. ); err != nil {
  176. return nil, err
  177. }
  178. items = append(items, i)
  179. }
  180. if err := rows.Close(); err != nil {
  181. return nil, err
  182. }
  183. if err := rows.Err(); err != nil {
  184. return nil, err
  185. }
  186. return items, nil
  187. }
  188. const updateCharacter = `-- name: UpdateCharacter :exec
  189. UPDATE data_character
  190. SET name=$1::text,
  191. short_name=$2::text,
  192. description=$3::text
  193. WHERE id=$4::text
  194. `
  195. type UpdateCharacterParams struct {
  196. Name string `json:"name"`
  197. ShortName string `json:"short_name"`
  198. Description string `json:"description"`
  199. ID string `json:"id"`
  200. }
  201. func (q *Queries) UpdateCharacter(ctx context.Context, arg UpdateCharacterParams) error {
  202. _, err := q.db.ExecContext(ctx, updateCharacter,
  203. arg.Name,
  204. arg.ShortName,
  205. arg.Description,
  206. arg.ID,
  207. )
  208. return err
  209. }