Remove deprecated WebSocket API, switch to SQLite for reply store
This commit is contained in:
31
internal/store/db.go
Normal file
31
internal/store/db.go
Normal 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
13
internal/store/models.go
Normal 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
|
||||
}
|
||||
42
internal/store/queries.sql.go
Normal file
42
internal/store/queries.sql.go
Normal 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
6
internal/store/types.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package store
|
||||
|
||||
const (
|
||||
Comment = "c"
|
||||
Post = "p"
|
||||
)
|
||||
Reference in New Issue
Block a user