mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
- Generate Server/db/dbgen/{events,plugins}.sql.go and full Server/db/pgdbgen/ (//go:build postgres gated)
- Implement PostgresStore EventStore and PluginStore methods in store/postgres.go
- Wire plugin host_events.go EventSink into hub broadcast path (SetPluginEventSink)
- Wire host_commands.go slash-command dispatcher: chat_command V1 handler + hub.SetPluginRegistry
- Add handlers_command.go + handlers_command_test.go for plugin slash-command dispatch
- Add reconnect_db_test.go: TestReconnect_BufferMiss_FallsBackToDBTier (cold-tier DB replay)
- Add otel-up/otel-down Makefile targets; docker-compose.otel.yml + prometheus.dev.yml
- Update PHASE_BC_LOCAL_TODO.md: mark in-session items complete; document remaining network-blocked steps
- Minor fixes: channel_handler access-control, router plugin handler wiring, service span instrumentation
110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
//go:build postgres
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: events.sql
|
|
|
|
package pgdbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getEventsSince = `-- name: GetEventsSince :many
|
|
SELECT seq, event_type, channel_id, payload, created_at
|
|
FROM events
|
|
WHERE seq > $1
|
|
ORDER BY seq ASC
|
|
LIMIT $2
|
|
`
|
|
|
|
type GetEventsSinceParams struct {
|
|
Seq int64 `json:"seq"`
|
|
Limit int32 `json:"limit"`
|
|
}
|
|
|
|
type GetEventsSinceRow struct {
|
|
Seq int64 `json:"seq"`
|
|
EventType string `json:"eventType"`
|
|
ChannelID int64 `json:"channelId"`
|
|
Payload []byte `json:"payload"`
|
|
CreatedAt pgtype.Timestamptz `json:"createdAt"`
|
|
}
|
|
|
|
func (q *Queries) GetEventsSince(ctx context.Context, arg GetEventsSinceParams) ([]GetEventsSinceRow, error) {
|
|
rows, err := q.db.Query(ctx, getEventsSince, arg.Seq, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetEventsSinceRow{}
|
|
for rows.Next() {
|
|
var i GetEventsSinceRow
|
|
if err := rows.Scan(
|
|
&i.Seq,
|
|
&i.EventType,
|
|
&i.ChannelID,
|
|
&i.Payload,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getMaxEventSeq = `-- name: GetMaxEventSeq :one
|
|
SELECT COALESCE(MAX(seq), 0)::BIGINT FROM events
|
|
`
|
|
|
|
func (q *Queries) GetMaxEventSeq(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, getMaxEventSeq)
|
|
var column_1 int64
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const persistEvent = `-- name: PersistEvent :exec
|
|
INSERT INTO events (seq, event_type, channel_id, payload)
|
|
VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type PersistEventParams struct {
|
|
Seq int64 `json:"seq"`
|
|
EventType string `json:"eventType"`
|
|
ChannelID int64 `json:"channelId"`
|
|
Payload []byte `json:"payload"`
|
|
}
|
|
|
|
// seq is supplied by the hub so the row seq matches the wrapped-payload seq.
|
|
// The schema's BIGSERIAL still owns the id column for inserts that omit seq,
|
|
// but PersistEvent always supplies an explicit value.
|
|
func (q *Queries) PersistEvent(ctx context.Context, arg PersistEventParams) error {
|
|
_, err := q.db.Exec(ctx, persistEvent,
|
|
arg.Seq,
|
|
arg.EventType,
|
|
arg.ChannelID,
|
|
arg.Payload,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const pruneEventsOlderThan = `-- name: PruneEventsOlderThan :execrows
|
|
DELETE FROM events WHERE created_at < $1
|
|
`
|
|
|
|
func (q *Queries) PruneEventsOlderThan(ctx context.Context, createdAt pgtype.Timestamptz) (int64, error) {
|
|
result, err := q.db.Exec(ctx, pruneEventsOlderThan, createdAt)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|