39 lines
1.1 KiB
PL/PgSQL
39 lines
1.1 KiB
PL/PgSQL
CREATE OR REPLACE PROCEDURE update_scores()
|
|
LANGUAGE SQL
|
|
AS $$
|
|
UPDATE scores SET score = votescore + scoreModifier
|
|
FROM vote_score_vw
|
|
WHERE scores.url = vote_score_vw.url;
|
|
$$;
|
|
|
|
CREATE OR REPLACE PROCEDURE add_request(url varchar,requester int)
|
|
LANGUAGE SQL
|
|
AS $$
|
|
INSERT INTO requests (url,requester) VALUES (url,requester);
|
|
INSERT INTO requestMetadata (url) VALUES (url);
|
|
INSERT INTO scores (url) VALUES (url);
|
|
INSERT INTO votes (requesturl,userid) VALUES (url,requester);
|
|
CALL update_scores();
|
|
$$;
|
|
|
|
CREATE OR REPLACE PROCEDURE add_vote(url varchar,voteuser int)
|
|
LANGUAGE SQL
|
|
AS $$
|
|
INSERT INTO votes (requesturl,userid) VALUES (url,voteuser);
|
|
CALL update_scores();
|
|
$$;
|
|
|
|
CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
|
|
LANGUAGE SQL
|
|
AS $$
|
|
DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
|
|
CALL update_scores();
|
|
$$;
|
|
|
|
CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, scoreDiff int)
|
|
LANGUAGE SQL
|
|
AS $$
|
|
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
|
|
CALL update_scores();
|
|
$$;
|