mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
fix: sqlc api
This commit is contained in:
@@ -35,41 +35,24 @@ func (q *Queries) CreateHistory(ctx context.Context, arg CreateHistoryParams) (H
|
||||
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
|
||||
const deleteHistoryByID = `-- name: DeleteHistoryByID :exec
|
||||
DELETE FROM history
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type ListHistoryByUserSinceParams struct {
|
||||
User pgtype.UUID `json:"user"`
|
||||
Timestamp pgtype.Timestamptz `json:"timestamp"`
|
||||
func (q *Queries) DeleteHistoryByID(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteHistoryByID, id)
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
const deleteHistoryByUser = `-- name: DeleteHistoryByUser :exec
|
||||
DELETE FROM history
|
||||
WHERE "user" = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteHistoryByUser(ctx context.Context, user pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteHistoryByUser, user)
|
||||
return err
|
||||
}
|
||||
|
||||
const getHistoryByID = `-- name: GetHistoryByID :one
|
||||
@@ -128,22 +111,39 @@ func (q *Queries) ListHistoryByUser(ctx context.Context, arg ListHistoryByUserPa
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const deleteHistoryByID = `-- name: DeleteHistoryByID :exec
|
||||
DELETE FROM history
|
||||
WHERE id = $1
|
||||
const listHistoryByUserSince = `-- name: ListHistoryByUserSince :many
|
||||
SELECT id, messages, timestamp, "user"
|
||||
FROM history
|
||||
WHERE "user" = $1 AND timestamp >= $2
|
||||
ORDER BY timestamp ASC
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteHistoryByID(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteHistoryByID, id)
|
||||
return err
|
||||
type ListHistoryByUserSinceParams struct {
|
||||
User pgtype.UUID `json:"user"`
|
||||
Timestamp pgtype.Timestamptz `json:"timestamp"`
|
||||
}
|
||||
|
||||
const deleteHistoryByUser = `-- name: DeleteHistoryByUser :exec
|
||||
DELETE FROM history
|
||||
WHERE "user" = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteHistoryByUser(ctx context.Context, user pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteHistoryByUser, user)
|
||||
return err
|
||||
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
|
||||
}
|
||||
|
||||
@@ -40,12 +40,6 @@ type History struct {
|
||||
User pgtype.UUID `json:"user"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
type LifecycleEvent struct {
|
||||
ID string `json:"id"`
|
||||
ContainerID string `json:"container_id"`
|
||||
@@ -111,3 +105,9 @@ type User struct {
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
LastLoginAt pgtype.Timestamptz `json:"last_login_at"`
|
||||
}
|
||||
|
||||
type UserSetting struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
@@ -11,20 +11,26 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteSettingsByUserID = `-- name: DeleteSettingsByUserID :exec
|
||||
DELETE FROM user_settings
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteSettingsByUserID(ctx context.Context, userID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteSettingsByUserID, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getSettingsByUserID = `-- name: GetSettingsByUserID :one
|
||||
SELECT user_id, max_context_load_time, language
|
||||
FROM user_settings
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSettingsByUserID(ctx context.Context, userID pgtype.UUID) (Settings, error) {
|
||||
func (q *Queries) GetSettingsByUserID(ctx context.Context, userID pgtype.UUID) (UserSetting, error) {
|
||||
row := q.db.QueryRow(ctx, getSettingsByUserID, userID)
|
||||
var i Settings
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
)
|
||||
var i UserSetting
|
||||
err := row.Scan(&i.UserID, &i.MaxContextLoadTime, &i.Language)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -43,24 +49,9 @@ type UpsertSettingsParams struct {
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertSettings(ctx context.Context, arg UpsertSettingsParams) (Settings, error) {
|
||||
func (q *Queries) UpsertSettings(ctx context.Context, arg UpsertSettingsParams) (UserSetting, error) {
|
||||
row := q.db.QueryRow(ctx, upsertSettings, arg.UserID, arg.MaxContextLoadTime, arg.Language)
|
||||
var i Settings
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
)
|
||||
var i UserSetting
|
||||
err := row.Scan(&i.UserID, &i.MaxContextLoadTime, &i.Language)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteSettingsByUserID = `-- name: DeleteSettingsByUserID :exec
|
||||
DELETE FROM user_settings
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteSettingsByUserID(ctx context.Context, userID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteSettingsByUserID, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,17 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countUsers = `-- name: CountUsers :one
|
||||
SELECT COUNT(*)::bigint AS count FROM users
|
||||
`
|
||||
|
||||
func (q *Queries) CountUsers(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countUsers)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (username, email, password_hash, role, display_name, avatar_url, is_active, data_root)
|
||||
VALUES (
|
||||
@@ -90,17 +101,6 @@ func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User,
|
||||
return i, err
|
||||
}
|
||||
|
||||
const countUsers = `-- name: CountUsers :one
|
||||
SELECT COUNT(*)::bigint AS count FROM users
|
||||
`
|
||||
|
||||
func (q *Queries) CountUsers(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countUsers)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const upsertUserByUsername = `-- name: UpsertUserByUsername :one
|
||||
INSERT INTO users (username, email, password_hash, role, display_name, avatar_url, is_active, data_root)
|
||||
VALUES (
|
||||
|
||||
Reference in New Issue
Block a user