Skip to content

Commit

Permalink
fix a sql query syntax in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmoe committed May 19, 2024
1 parent 24e2d42 commit 890ae38
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/litestack/litequeue.sql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ schema:
CREATE TABLE IF NOT EXISTS queue(
id TEXT PRIMARY KEY DEFAULT(hex(randomblob(32))) NOT NULL ON CONFLICT REPLACE,
name TEXT DEFAULT('default') NOT NULL ON CONFLICT REPLACE,
fire_at INTEGER DEFAULT(unixepoch()) NOT NULL ON CONFLICT REPLACE,
fire_at REAL DEFAULT(unixepoch('subsec')) NOT NULL ON CONFLICT REPLACE,
value TEXT,
created_at INTEGER DEFAULT(unixepoch()) NOT NULL ON CONFLICT REPLACE
) WITHOUT ROWID;
Expand All @@ -16,21 +16,36 @@ stmts:

push: >
INSERT INTO queue(id, name, fire_at, value)
VALUES (hex(randomblob(32)), $1, (unixepoch() + $2), $3)
VALUES (hex(randomblob(32)), $1, (unixepoch('subsec') + $2), $3)
RETURNING id, name;
repush: >
INSERT INTO queue(id, name, fire_at, value)
VALUES (?, ?, (unixepoch() + ?), ?)
VALUES (?, ?, (unixepoch('subsec') + ?), ?)
RETURNING name;
pop_in_place: >
UPDATE queue
SET
name = '->:' || name,
fire_at = unixepoch('subsec')
WHERE (name, fire_at, id)
IN (
SELECT name, fire_at, id FROM queue
WHERE name = ifnull($1, 'default')
AND fire_at <= (unixepoch('subsec'))
ORDER BY fire_at ASC
LIMIT ifnull($2, 1)
)
RETURNING id, value;
pop: >
DELETE FROM queue
WHERE (name, fire_at, id)
IN (
SELECT name, fire_at, id FROM queue
WHERE name = ifnull($1, 'default')
AND fire_at <= (unixepoch())
AND fire_at <= (unixepoch('subsec'))
ORDER BY fire_at ASC
LIMIT ifnull($2, 1)
)
Expand Down

0 comments on commit 890ae38

Please sign in to comment.