You've already forked agentic-coding-workflow
feat(chat): sqlc queries for conversations/messages/attachments/templates/endpoints/models/usage
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: usage.sql
|
||||
|
||||
package chatsqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const insertUsage = `-- name: InsertUsage :exec
|
||||
INSERT INTO llm_usage (
|
||||
conversation_id, message_id, user_id, endpoint_id, model_id,
|
||||
prompt_tokens, completion_tokens, thinking_tokens, cost_usd
|
||||
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
||||
`
|
||||
|
||||
type InsertUsageParams struct {
|
||||
ConversationID pgtype.UUID `json:"conversation_id"`
|
||||
MessageID int64 `json:"message_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EndpointID pgtype.UUID `json:"endpoint_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUsage(ctx context.Context, arg InsertUsageParams) error {
|
||||
_, err := q.db.Exec(ctx, insertUsage,
|
||||
arg.ConversationID,
|
||||
arg.MessageID,
|
||||
arg.UserID,
|
||||
arg.EndpointID,
|
||||
arg.ModelID,
|
||||
arg.PromptTokens,
|
||||
arg.CompletionTokens,
|
||||
arg.ThinkingTokens,
|
||||
arg.CostUsd,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const summarizeUsageByDay = `-- name: SummarizeUsageByDay :many
|
||||
SELECT date_trunc('day', created_at) AS day,
|
||||
SUM(prompt_tokens)::int AS prompt_tokens,
|
||||
SUM(completion_tokens)::int AS completion_tokens,
|
||||
SUM(thinking_tokens)::int AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM llm_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY day
|
||||
ORDER BY day
|
||||
`
|
||||
|
||||
type SummarizeUsageByDayParams struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
||||
}
|
||||
|
||||
type SummarizeUsageByDayRow struct {
|
||||
Day pgtype.Interval `json:"day"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
}
|
||||
|
||||
func (q *Queries) SummarizeUsageByDay(ctx context.Context, arg SummarizeUsageByDayParams) ([]SummarizeUsageByDayRow, error) {
|
||||
rows, err := q.db.Query(ctx, summarizeUsageByDay, arg.CreatedAt, arg.CreatedAt_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SummarizeUsageByDayRow
|
||||
for rows.Next() {
|
||||
var i SummarizeUsageByDayRow
|
||||
if err := rows.Scan(
|
||||
&i.Day,
|
||||
&i.PromptTokens,
|
||||
&i.CompletionTokens,
|
||||
&i.ThinkingTokens,
|
||||
&i.CostUsd,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const summarizeUsageByModel = `-- name: SummarizeUsageByModel :many
|
||||
SELECT model_id,
|
||||
SUM(prompt_tokens)::int AS prompt_tokens,
|
||||
SUM(completion_tokens)::int AS completion_tokens,
|
||||
SUM(thinking_tokens)::int AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM llm_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY model_id
|
||||
ORDER BY cost_usd DESC
|
||||
`
|
||||
|
||||
type SummarizeUsageByModelParams struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
||||
}
|
||||
|
||||
type SummarizeUsageByModelRow struct {
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
}
|
||||
|
||||
func (q *Queries) SummarizeUsageByModel(ctx context.Context, arg SummarizeUsageByModelParams) ([]SummarizeUsageByModelRow, error) {
|
||||
rows, err := q.db.Query(ctx, summarizeUsageByModel, arg.CreatedAt, arg.CreatedAt_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SummarizeUsageByModelRow
|
||||
for rows.Next() {
|
||||
var i SummarizeUsageByModelRow
|
||||
if err := rows.Scan(
|
||||
&i.ModelID,
|
||||
&i.PromptTokens,
|
||||
&i.CompletionTokens,
|
||||
&i.ThinkingTokens,
|
||||
&i.CostUsd,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const summarizeUsageByUser = `-- name: SummarizeUsageByUser :many
|
||||
SELECT user_id,
|
||||
SUM(prompt_tokens)::int AS prompt_tokens,
|
||||
SUM(completion_tokens)::int AS completion_tokens,
|
||||
SUM(thinking_tokens)::int AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM llm_usage
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
GROUP BY user_id
|
||||
ORDER BY cost_usd DESC
|
||||
`
|
||||
|
||||
type SummarizeUsageByUserParams struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
||||
}
|
||||
|
||||
type SummarizeUsageByUserRow struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
}
|
||||
|
||||
func (q *Queries) SummarizeUsageByUser(ctx context.Context, arg SummarizeUsageByUserParams) ([]SummarizeUsageByUserRow, error) {
|
||||
rows, err := q.db.Query(ctx, summarizeUsageByUser, arg.CreatedAt, arg.CreatedAt_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SummarizeUsageByUserRow
|
||||
for rows.Next() {
|
||||
var i SummarizeUsageByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.PromptTokens,
|
||||
&i.CompletionTokens,
|
||||
&i.ThinkingTokens,
|
||||
&i.CostUsd,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const summarizeUserDaily = `-- name: SummarizeUserDaily :many
|
||||
SELECT date_trunc('day', created_at) AS day,
|
||||
SUM(prompt_tokens)::int AS prompt_tokens,
|
||||
SUM(completion_tokens)::int AS completion_tokens,
|
||||
SUM(thinking_tokens)::int AS thinking_tokens,
|
||||
SUM(cost_usd)::numeric AS cost_usd
|
||||
FROM llm_usage
|
||||
WHERE user_id = $1 AND created_at >= $2 AND created_at < $3
|
||||
GROUP BY day
|
||||
ORDER BY day
|
||||
`
|
||||
|
||||
type SummarizeUserDailyParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
||||
}
|
||||
|
||||
type SummarizeUserDailyRow struct {
|
||||
Day pgtype.Interval `json:"day"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
}
|
||||
|
||||
func (q *Queries) SummarizeUserDaily(ctx context.Context, arg SummarizeUserDailyParams) ([]SummarizeUserDailyRow, error) {
|
||||
rows, err := q.db.Query(ctx, summarizeUserDaily, arg.UserID, arg.CreatedAt, arg.CreatedAt_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SummarizeUserDailyRow
|
||||
for rows.Next() {
|
||||
var i SummarizeUserDailyRow
|
||||
if err := rows.Scan(
|
||||
&i.Day,
|
||||
&i.PromptTokens,
|
||||
&i.CompletionTokens,
|
||||
&i.ThinkingTokens,
|
||||
&i.CostUsd,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user