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.

44 lines
1.7 KiB

  1. -- name: SelectLog :one
  2. SELECT id, short_id, character_ids, date, channel_name, event_name, title, description, open FROM log WHERE id=$1 OR short_id=$1 LIMIT 1;
  3. -- name: SelectLogs :many
  4. SELECT id, short_id, character_ids, date, channel_name, event_name, title, description, open FROM log
  5. WHERE (@filter_short_id::BOOL = false OR short_id = ANY(@short_ids::TEXT[]))
  6. AND (@filter_character_id::BOOL = false OR character_ids @> (@character_ids::TEXT[]))
  7. AND (@filter_channel_name::BOOL = false OR channel_name = ANY(@channel_names::TEXT[]))
  8. AND (@filter_event_name::BOOL = false OR event_name = ANY(@event_names::TEXT[]))
  9. AND (@filter_open::BOOL = false OR open = @open::BOOL)
  10. AND (@filter_earlist_date::BOOL = false OR date >= @earliest_date::TIMESTAMP)
  11. AND (@filter_lastest_date::BOOL = false OR date <= @latest_date::TIMESTAMP)
  12. AND (@filter_search::BOOL = false OR "ts_vector" @@ to_tsquery(@search::TEXT))
  13. ORDER BY date DESC
  14. LIMIT NULLIF(@limit_size::INT, 0);
  15. -- name: InsertLog :exec
  16. INSERT INTO log (id, short_id, character_ids, date, channel_name, event_name, title, description, open)
  17. VALUES (
  18. @id, @short_id, @character_ids, @date, @channel_name, @event_name, @title, @description, @open
  19. );
  20. -- name: UpdateLog :exec
  21. UPDATE log
  22. SET title = @title,
  23. event_name = @event_name,
  24. description = @description,
  25. open = @open,
  26. character_ids = @character_ids
  27. WHERE id = @id;
  28. -- name: GenerateLogTSVector :exec
  29. UPDATE log
  30. SET "ts_vector" = (
  31. SELECT TO_TSVECTOR(
  32. immutable_array_to_string(array_agg(text), '\n\n')
  33. )
  34. FROM log_post
  35. WHERE log_short_id = @short_id
  36. )
  37. WHERE short_id = @short_id;
  38. -- name: DeleteLog :exec
  39. DELETE FROM log WHERE id=$1;