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.

46 lines
1.6 KiB

  1. -- name: SelectCharacterByID :one
  2. SELECT * FROM data_character WHERE id = @id::text;
  3. -- name: SelectCharacterByNick :one
  4. SELECT * FROM data_character WHERE nicks <@ ARRAY[@nick::text];
  5. -- name: SelectCharacterByName :one
  6. SELECT * FROM data_character WHERE name = @name::text;
  7. -- name: SelectCharacters :many
  8. SELECT * FROM data_character
  9. WHERE (@filter_id::bool = false OR id = ANY(@ids::text[]))
  10. AND (@filter_name::bool = false OR name = ANY(@names::text[]))
  11. AND (@filter_nick::bool = false OR nicks && (@nicks::text[]))
  12. AND (@filter_author::bool = false OR author = @author::text)
  13. AND (@filter_search::bool = false OR "ts_vector" @@ to_tsquery(@search::text))
  14. LIMIT NULLIF(@limit_size::INT, 0);
  15. -- name: InsertCharacter :exec
  16. INSERT INTO data_character (id, nicks, name, short_name, author, description, ts_vector) VALUES (
  17. @id::text, @nicks::text[], @name::text,
  18. @short_name::text, @author::text, @description::text,
  19. to_tsvector(
  20. 'english', @name::text || ' ' || @description::text || ' ' || @author::text || ' '
  21. || immutable_array_to_string(@nicks::text[], ' ')
  22. )
  23. );
  24. -- name: UpdateCharacter :exec
  25. UPDATE data_character
  26. SET name = @name::text,
  27. short_name = @short_name::text,
  28. description = @description::text
  29. WHERE id = @id::text;
  30. -- name: AddCharacterNick :exec
  31. UPDATE data_character
  32. SET nicks=array_append(nicks, @nick::text)
  33. WHERE id = @id::text;
  34. -- name: RemoveCharacterNick :exec
  35. UPDATE data_character
  36. SET nicks=array_remove(nicks, @nick::text)
  37. WHERE id = @id::text;
  38. -- name: DeleteCharacter :exec
  39. DELETE FROM data_character WHERE id=$1;