Files
Memoh/internal/db/sqlc/users.sql.go
T
BBQ 6aebbe9279 feat: refactor User/Bot architecture and implement multi-channel gateway
Major changes:
1. Core Architecture: Decoupled Bots from Users. Bots now have independent lifecycles, member management (bot_members), and dedicated configurations.
2. Channel Gateway:
   - Implemented a unified Channel Manager supporting Feishu, Telegram, and Local (Web/CLI) adapters.
   - Added message processing pipeline to normalize interactions across different platforms.
   - Introduced a Contact system for identity binding and guest access policies.
3. Database & Tooling:
   - Consolidated all migrations into 0001_init with updated schema for bots, channels, and contacts.
   - Optimized sqlc.yaml to automatically track the migrations directory.
4. Agent Enhancements:
   - Introduced ToolContext to provide Agents with platform-aware execution capabilities (e.g., messaging, contact lookups).
   - Added tool logging and fallback mechanisms for toolChoice execution.
5. UI & Docs: Updated frontend stores, UI components, and Swagger documentation to align with the new Bot-centric model.
2026-02-04 23:49:50 +08:00

459 lines
10 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: users.sql
package sqlc
import (
"context"
"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 (
$1,
$2,
$3,
$4::user_role,
$5,
$6,
$7,
$8
)
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type CreateUserParams struct {
Username string `json:"username"`
Email pgtype.Text `json:"email"`
PasswordHash string `json:"password_hash"`
Role string `json:"role"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
DataRoot pgtype.Text `json:"data_root"`
}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
row := q.db.QueryRow(ctx, createUser,
arg.Username,
arg.Email,
arg.PasswordHash,
arg.Role,
arg.DisplayName,
arg.AvatarUrl,
arg.IsActive,
arg.DataRoot,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const createUserWithID = `-- name: CreateUserWithID :one
INSERT INTO users (id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root)
VALUES (
$1,
$2,
$3,
$4,
$5::user_role,
$6,
$7,
$8,
$9
)
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type CreateUserWithIDParams struct {
ID pgtype.UUID `json:"id"`
Username string `json:"username"`
Email pgtype.Text `json:"email"`
PasswordHash string `json:"password_hash"`
Role string `json:"role"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
DataRoot pgtype.Text `json:"data_root"`
}
func (q *Queries) CreateUserWithID(ctx context.Context, arg CreateUserWithIDParams) (User, error) {
row := q.db.QueryRow(ctx, createUserWithID,
arg.ID,
arg.Username,
arg.Email,
arg.PasswordHash,
arg.Role,
arg.DisplayName,
arg.AvatarUrl,
arg.IsActive,
arg.DataRoot,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const getUserByID = `-- name: GetUserByID :one
SELECT id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at FROM users WHERE id = $1
`
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (User, error) {
row := q.db.QueryRow(ctx, getUserByID, id)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const getUserByIdentity = `-- name: GetUserByIdentity :one
SELECT id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at FROM users WHERE username = $1 OR email = $1
`
func (q *Queries) GetUserByIdentity(ctx context.Context, identity string) (User, error) {
row := q.db.QueryRow(ctx, getUserByIdentity, identity)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const getUserByUsername = `-- name: GetUserByUsername :one
SELECT id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at FROM users WHERE username = $1
`
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
row := q.db.QueryRow(ctx, getUserByUsername, username)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const listUsers = `-- name: ListUsers :many
SELECT id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at FROM users
ORDER BY created_at DESC
`
func (q *Queries) ListUsers(ctx context.Context) ([]User, error) {
rows, err := q.db.Query(ctx, listUsers)
if err != nil {
return nil, err
}
defer rows.Close()
var items []User
for rows.Next() {
var i User
if err := rows.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateUserAdmin = `-- name: UpdateUserAdmin :one
UPDATE users
SET role = $1::user_role,
display_name = $2,
avatar_url = $3,
is_active = $4,
updated_at = now()
WHERE id = $5
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type UpdateUserAdminParams struct {
Role string `json:"role"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateUserAdmin(ctx context.Context, arg UpdateUserAdminParams) (User, error) {
row := q.db.QueryRow(ctx, updateUserAdmin,
arg.Role,
arg.DisplayName,
arg.AvatarUrl,
arg.IsActive,
arg.ID,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const updateUserLastLogin = `-- name: UpdateUserLastLogin :one
UPDATE users
SET last_login_at = now(),
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
func (q *Queries) UpdateUserLastLogin(ctx context.Context, id pgtype.UUID) (User, error) {
row := q.db.QueryRow(ctx, updateUserLastLogin, id)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const updateUserPassword = `-- name: UpdateUserPassword :one
UPDATE users
SET password_hash = $2,
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type UpdateUserPasswordParams struct {
ID pgtype.UUID `json:"id"`
PasswordHash string `json:"password_hash"`
}
func (q *Queries) UpdateUserPassword(ctx context.Context, arg UpdateUserPasswordParams) (User, error) {
row := q.db.QueryRow(ctx, updateUserPassword, arg.ID, arg.PasswordHash)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const updateUserProfile = `-- name: UpdateUserProfile :one
UPDATE users
SET display_name = $2,
avatar_url = $3,
is_active = $4,
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type UpdateUserProfileParams struct {
ID pgtype.UUID `json:"id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
}
func (q *Queries) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) (User, error) {
row := q.db.QueryRow(ctx, updateUserProfile,
arg.ID,
arg.DisplayName,
arg.AvatarUrl,
arg.IsActive,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}
const upsertUserByUsername = `-- name: UpsertUserByUsername :one
INSERT INTO users (username, email, password_hash, role, display_name, avatar_url, is_active, data_root)
VALUES (
$1,
$2,
$3,
$4::user_role,
$5,
$6,
$7,
$8
)
ON CONFLICT (username) DO UPDATE SET
email = EXCLUDED.email,
password_hash = EXCLUDED.password_hash,
role = EXCLUDED.role,
display_name = EXCLUDED.display_name,
avatar_url = EXCLUDED.avatar_url,
is_active = EXCLUDED.is_active,
data_root = EXCLUDED.data_root,
updated_at = now()
RETURNING id, username, email, password_hash, role, display_name, avatar_url, is_active, data_root, created_at, updated_at, last_login_at
`
type UpsertUserByUsernameParams struct {
Username string `json:"username"`
Email pgtype.Text `json:"email"`
PasswordHash string `json:"password_hash"`
Role string `json:"role"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
DataRoot pgtype.Text `json:"data_root"`
}
func (q *Queries) UpsertUserByUsername(ctx context.Context, arg UpsertUserByUsernameParams) (User, error) {
row := q.db.QueryRow(ctx, upsertUserByUsername,
arg.Username,
arg.Email,
arg.PasswordHash,
arg.Role,
arg.DisplayName,
arg.AvatarUrl,
arg.IsActive,
arg.DataRoot,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Email,
&i.PasswordHash,
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.IsActive,
&i.DataRoot,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastLoginAt,
)
return i, err
}