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.

59 lines
2.4 KiB

  1. -- name: SelectPost :one
  2. SELECT * FROM log_post WHERE id=$1 LIMIT 1;
  3. -- name: SelectLogIDsFromPostSearch :many
  4. SELECT DISTINCT(log_short_id) FROM log_post WHERE "ts_vector" @@ to_tsquery(@search::TEXT);
  5. -- name: SelectPostsByPositionRange :many
  6. SELECT * FROM log_post WHERE log_short_id = @log_short_id AND position >= @from_position AND position = @to_position;
  7. -- name: SelectPosts :many
  8. SELECT * FROM log_post
  9. WHERE (@filter_ids::BOOL = false OR id = ANY(@ids::TEXT[]))
  10. AND (@filter_kinds::BOOL = false OR kind = ANY(@kinds::TEXT[]))
  11. AND (@filter_log_short_id::BOOL = false OR log_short_id = @log_short_id)
  12. AND (@filter_search::BOOL = false OR "ts_vector" @@ to_tsquery(@search::TEXT))
  13. ORDER BY log_short_id, position
  14. LIMIT NULLIF(@limit_size::INT, 0);
  15. -- name: InsertPost :one
  16. INSERT INTO log_post (id, log_short_id, time, kind, nick, text, position, ts_vector)
  17. SELECT @id, @log_short_id, @time, @kind, @nick, @text, COALESCE(MAX(position), 0)+1, to_tsvector(@nick || ' ' || @text)
  18. FROM log_post
  19. WHERE log_short_id=@log_short_id
  20. RETURNING position;
  21. -- name: InsertPosts :one
  22. INSERT INTO log_post (id, log_short_id, time, kind, nick, text, position, ts_vector)
  23. SELECT UNNEST(@ids::TEXT[]), @log_short_id, UNNEST(@times::TIMESTAMP[]), UNNEST(@kinds::TEXT[]),
  24. UNNEST(@nicks::TEXT[]), UNNEST(@texts::TEXT[]), COALESCE(MAX(position), 1) + UNNEST(@offsets::INT[]),
  25. to_tsvector(UNNEST(@nicks::TEXT[]) || ' ' || UNNEST(@texts::TEXT[]))
  26. FROM log_post
  27. WHERE log_short_id = @log_short_id
  28. RETURNING position;
  29. -- name: UpdatePost :exec
  30. UPDATE log_post
  31. SET time = @time,
  32. kind = @kind,
  33. nick = @nick,
  34. text = @text,
  35. ts_vector = to_tsvector(@nick || ' ' || @text)
  36. WHERE id = @id;
  37. -- name: MovePost :exec
  38. UPDATE log_post SET position = @position WHERE id = @id;
  39. -- name: ShiftPostsBetween :exec
  40. UPDATE log_post SET position = position + @shift_offset::INT WHERE log_short_id = @log_short_id AND position >= @from_position AND position <= @to_position;
  41. -- name: ShiftPostsAfter :exec
  42. UPDATE log_post SET position = position + @shift_offset::INT WHERE log_short_id = @log_short_id AND position >= @from_position;
  43. -- name: ShiftPostsBefore :exec
  44. UPDATE log_post SET position = position + @shift_offset::INT WHERE log_short_id = @log_short_id AND position <= @to_position;
  45. -- name: DeletePost :exec
  46. DELETE FROM log_post WHERE id = @id;
  47. -- name: DeletePostsByLogShortID :exec
  48. DELETE FROM log_post WHERE log_short_id = @log_short_id;