Loggest thy stuff
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.

124 lines
4.0 KiB

3 years ago
3 years ago
  1. -- name: GetItem :one
  2. SELECT i.*, pr.project_id FROM item i
  3. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  4. WHERE i.id = ?;
  5. -- name: ListItemsByProject :many
  6. SELECT i.*, pr.project_id FROM item i
  7. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  8. WHERE pr.project_id = ?;
  9. -- name: ListItemsAcquiredBetween :many
  10. SELECT i.*, pr.project_id FROM item i
  11. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  12. WHERE i.acquired_time >= ?
  13. AND i.acquired_time <= ?
  14. AND i.scope_id = ?
  15. ORDER BY acquired_time DESC, created_time DESC;
  16. -- name: ListItemsScheduledBetween :many
  17. SELECT i.*, pr.project_id FROM item i
  18. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  19. WHERE i.scheduled_date >= ?
  20. AND i.scheduled_date <= ?
  21. AND i.scope_id = ?
  22. ORDER BY scheduled_date, created_time;
  23. -- name: ListItemsCreatedBetween :many
  24. SELECT i.*, pr.project_id FROM item i
  25. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  26. WHERE i.created_time >= ?
  27. AND i.created_time <= ?
  28. AND i.scope_id = ?
  29. ORDER BY created_time DESC;
  30. -- name: ListItemsLooseBetween :many
  31. SELECT i.*, pr.project_id FROM item i
  32. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  33. WHERE i.created_time >= ?
  34. AND i.created_time <= ?
  35. AND i.scope_id = ?
  36. AND i.scheduled_date IS NULL
  37. AND i.acquired_time IS NULL
  38. AND i.project_requirement_id IS NULL
  39. ORDER BY created_time DESC;
  40. -- name: ListItemsScheduledBetweenNoScope :many
  41. SELECT i.*, pr.project_id FROM item i
  42. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  43. WHERE i.scheduled_date >= ?
  44. AND i.scheduled_date < ?;
  45. -- name: ListItemsCreatedBetweenNoScope :many
  46. SELECT i.*, pr.project_id FROM item i
  47. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  48. WHERE i.created_time >= ?
  49. AND i.created_time < ?;
  50. -- name: ListItemsLooseBetweenNoScope :many
  51. SELECT i.*, pr.project_id FROM item i
  52. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  53. WHERE i.created_time >= ?
  54. AND i.created_time < ?
  55. AND i.scheduled_date IS NULL
  56. AND i.acquired_time IS NULL;
  57. -- name: GetItemStatProgressBetween :one
  58. SELECT s.id, s.name, s.weight, SUM(isp.acquired), SUM(isp.required) FROM item i
  59. LEFT JOIN item_stat_progress isp on i.id = isp.item_id
  60. LEFT JOIN stat s on isp.stat_id = s.id
  61. WHERE i.acquired_time >= ?
  62. AND i.acquired_time < ?
  63. AND i.scope_id = ?
  64. GROUP BY stat_id;
  65. -- name: ListItemStatProgress :many
  66. SELECT isp.required, isp.acquired, s.id, s.name, s.weight FROM item_stat_progress isp
  67. LEFT JOIN stat s ON s.id = isp.stat_id
  68. WHERE item_id = ?;
  69. -- name: ListItemStatProgressMulti :many
  70. SELECT isp.item_id, isp.required, isp.acquired, s.id, s.name, s.weight FROM item_stat_progress isp
  71. LEFT JOIN stat s ON s.id = isp.stat_id
  72. WHERE item_id IN (?, ?, ?, ?, ?, ?, ?, ?);
  73. -- name: InsertItem :execresult
  74. INSERT INTO item (scope_id, project_requirement_id, name, description, created_time, created_user_id, acquired_time, scheduled_date)
  75. VALUES (?, ?, ?, ?, ?, ?, ?, ?);
  76. -- name: UpdateItem :exec
  77. UPDATE item
  78. SET project_requirement_id = ?,
  79. name = ?,
  80. description = ?,
  81. acquired_time = ?,
  82. scheduled_date = ?,
  83. created_user_id = ?
  84. WHERE id = ?;
  85. -- name: DeleteItem :exec
  86. DELETE FROM item WHERE id = ?;
  87. -- name: DeleteItemForRequirement :exec
  88. DELETE FROM item WHERE project_requirement_id = ?;
  89. -- name: ClearItemProjectRequirement :exec
  90. UPDATE item SET project_requirement_id = NULL WHERE project_requirement_id = ?;
  91. -- name: ClearItemProjectRequirementByProjectID :exec
  92. UPDATE item i
  93. LEFT JOIN project_requirement pr ON pr.id = i.project_requirement_id
  94. SET i.project_requirement_id = NULL
  95. WHERE pr.project_id = ?;
  96. -- name: ReplaceItemStatProgress :exec
  97. REPLACE INTO item_stat_progress (item_id, stat_id, acquired, required)
  98. VALUES (?, ?, ?, ?);
  99. -- name: DeleteItemStatProgress :exec
  100. DELETE FROM item_stat_progress WHERE item_id = ? AND stat_id = ?;
  101. -- name: ClearItemStatProgress :exec
  102. DELETE FROM item_stat_progress WHERE item_id = ?;
  103. -- name: CLearItemStatProgressByStat :exec
  104. DELETE FROM item_stat_progress WHERE stat_id = ?;