Remove deprecated WebSocket API, switch to SQLite for reply store

This commit is contained in:
2023-08-18 19:10:43 -07:00
parent a9cddb115f
commit bc91986e6c
12 changed files with 289 additions and 165 deletions

31
internal/store/db.go Normal file
View File

@@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.19.1
package store
import (
"context"
"database/sql"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

13
internal/store/models.go Normal file
View File

@@ -0,0 +1,13 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.19.1
package store
import ()
type RepliedItem struct {
ID int64
ItemType string
UpdatedTime int64
}

View File

@@ -0,0 +1,42 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.19.1
// source: queries.sql
package store
import (
"context"
)
const addItem = `-- name: AddItem :exec
INSERT OR REPLACE INTO replied_items (id, item_type, updated_time) VALUES (?, ?, ?)
`
type AddItemParams struct {
ID int64
ItemType string
UpdatedTime int64
}
func (q *Queries) AddItem(ctx context.Context, arg AddItemParams) error {
_, err := q.db.ExecContext(ctx, addItem, arg.ID, arg.ItemType, arg.UpdatedTime)
return err
}
const itemExists = `-- name: ItemExists :one
SELECT COUNT(1) FROM replied_items WHERE item_type = ? AND id = ? AND updated_time = ?
`
type ItemExistsParams struct {
ItemType string
ID int64
UpdatedTime int64
}
func (q *Queries) ItemExists(ctx context.Context, arg ItemExistsParams) (int64, error) {
row := q.db.QueryRowContext(ctx, itemExists, arg.ItemType, arg.ID, arg.UpdatedTime)
var count int64
err := row.Scan(&count)
return count, err
}

6
internal/store/types.go Normal file
View File

@@ -0,0 +1,6 @@
package store
const (
Comment = "c"
Post = "p"
)