Skip to content

Commit

Permalink
Fix query parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Jan 21, 2024
1 parent 79647d0 commit 5352c52
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions queries/job.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
-- Add new job to queue
-- :name add_job :insert
-- Add new job to queue
INSERT INTO job (job_type, job_object, data)
VALUES (:job_type, :job_object, :data)
ON CONFLICT (job_type, job_object)
DO NOTHING;

-- Quick check if there are pending jobs
-- :name has_jobs :one
-- Quick check if there are pending jobs
SELECT EXISTS (SELECT * FROM job LIMIT 1)

-- :name get_job :one
-- Get a random job from the queue to work on
-- This selects jobs randomly to avoid bias or generation loops
-- :name get_job :one
SELECT * FROM job ORDER BY random() LIMIT 1

-- Mark that a job has failed, and so its attempt count is incremented
-- :name fail_job :affected
-- Mark that a job has failed, and so its attempt count is incremented
UPDATE job
SET attempts = attempts + 1
WHERE job_id = :job_id

-- Delete job from queue, either because it's finished or failed
-- :name delete_job :affected
-- Delete job from queue, either because it's finished or failed
DELETE FROM job
WHERE job_id = :job_id;

-- Add job to dead letter queue
-- :name add_dead_job :insert
-- Add job to dead letter queue
INSERT INTO job_dead (job_id, job_type, job_object, data)
VALUES (:job_id, :job_type, :job_object, :data);
4 changes: 2 additions & 2 deletions queries/page.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Adds a page
-- :name add_page :insert
-- Adds a page
INSERT INTO page (site_slug, page_slug, page_id, page_category_id)
VALUES (:site_slug, :page_slug, :page_id, :page_category_id);

-- Marks a page as deleted
-- :name delete_page :affected
-- Marks a page as deleted
UPDATE page SET deleted_at = now()
WHERE site_slug = :site_slug
AND page_slug = :page_slug;
4 changes: 2 additions & 2 deletions queries/site.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-- Adds or updates a site
-- :name add_site :insert
-- Adds or updates a site
INSERT INTO site (site_slug, wikidot_id, home_slug, name, tagline, language)
VALUES (:site_slug, :site_id, :home_slug, :name, :tagline, :language)
ON CONFLICT (site_slug)
DO UPDATE
SET home_slug = :home_slug, name = :name, tagline = :tagline, language = :language;

-- Gets site by slug
-- :name get_site :one
-- Gets site by slug
SELECT * FROM site
WHERE site_slug = :slug;
2 changes: 1 addition & 1 deletion queries/site_member.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- :name add_site_member :insert
-- Adds a site member relation, if not already present
-- This prefers earlier join dates to later ones, if multiple exist
-- :name add_site_member :insert
INSERT INTO site_member (user_id, site_id, joined_at)
VALUES (:user_id, :site_id, :joined_at)
ON CONFLICT (user_id, site_id)
Expand Down
2 changes: 1 addition & 1 deletion queries/text.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Inserts a text entry, if not already present
-- :name add_text :insert
-- Inserts a text entry, if not already present
INSERT INTO text (hash, contents)
VALUES (:hash, :contents)
ON CONFLICT (hash)
Expand Down
6 changes: 3 additions & 3 deletions queries/user.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Adds or updates a user
-- :name add_user :insert
-- Adds or updates a user
INSERT INTO "user" (
user_slug,
user_name,
Expand Down Expand Up @@ -41,12 +41,12 @@ INSERT INTO "user" (
karma = :karma;


-- Gets a user by ID
-- :name get_user_by_id :one
-- Gets a user by ID
SELECT * FROM "user"
WHERE wikidot_id = :user_id;

-- Gets a user by slug
-- :name get_user_by_slug :one
-- Gets a user by slug
SELECT * FROM "user"
WHERE user_slug = :user_slug;
2 changes: 1 addition & 1 deletion queries/user_avatar.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Sets a user's avatar after uploading to S3
-- :name add_user_avatar :affected
-- Sets a user's avatar after uploading to S3
UPDATE "user"
SET avatar = :hash
WHERE wikidot_id = :user_id;

0 comments on commit 5352c52

Please sign in to comment.