// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: favorites.sql package db import ( "context" "database/sql" ) const CreateFavorite = `-- name: CreateFavorite :exec INSERT INTO favorites (url, title, favicon_url, position, created_at, updated_at) VALUES ( ?, ?, ?, COALESCE((SELECT MAX(position) + 1 FROM favorites), 0), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP ) ` // Insert a new favorite with auto-incremented position func (q *Queries) CreateFavorite(ctx context.Context, url string, title sql.NullString, faviconUrl sql.NullString) error { _, err := q.db.ExecContext(ctx, CreateFavorite, url, title, faviconUrl) return err } const DeleteFavorite = `-- name: DeleteFavorite :exec DELETE FROM favorites WHERE url = ? ` // Delete a favorite by URL func (q *Queries) DeleteFavorite(ctx context.Context, url string) error { _, err := q.db.ExecContext(ctx, DeleteFavorite, url) return err } const GetAllFavorites = `-- name: GetAllFavorites :many SELECT id, url, title, favicon_url, position, created_at, updated_at FROM favorites ORDER BY position ASC ` // Get all favorites ordered by position func (q *Queries) GetAllFavorites(ctx context.Context) ([]Favorite, error) { rows, err := q.db.QueryContext(ctx, GetAllFavorites) if err != nil { return nil, err } defer rows.Close() items := []Favorite{} for rows.Next() { var i Favorite if err := rows.Scan( &i.ID, &i.Url, &i.Title, &i.FaviconUrl, &i.Position, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetFavoriteByURL = `-- name: GetFavoriteByURL :one SELECT id, url, title, favicon_url, position, created_at, updated_at FROM favorites WHERE url = ? LIMIT 1 ` // Get a specific favorite by URL func (q *Queries) GetFavoriteByURL(ctx context.Context, url string) (Favorite, error) { row := q.db.QueryRowContext(ctx, GetFavoriteByURL, url) var i Favorite err := row.Scan( &i.ID, &i.Url, &i.Title, &i.FaviconUrl, &i.Position, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const GetFavoriteCount = `-- name: GetFavoriteCount :one SELECT COUNT(*) as count FROM favorites ` // Get total count of favorites func (q *Queries) GetFavoriteCount(ctx context.Context) (int64, error) { row := q.db.QueryRowContext(ctx, GetFavoriteCount) var count int64 err := row.Scan(&count) return count, err } const IsFavorite = `-- name: IsFavorite :one SELECT COUNT(*) as count FROM favorites WHERE url = ? LIMIT 1 ` // Check if a URL is favorited func (q *Queries) IsFavorite(ctx context.Context, url string) (int64, error) { row := q.db.QueryRowContext(ctx, IsFavorite, url) var count int64 err := row.Scan(&count) return count, err } const UpdateFavorite = `-- name: UpdateFavorite :exec UPDATE favorites SET title = ?, favicon_url = ?, updated_at = CURRENT_TIMESTAMP WHERE url = ? ` // Update favorite metadata (title, favicon) func (q *Queries) UpdateFavorite(ctx context.Context, title sql.NullString, faviconUrl sql.NullString, url string) error { _, err := q.db.ExecContext(ctx, UpdateFavorite, title, faviconUrl, url) return err } const UpdateFavoritePosition = `-- name: UpdateFavoritePosition :exec UPDATE favorites SET position = ?, updated_at = CURRENT_TIMESTAMP WHERE url = ? ` // Update the position of a favorite func (q *Queries) UpdateFavoritePosition(ctx context.Context, position int64, url string) error { _, err := q.db.ExecContext(ctx, UpdateFavoritePosition, position, url) return err }