Skip to content

Commit

Permalink
feat: added set sql queries (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
emoral435 authored Mar 5, 2024
2 parents c06cbca + 8962b92 commit 0ee6459
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 24 deletions.
4 changes: 2 additions & 2 deletions backend/db/query/exercises.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ INSERT INTO "exercises" (
SELECT * FROM "exercises"
WHERE workout_id = $1;

-- Getexercise: returns an existing exercise, given exercise id
-- GetExercise: returns an existing exercise, given exercise id
--
-- returns: the corresponding exercise row
-- name: Getexercise :one
-- name: GetExercise :one
SELECT * FROM "exercises"
WHERE id = $1 LIMIT 1;

Expand Down
56 changes: 56 additions & 0 deletions backend/db/query/sets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- CreateSet: returns a new set, providing:
-- a exercise id, and reps and weights
--
-- returns: the new set row
-- name: CreateSet :one
INSERT INTO "set" (
exercise_id, reps, weight
) VALUES (
(SELECT "workouts".id FROM "workouts" WHERE "workouts".id = $1), $2, $3
) RETURNING *;

-- GetExerciseSets: returns all exercises sets
--
-- returns: the exercises corresponding sets
-- name: GetExerciseSets :many
SELECT * FROM "set"
WHERE exercise_id = $1;

-- GetSet: returns an existing Set, given Set id
--
-- returns: the corresponding Set row
-- name: GetSet :one
SELECT * FROM "set"
WHERE id = $1 LIMIT 1;

-- UpdateSetRep: updates sets reps given its id
--
-- returns: the set's new corresponding row
-- name: UpdateSetRep :one
UPDATE "set"
SET reps = $2
WHERE id = $1
RETURNING *;

-- UpdateSetWeight: updates set's weight given its id
--
-- returns: the sets's new corresponding row
-- name: UpdateSetWeight :one
UPDATE "set"
SET weight = $2
WHERE id = $1
RETURNING *;

-- DeleteSingleSet: deletes a single exercises's set
--
-- returns: nothing! see https://docs.sqlc.dev/en/stable/reference/query-annotations.html for exec
-- name: DeleteSingleSet :exec
DELETE FROM "set"
WHERE id = $1;

-- DeleteAllSets: deletes All exercises sets!
--
-- returns: nothing! see https://docs.sqlc.dev/en/stable/reference/query-annotations.html for exec
-- name: DeleteAllSets :exec
DELETE FROM "set"
WHERE exercise_id = $1;
73 changes: 51 additions & 22 deletions backend/db/sqlc/exercises.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 177 additions & 0 deletions backend/db/sqlc/sets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ee6459

Please sign in to comment.