@@ -36,17 +36,17 @@ func newPriorityQueue(db *sql.DB, tableName string, opts ...Option) (*PriorityQu
3636func (pq * PriorityQueue ) initPriorityColumn () error {
3737 // Check if priority column exists
3838 var name string
39- err := pq .client .QueryRow (fmt .Sprintf ("PRAGMA table_info(%s)" , pq .tableName )).Scan (nil , & name , nil , nil , nil , nil )
39+ err := pq .client .QueryRow (fmt .Sprintf ("PRAGMA table_info(%s)" , quoteIdent ( pq .tableName ) )).Scan (nil , & name , nil , nil , nil , nil )
4040
4141 if err != nil || name != "priority" {
4242 // Add priority column with default value 0
43- _ , err := pq .client .Exec (fmt .Sprintf ("ALTER TABLE %s ADD COLUMN priority INTEGER NOT NULL DEFAULT 0" , pq .tableName ))
43+ _ , err := pq .client .Exec (fmt .Sprintf ("ALTER TABLE %s ADD COLUMN priority INTEGER NOT NULL DEFAULT 0" , quoteIdent ( pq .tableName ) ))
4444 if err != nil {
4545 return err
4646 }
4747
4848 // Create index on priority (ASC for lower numbers = higher priority)
49- _ , err = pq .client .Exec (fmt .Sprintf ("CREATE INDEX IF NOT EXISTS %s_priority_idx ON %s (priority ASC, created_at ASC)" , pq .tableName , pq .tableName ))
49+ _ , err = pq .client .Exec (fmt .Sprintf ("CREATE INDEX IF NOT EXISTS %s ON %s (priority ASC, created_at ASC)" , quoteIdent ( pq .tableName + "_priority_idx" ), quoteIdent ( pq .tableName ) ))
5050 if err != nil {
5151 return err
5252 }
@@ -75,7 +75,7 @@ func (pq *PriorityQueue) Enqueue(item any, priority int) bool {
7575 }()
7676
7777 _ , err = tx .Exec (
78- fmt .Sprintf ("INSERT INTO %s (data, status, created_at, updated_at, priority) VALUES (?, ?, ?, ?, ?)" , pq .tableName ),
78+ fmt .Sprintf ("INSERT INTO %s (data, status, created_at, updated_at, priority) VALUES (?, ?, ?, ?, ?)" , quoteIdent ( pq .tableName ) ),
7979 item , "pending" , now , now , priority ,
8080 )
8181 if err != nil {
@@ -108,7 +108,7 @@ func (pq *PriorityQueue) dequeueInternal(withAckId bool) (any, bool, string) {
108108 var data []byte
109109 row := tx .QueryRow (fmt .Sprintf (
110110 "SELECT id, data FROM %s WHERE status = 'pending' ORDER BY priority ASC, created_at ASC LIMIT 1" ,
111- pq .tableName ,
111+ quoteIdent ( pq .tableName ) ,
112112 ))
113113 err = row .Scan (& id , & data )
114114 if err != nil {
@@ -128,13 +128,13 @@ func (pq *PriorityQueue) dequeueInternal(withAckId bool) (any, bool, string) {
128128 ackID = cuid .New ()
129129
130130 _ , err = tx .Exec (
131- fmt .Sprintf ("UPDATE %s SET status = 'processing', ack_id = ?, updated_at = ? WHERE id = ?" , pq .tableName ),
131+ fmt .Sprintf ("UPDATE %s SET status = 'processing', ack_id = ?, updated_at = ? WHERE id = ?" , quoteIdent ( pq .tableName ) ),
132132 ackID , now , id ,
133133 )
134134 } else {
135135 // remove the row if there is no ack
136136 _ , err = tx .Exec (
137- fmt .Sprintf ("DELETE FROM %s WHERE id = ?" , pq .tableName ),
137+ fmt .Sprintf ("DELETE FROM %s WHERE id = ?" , quoteIdent ( pq .tableName ) ),
138138 id ,
139139 )
140140 }
0 commit comments