feat: chat api

This commit is contained in:
Acbox
2026-01-28 15:15:57 +08:00
parent 0711b1f086
commit 39215309da
26 changed files with 673 additions and 1873 deletions
+73
View File
@@ -0,0 +1,73 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: history.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createHistory = `-- name: CreateHistory :one
INSERT INTO history (messages, timestamp, "user")
VALUES ($1, $2, $3)
RETURNING id, messages, timestamp, "user"
`
type CreateHistoryParams struct {
Messages []byte `json:"messages"`
Timestamp pgtype.Timestamptz `json:"timestamp"`
User pgtype.UUID `json:"user"`
}
func (q *Queries) CreateHistory(ctx context.Context, arg CreateHistoryParams) (History, error) {
row := q.db.QueryRow(ctx, createHistory, arg.Messages, arg.Timestamp, arg.User)
var i History
err := row.Scan(
&i.ID,
&i.Messages,
&i.Timestamp,
&i.User,
)
return i, err
}
const listHistoryByUserSince = `-- name: ListHistoryByUserSince :many
SELECT id, messages, timestamp, "user"
FROM history
WHERE "user" = $1 AND timestamp >= $2
ORDER BY timestamp ASC
`
type ListHistoryByUserSinceParams struct {
User pgtype.UUID `json:"user"`
Timestamp pgtype.Timestamptz `json:"timestamp"`
}
func (q *Queries) ListHistoryByUserSince(ctx context.Context, arg ListHistoryByUserSinceParams) ([]History, error) {
rows, err := q.db.Query(ctx, listHistoryByUserSince, arg.User, arg.Timestamp)
if err != nil {
return nil, err
}
defer rows.Close()
var items []History
for rows.Next() {
var i History
if err := rows.Scan(
&i.ID,
&i.Messages,
&i.Timestamp,
&i.User,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}