mirror of
https://github.com/Dvorinka/Trackeep.git
synced 2026-06-03 20:12:58 +00:00
feat: migrate to DragonflyDB and clean up environment configuration
- Replace Redis with DragonflyDB for better performance and memory efficiency - Remove redundant environment variables (POSTGRES_*, ENCRYPTION_KEY, OAUTH_SERVICE_URL) - Consolidate database configuration to use single DB_* variables - Use JWT_SECRET for both JWT tokens and encryption - Remove PORT variable redundancy, use BACKEND_PORT consistently - Clean up docker-compose configurations for dev/prod consistency - Add DragonflyDB configuration with optimized memory usage - Remove redis.conf as it's no longer needed - Update health checks to use Redis-compatible CLI for DragonflyDB - Add missing VITE_API_URL to production frontend - Fix GitHub Actions to use correct go.sum path - Clean up development directories and unused files
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/trackeep/backend/internal/db/sqlc"
|
||||
)
|
||||
|
||||
// DB wraps the sqlc DB with additional functionality
|
||||
type DB struct {
|
||||
*sqlc.Queries
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
// NewDB creates a new database connection
|
||||
func NewDB() (*DB, error) {
|
||||
// Get database connection string
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s",
|
||||
os.Getenv("DB_HOST"),
|
||||
os.Getenv("DB_USER"),
|
||||
os.Getenv("DB_PASSWORD"),
|
||||
os.Getenv("DB_NAME"),
|
||||
os.Getenv("DB_PORT"),
|
||||
os.Getenv("DB_SSL_MODE"),
|
||||
)
|
||||
|
||||
// Create connection pool
|
||||
pool, err := pgxpool.New(context.Background(), dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create connection pool: %w", err)
|
||||
}
|
||||
|
||||
// Test connection
|
||||
if err := pool.Ping(context.Background()); err != nil {
|
||||
return nil, fmt.Errorf("failed to ping database: %w", err)
|
||||
}
|
||||
|
||||
// Create queries instance
|
||||
queries := sqlc.New(pool)
|
||||
|
||||
return &DB{
|
||||
Queries: queries,
|
||||
pool: pool,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close closes the database connection
|
||||
func (db *DB) Close() error {
|
||||
db.pool.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// BeginTx starts a transaction
|
||||
func (db *DB) BeginTx(ctx context.Context) (*DB, error) {
|
||||
tx, err := db.pool.BeginTx(ctx, pgx.TxOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DB{
|
||||
Queries: sqlc.New(tx),
|
||||
pool: nil, // Not using pool in transaction mode
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Commit commits the transaction
|
||||
func (db *DB) Commit() error {
|
||||
// This would need to be implemented with transaction tracking
|
||||
// For now, transactions should be handled by the caller
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rollback rolls back the transaction
|
||||
func (db *DB) Rollback() error {
|
||||
// This would need to be implemented with transaction tracking
|
||||
// For now, transactions should be handled by the caller
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPool returns the underlying connection pool
|
||||
func (db *DB) GetPool() *pgxpool.Pool {
|
||||
return db.pool
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: bookmarks.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const AddBookmarkTag = `-- name: AddBookmarkTag :exec
|
||||
INSERT INTO bookmark_tags (bookmark_id, tag_id) VALUES ($1, $2) ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
type AddBookmarkTagParams struct {
|
||||
BookmarkID pgtype.UUID `json:"bookmarkId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddBookmarkTag(ctx context.Context, arg AddBookmarkTagParams) error {
|
||||
_, err := q.db.Exec(ctx, AddBookmarkTag, arg.BookmarkID, arg.TagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const CreateBookmark = `-- name: CreateBookmark :one
|
||||
INSERT INTO bookmarks (title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateBookmarkParams struct {
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
Description *string `json:"description"`
|
||||
FaviconUrl *string `json:"faviconUrl"`
|
||||
ScreenshotUrl *string `json:"screenshotUrl"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
IsArchived *bool `json:"isArchived"`
|
||||
IsFavorite *bool `json:"isFavorite"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBookmark(ctx context.Context, arg CreateBookmarkParams) (Bookmark, error) {
|
||||
row := q.db.QueryRow(ctx, CreateBookmark,
|
||||
arg.Title,
|
||||
arg.Url,
|
||||
arg.Description,
|
||||
arg.FaviconUrl,
|
||||
arg.ScreenshotUrl,
|
||||
arg.UserID,
|
||||
arg.IsArchived,
|
||||
arg.IsFavorite,
|
||||
)
|
||||
var i Bookmark
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const DeleteBookmark = `-- name: DeleteBookmark :exec
|
||||
DELETE FROM bookmarks WHERE id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type DeleteBookmarkParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteBookmark(ctx context.Context, arg DeleteBookmarkParams) error {
|
||||
_, err := q.db.Exec(ctx, DeleteBookmark, arg.ID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const GetBookmarkByID = `-- name: GetBookmarkByID :one
|
||||
SELECT id, title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite, created_at, updated_at
|
||||
FROM bookmarks
|
||||
WHERE id = $1 AND user_id = $2 LIMIT 1
|
||||
`
|
||||
|
||||
type GetBookmarkByIDParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBookmarkByID(ctx context.Context, arg GetBookmarkByIDParams) (Bookmark, error) {
|
||||
row := q.db.QueryRow(ctx, GetBookmarkByID, arg.ID, arg.UserID)
|
||||
var i Bookmark
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetBookmarksByTag = `-- name: GetBookmarksByTag :many
|
||||
SELECT b.id, b.title, b.url, b.description, b.favicon_url, b.screenshot_url, b.user_id, b.is_archived, b.is_favorite, b.created_at, b.updated_at
|
||||
FROM bookmarks b
|
||||
INNER JOIN bookmark_tags bt ON b.id = bt.bookmark_id
|
||||
INNER JOIN tags t ON bt.tag_id = t.id
|
||||
WHERE t.id = $1 AND b.user_id = $2
|
||||
ORDER BY b.created_at DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
type GetBookmarksByTagParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBookmarksByTag(ctx context.Context, arg GetBookmarksByTagParams) ([]Bookmark, error) {
|
||||
rows, err := q.db.Query(ctx, GetBookmarksByTag,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Bookmark{}
|
||||
for rows.Next() {
|
||||
var i Bookmark
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetBookmarksByUser = `-- name: GetBookmarksByUser :many
|
||||
SELECT id, title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite, created_at, updated_at
|
||||
FROM bookmarks
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type GetBookmarksByUserParams struct {
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBookmarksByUser(ctx context.Context, arg GetBookmarksByUserParams) ([]Bookmark, error) {
|
||||
rows, err := q.db.Query(ctx, GetBookmarksByUser, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Bookmark{}
|
||||
for rows.Next() {
|
||||
var i Bookmark
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const RemoveBookmarkTag = `-- name: RemoveBookmarkTag :exec
|
||||
DELETE FROM bookmark_tags WHERE bookmark_id = $1 AND tag_id = $2
|
||||
`
|
||||
|
||||
type RemoveBookmarkTagParams struct {
|
||||
BookmarkID pgtype.UUID `json:"bookmarkId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveBookmarkTag(ctx context.Context, arg RemoveBookmarkTagParams) error {
|
||||
_, err := q.db.Exec(ctx, RemoveBookmarkTag, arg.BookmarkID, arg.TagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const SearchBookmarks = `-- name: SearchBookmarks :many
|
||||
SELECT id, title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite, created_at, updated_at
|
||||
FROM bookmarks
|
||||
WHERE user_id = $1 AND (
|
||||
title ILIKE $2 OR
|
||||
description ILIKE $2 OR
|
||||
url ILIKE $2
|
||||
)
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
type SearchBookmarksParams struct {
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Title string `json:"title"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchBookmarks(ctx context.Context, arg SearchBookmarksParams) ([]Bookmark, error) {
|
||||
rows, err := q.db.Query(ctx, SearchBookmarks,
|
||||
arg.UserID,
|
||||
arg.Title,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Bookmark{}
|
||||
for rows.Next() {
|
||||
var i Bookmark
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const UpdateBookmark = `-- name: UpdateBookmark :one
|
||||
UPDATE bookmarks
|
||||
SET title = $2,
|
||||
url = $3,
|
||||
description = $4,
|
||||
favicon_url = $5,
|
||||
screenshot_url = $6,
|
||||
is_archived = $7,
|
||||
is_favorite = $8,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1 AND user_id = $9
|
||||
RETURNING id, title, url, description, favicon_url, screenshot_url, user_id, is_archived, is_favorite, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateBookmarkParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
Description *string `json:"description"`
|
||||
FaviconUrl *string `json:"faviconUrl"`
|
||||
ScreenshotUrl *string `json:"screenshotUrl"`
|
||||
IsArchived *bool `json:"isArchived"`
|
||||
IsFavorite *bool `json:"isFavorite"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBookmark(ctx context.Context, arg UpdateBookmarkParams) (Bookmark, error) {
|
||||
row := q.db.QueryRow(ctx, UpdateBookmark,
|
||||
arg.ID,
|
||||
arg.Title,
|
||||
arg.Url,
|
||||
arg.Description,
|
||||
arg.FaviconUrl,
|
||||
arg.ScreenshotUrl,
|
||||
arg.IsArchived,
|
||||
arg.IsFavorite,
|
||||
arg.UserID,
|
||||
)
|
||||
var i Bookmark
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Url,
|
||||
&i.Description,
|
||||
&i.FaviconUrl,
|
||||
&i.ScreenshotUrl,
|
||||
&i.UserID,
|
||||
&i.IsArchived,
|
||||
&i.IsFavorite,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type AuditLog struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Action string `json:"action"`
|
||||
ResourceType string `json:"resourceType"`
|
||||
ResourceID pgtype.UUID `json:"resourceId"`
|
||||
OldValues []byte `json:"oldValues"`
|
||||
NewValues []byte `json:"newValues"`
|
||||
IpAddress *netip.Addr `json:"ipAddress"`
|
||||
UserAgent *string `json:"userAgent"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
}
|
||||
|
||||
type Bookmark struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
Description *string `json:"description"`
|
||||
FaviconUrl *string `json:"faviconUrl"`
|
||||
ScreenshotUrl *string `json:"screenshotUrl"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
IsArchived *bool `json:"isArchived"`
|
||||
IsFavorite *bool `json:"isFavorite"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type BookmarkTag struct {
|
||||
BookmarkID pgtype.UUID `json:"bookmarkId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Filename string `json:"filename"`
|
||||
OriginalName string `json:"originalName"`
|
||||
FileSize int64 `json:"fileSize"`
|
||||
MimeType *string `json:"mimeType"`
|
||||
FilePath string `json:"filePath"`
|
||||
ThumbnailPath *string `json:"thumbnailPath"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type FileTag struct {
|
||||
FileID pgtype.UUID `json:"fileId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
type Note struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content *string `json:"content"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type NoteTag struct {
|
||||
NoteID pgtype.UUID `json:"noteId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color *string `json:"color"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Status *string `json:"status"`
|
||||
Priority *string `json:"priority"`
|
||||
DueDate pgtype.Timestamp `json:"dueDate"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type TaskTag struct {
|
||||
TaskID pgtype.UUID `json:"taskId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"passwordHash"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
AddBookmarkTag(ctx context.Context, arg AddBookmarkTagParams) error
|
||||
AddTaskTag(ctx context.Context, arg AddTaskTagParams) error
|
||||
CreateBookmark(ctx context.Context, arg CreateBookmarkParams) (Bookmark, error)
|
||||
CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error)
|
||||
DeleteBookmark(ctx context.Context, arg DeleteBookmarkParams) error
|
||||
DeleteTask(ctx context.Context, arg DeleteTaskParams) error
|
||||
DeleteUser(ctx context.Context, id pgtype.UUID) error
|
||||
GetBookmarkByID(ctx context.Context, arg GetBookmarkByIDParams) (Bookmark, error)
|
||||
GetBookmarksByTag(ctx context.Context, arg GetBookmarksByTagParams) ([]Bookmark, error)
|
||||
GetBookmarksByUser(ctx context.Context, arg GetBookmarksByUserParams) ([]Bookmark, error)
|
||||
GetTaskByID(ctx context.Context, arg GetTaskByIDParams) (Task, error)
|
||||
GetTasksByStatus(ctx context.Context, arg GetTasksByStatusParams) ([]Task, error)
|
||||
GetTasksByTag(ctx context.Context, arg GetTasksByTagParams) ([]Task, error)
|
||||
GetTasksByUser(ctx context.Context, arg GetTasksByUserParams) ([]Task, error)
|
||||
GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error)
|
||||
GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error)
|
||||
ListUsers(ctx context.Context, arg ListUsersParams) ([]ListUsersRow, error)
|
||||
RemoveBookmarkTag(ctx context.Context, arg RemoveBookmarkTagParams) error
|
||||
RemoveTaskTag(ctx context.Context, arg RemoveTaskTagParams) error
|
||||
SearchBookmarks(ctx context.Context, arg SearchBookmarksParams) ([]Bookmark, error)
|
||||
SearchTasks(ctx context.Context, arg SearchTasksParams) ([]Task, error)
|
||||
UpdateBookmark(ctx context.Context, arg UpdateBookmarkParams) (Bookmark, error)
|
||||
UpdateLastLogin(ctx context.Context, id pgtype.UUID) error
|
||||
UpdateTask(ctx context.Context, arg UpdateTaskParams) (Task, error)
|
||||
UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
||||
@@ -0,0 +1,395 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: tasks.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const AddTaskTag = `-- name: AddTaskTag :exec
|
||||
INSERT INTO task_tags (task_id, tag_id) VALUES ($1, $2) ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
type AddTaskTagParams struct {
|
||||
TaskID pgtype.UUID `json:"taskId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddTaskTag(ctx context.Context, arg AddTaskTagParams) error {
|
||||
_, err := q.db.Exec(ctx, AddTaskTag, arg.TaskID, arg.TagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const CreateTask = `-- name: CreateTask :one
|
||||
INSERT INTO tasks (title, description, status, priority, due_date, user_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateTaskParams struct {
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Status *string `json:"status"`
|
||||
Priority *string `json:"priority"`
|
||||
DueDate pgtype.Timestamp `json:"dueDate"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, CreateTask,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.DueDate,
|
||||
arg.UserID,
|
||||
)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const DeleteTask = `-- name: DeleteTask :exec
|
||||
DELETE FROM tasks WHERE id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type DeleteTaskParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteTask(ctx context.Context, arg DeleteTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, DeleteTask, arg.ID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const GetTaskByID = `-- name: GetTaskByID :one
|
||||
SELECT id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE id = $1 AND user_id = $2 LIMIT 1
|
||||
`
|
||||
|
||||
type GetTaskByIDParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTaskByID(ctx context.Context, arg GetTaskByIDParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, GetTaskByID, arg.ID, arg.UserID)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetTasksByStatus = `-- name: GetTasksByStatus :many
|
||||
SELECT id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE user_id = $1 AND status = $2
|
||||
ORDER BY
|
||||
CASE priority
|
||||
WHEN 'high' THEN 1
|
||||
WHEN 'medium' THEN 2
|
||||
WHEN 'low' THEN 3
|
||||
END,
|
||||
due_date ASC NULLS LAST,
|
||||
created_at DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
type GetTasksByStatusParams struct {
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Status *string `json:"status"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTasksByStatus(ctx context.Context, arg GetTasksByStatusParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, GetTasksByStatus,
|
||||
arg.UserID,
|
||||
arg.Status,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetTasksByTag = `-- name: GetTasksByTag :many
|
||||
SELECT t.id, t.title, t.description, t.status, t.priority, t.due_date, t.user_id, t.created_at, t.updated_at
|
||||
FROM tasks t
|
||||
INNER JOIN task_tags tt ON t.id = tt.task_id
|
||||
INNER JOIN tags tg ON tt.tag_id = tg.id
|
||||
WHERE tg.id = $1 AND t.user_id = $2
|
||||
ORDER BY
|
||||
CASE t.priority
|
||||
WHEN 'high' THEN 1
|
||||
WHEN 'medium' THEN 2
|
||||
WHEN 'low' THEN 3
|
||||
END,
|
||||
t.due_date ASC NULLS LAST,
|
||||
t.created_at DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
type GetTasksByTagParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTasksByTag(ctx context.Context, arg GetTasksByTagParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, GetTasksByTag,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetTasksByUser = `-- name: GetTasksByUser :many
|
||||
SELECT id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE user_id = $1
|
||||
ORDER BY
|
||||
CASE priority
|
||||
WHEN 'high' THEN 1
|
||||
WHEN 'medium' THEN 2
|
||||
WHEN 'low' THEN 3
|
||||
END,
|
||||
due_date ASC NULLS LAST,
|
||||
created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type GetTasksByUserParams struct {
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTasksByUser(ctx context.Context, arg GetTasksByUserParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, GetTasksByUser, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const RemoveTaskTag = `-- name: RemoveTaskTag :exec
|
||||
DELETE FROM task_tags WHERE task_id = $1 AND tag_id = $2
|
||||
`
|
||||
|
||||
type RemoveTaskTagParams struct {
|
||||
TaskID pgtype.UUID `json:"taskId"`
|
||||
TagID pgtype.UUID `json:"tagId"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveTaskTag(ctx context.Context, arg RemoveTaskTagParams) error {
|
||||
_, err := q.db.Exec(ctx, RemoveTaskTag, arg.TaskID, arg.TagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const SearchTasks = `-- name: SearchTasks :many
|
||||
SELECT id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE user_id = $1 AND (
|
||||
title ILIKE $2 OR
|
||||
description ILIKE $2
|
||||
)
|
||||
ORDER BY
|
||||
CASE priority
|
||||
WHEN 'high' THEN 1
|
||||
WHEN 'medium' THEN 2
|
||||
WHEN 'low' THEN 3
|
||||
END,
|
||||
due_date ASC NULLS LAST,
|
||||
created_at DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
type SearchTasksParams struct {
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
Title string `json:"title"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchTasks(ctx context.Context, arg SearchTasksParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, SearchTasks,
|
||||
arg.UserID,
|
||||
arg.Title,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const UpdateTask = `-- name: UpdateTask :one
|
||||
UPDATE tasks
|
||||
SET title = $2,
|
||||
description = $3,
|
||||
status = $4,
|
||||
priority = $5,
|
||||
due_date = $6,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1 AND user_id = $7
|
||||
RETURNING id, title, description, status, priority, due_date, user_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateTaskParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Status *string `json:"status"`
|
||||
Priority *string `json:"priority"`
|
||||
DueDate pgtype.Timestamp `json:"dueDate"`
|
||||
UserID pgtype.UUID `json:"userId"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, UpdateTask,
|
||||
arg.ID,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.DueDate,
|
||||
arg.UserID,
|
||||
)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
// 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 CreateUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (email, password_hash, first_name, last_name, avatar_url, is_active, is_verified)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"passwordHash"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, CreateUser,
|
||||
arg.Email,
|
||||
arg.PasswordHash,
|
||||
arg.FirstName,
|
||||
arg.LastName,
|
||||
arg.AvatarUrl,
|
||||
arg.IsActive,
|
||||
arg.IsVerified,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.IsVerified,
|
||||
&i.LastLogin,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const DeleteUser = `-- name: DeleteUser :exec
|
||||
DELETE FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUser(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, DeleteUser, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const GetUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
|
||||
FROM users
|
||||
WHERE email = $1 LIMIT 1
|
||||
`
|
||||
|
||||
type GetUserByEmailRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
|
||||
row := q.db.QueryRow(ctx, GetUserByEmail, email)
|
||||
var i GetUserByEmailRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.IsVerified,
|
||||
&i.LastLogin,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
|
||||
FROM users
|
||||
WHERE id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
type GetUserByIDRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, GetUserByID, id)
|
||||
var i GetUserByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.IsVerified,
|
||||
&i.LastLogin,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const ListUsers = `-- name: ListUsers :many
|
||||
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
|
||||
FROM users
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListUsersParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
type ListUsersRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]ListUsersRow, error) {
|
||||
rows, err := q.db.Query(ctx, ListUsers, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListUsersRow{}
|
||||
for rows.Next() {
|
||||
var i ListUsersRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.IsVerified,
|
||||
&i.LastLogin,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const UpdateLastLogin = `-- name: UpdateLastLogin :exec
|
||||
UPDATE users
|
||||
SET last_login = CURRENT_TIMESTAMP
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateLastLogin(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, UpdateLastLogin, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const UpdateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET first_name = $2,
|
||||
last_name = $3,
|
||||
avatar_url = $4,
|
||||
is_active = $5,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1
|
||||
RETURNING id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
}
|
||||
|
||||
type UpdateUserRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
FirstName *string `json:"firstName"`
|
||||
LastName *string `json:"lastName"`
|
||||
AvatarUrl *string `json:"avatarUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
IsVerified *bool `json:"isVerified"`
|
||||
LastLogin pgtype.Timestamp `json:"lastLogin"`
|
||||
CreatedAt pgtype.Timestamp `json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamp `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, UpdateUser,
|
||||
arg.ID,
|
||||
arg.FirstName,
|
||||
arg.LastName,
|
||||
arg.AvatarUrl,
|
||||
arg.IsActive,
|
||||
)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.IsVerified,
|
||||
&i.LastLogin,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user