-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueues.go
More file actions
45 lines (36 loc) · 975 Bytes
/
queues.go
File metadata and controls
45 lines (36 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package sqliteq
import (
"database/sql"
"fmt"
)
type queues struct {
client *sql.DB
}
type Queues interface {
NewQueue(queueKey string, opts ...Option) (*Queue, error)
NewPriorityQueue(queueKey string, opts ...Option) (*PriorityQueue, error)
Close() error
}
func New(dbPath string) Queues {
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
panic(fmt.Sprintf("failed to open database: %v", err))
}
// Enable WAL mode for better concurrency
if _, err := db.Exec("PRAGMA journal_mode=WAL;"); err != nil {
db.Close()
panic(fmt.Sprintf("failed to enable WAL mode: %v", err))
}
return &queues{
client: db,
}
}
func (q *queues) NewQueue(queueKey string, opts ...Option) (*Queue, error) {
return newQueue(q.client, queueKey, opts...)
}
func (q *queues) NewPriorityQueue(queueKey string, opts ...Option) (*PriorityQueue, error) {
return newPriorityQueue(q.client, queueKey, opts...)
}
func (q *queues) Close() error {
return q.client.Close()
}