Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorCode(err error) string
- type Blog
- type Comment
- type CreateBlogParams
- type CreateCommentParams
- type CreateFavoriteParams
- type CreateSessionParams
- type CreateUserParams
- type CreateUserTxParams
- type CreateUserTxResult
- type CreateVerifyEmailParams
- type DBTX
- type DeleteBlogTxParams
- type DeleteBlogTxResult
- type DeleteCommentByBlogIDParams
- type Favorite
- type ListBlogsParams
- type ListCommentsByBlogParams
- type ListFavoritesByBlogParams
- type Querier
- type Queries
- func (q *Queries) CreateBlog(ctx context.Context, arg CreateBlogParams) (Blog, error)
- func (q *Queries) CreateComment(ctx context.Context, arg CreateCommentParams) (Comment, error)
- func (q *Queries) CreateFavorite(ctx context.Context, arg CreateFavoriteParams) (Favorite, error)
- func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)
- func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
- func (q *Queries) CreateVerifyEmail(ctx context.Context, arg CreateVerifyEmailParams) (VerifyEmail, error)
- func (q *Queries) DeleteBlog(ctx context.Context, id uuid.UUID) error
- func (q *Queries) DeleteComment(ctx context.Context, id uuid.UUID) error
- func (q *Queries) DeleteCommentByBlogID(ctx context.Context, arg DeleteCommentByBlogIDParams) error
- func (q *Queries) DeleteCommentsByBlog(ctx context.Context, blogID uuid.UUID) (pgconn.CommandTag, error)
- func (q *Queries) DeleteFavorite(ctx context.Context, id uuid.UUID) error
- func (q *Queries) DeleteFavoritesByBlog(ctx context.Context, blogID uuid.UUID) (pgconn.CommandTag, error)
- func (q *Queries) GetBlog(ctx context.Context, id uuid.UUID) (Blog, error)
- func (q *Queries) GetBlogBySlug(ctx context.Context, slug string) (Blog, error)
- func (q *Queries) GetComment(ctx context.Context, id uuid.UUID) (Comment, error)
- func (q *Queries) GetFavorite(ctx context.Context, id uuid.UUID) (Favorite, error)
- func (q *Queries) GetSession(ctx context.Context, id uuid.UUID) (Session, error)
- func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error)
- func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error)
- func (q *Queries) ListBlogs(ctx context.Context, arg ListBlogsParams) ([]Blog, error)
- func (q *Queries) ListCommentsByBlog(ctx context.Context, arg ListCommentsByBlogParams) ([]Comment, error)
- func (q *Queries) ListFavoritesByBlog(ctx context.Context, arg ListFavoritesByBlogParams) ([]Favorite, error)
- func (q *Queries) UpdateBlog(ctx context.Context, arg UpdateBlogParams) (Blog, error)
- func (q *Queries) UpdateComment(ctx context.Context, arg UpdateCommentParams) (Comment, error)
- func (q *Queries) UpdateCommentByBlogID(ctx context.Context, arg UpdateCommentByBlogIDParams) (Comment, error)
- func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
- func (q *Queries) UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error)
- func (q *Queries) WithTx(tx pgx.Tx) *Queries
- type SQLStore
- func (store *SQLStore) CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error)
- func (store *SQLStore) DeleteBlogTx(ctx context.Context, arg DeleteBlogTxParams) (DeleteBlogTxResult, error)
- func (store *SQLStore) VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error)
- type Session
- type Store
- type UpdateBlogParams
- type UpdateCommentByBlogIDParams
- type UpdateCommentParams
- type UpdateUserParams
- type UpdateVerifyEmailParams
- type User
- type VerifyEmail
- type VerifyEmailTxParams
- type VerifyEmailTxResult
Constants ¶
const ( ForeignKeyViolation = "23503" UniqueViolation = "23505" )
Constants for PostgreSQL error codes ForeignKeyViolation represents a foreign key violation error UniqueViolation represents a unique constraint violation error
Variables ¶
var ErrRecordNotFound = pgx.ErrNoRows
ErrRecordNotFound is returned when a query returns no rows
var ErrUniqueViolation = &pgconn.PgError{ Code: UniqueViolation, }
ErrUniqueViolation is returned when a unique constraint is violated
Functions ¶
Types ¶
type Blog ¶
type Blog struct { ID uuid.UUID `json:"id"` Title string `json:"title"` Slug string `json:"slug"` Description string `json:"description"` Body string `json:"body"` BannerImage string `json:"banner_image"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` AuthorID uuid.UUID `json:"author_id"` }
type CreateBlogParams ¶
type CreateCommentParams ¶
type CreateFavoriteParams ¶
type CreateSessionParams ¶
type CreateUserParams ¶
type CreateUserTxParams ¶
type CreateUserTxParams struct { CreateUserParams AfterCreate func(user User) error }
type CreateUserTxResult ¶
type CreateUserTxResult struct {
User User
}
type CreateVerifyEmailParams ¶
type DeleteBlogTxParams ¶
DeleteBlogTxParams contains the input parameters of the delete blog transaction
type DeleteBlogTxResult ¶
type DeleteBlogTxResult struct { DeletedBlogID uuid.UUID `json:"deleted_blog_id"` DeletedCommentsCount int64 `json:"deleted_comments_count"` DeletedFavoritesCount int64 `json:"deleted_favorites_count"` }
DeleteBlogTxResult is the result of the delete blog transaction
type ListBlogsParams ¶
type Querier ¶
type Querier interface { CreateBlog(ctx context.Context, arg CreateBlogParams) (Blog, error) CreateComment(ctx context.Context, arg CreateCommentParams) (Comment, error) CreateFavorite(ctx context.Context, arg CreateFavoriteParams) (Favorite, error) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) CreateVerifyEmail(ctx context.Context, arg CreateVerifyEmailParams) (VerifyEmail, error) DeleteBlog(ctx context.Context, id uuid.UUID) error DeleteComment(ctx context.Context, id uuid.UUID) error DeleteCommentByBlogID(ctx context.Context, arg DeleteCommentByBlogIDParams) error DeleteCommentsByBlog(ctx context.Context, blogID uuid.UUID) (pgconn.CommandTag, error) DeleteFavorite(ctx context.Context, id uuid.UUID) error DeleteFavoritesByBlog(ctx context.Context, blogID uuid.UUID) (pgconn.CommandTag, error) GetBlog(ctx context.Context, id uuid.UUID) (Blog, error) GetBlogBySlug(ctx context.Context, slug string) (Blog, error) GetComment(ctx context.Context, id uuid.UUID) (Comment, error) GetFavorite(ctx context.Context, id uuid.UUID) (Favorite, error) GetSession(ctx context.Context, id uuid.UUID) (Session, error) GetUser(ctx context.Context, id uuid.UUID) (User, error) GetUserByUsername(ctx context.Context, username string) (User, error) ListBlogs(ctx context.Context, arg ListBlogsParams) ([]Blog, error) ListCommentsByBlog(ctx context.Context, arg ListCommentsByBlogParams) ([]Comment, error) ListFavoritesByBlog(ctx context.Context, arg ListFavoritesByBlogParams) ([]Favorite, error) UpdateBlog(ctx context.Context, arg UpdateBlogParams) (Blog, error) UpdateComment(ctx context.Context, arg UpdateCommentParams) (Comment, error) UpdateCommentByBlogID(ctx context.Context, arg UpdateCommentByBlogIDParams) (Comment, error) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error) }
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) CreateBlog ¶
func (*Queries) CreateComment ¶
func (*Queries) CreateFavorite ¶
func (*Queries) CreateSession ¶
func (*Queries) CreateUser ¶
func (*Queries) CreateVerifyEmail ¶
func (q *Queries) CreateVerifyEmail(ctx context.Context, arg CreateVerifyEmailParams) (VerifyEmail, error)
func (*Queries) DeleteComment ¶
func (*Queries) DeleteCommentByBlogID ¶
func (q *Queries) DeleteCommentByBlogID(ctx context.Context, arg DeleteCommentByBlogIDParams) error
func (*Queries) DeleteCommentsByBlog ¶
func (*Queries) DeleteFavorite ¶
func (*Queries) DeleteFavoritesByBlog ¶
func (*Queries) GetBlogBySlug ¶
func (*Queries) GetComment ¶
func (*Queries) GetFavorite ¶
func (*Queries) GetSession ¶
func (*Queries) GetUserByUsername ¶
func (*Queries) ListCommentsByBlog ¶
func (*Queries) ListFavoritesByBlog ¶
func (*Queries) UpdateBlog ¶
func (*Queries) UpdateComment ¶
func (*Queries) UpdateCommentByBlogID ¶
func (*Queries) UpdateUser ¶
func (*Queries) UpdateVerifyEmail ¶
func (q *Queries) UpdateVerifyEmail(ctx context.Context, arg UpdateVerifyEmailParams) (VerifyEmail, error)
type SQLStore ¶
type SQLStore struct { *Queries // contains filtered or unexported fields }
provides functionality for executing all SQL queries and transactions
func (*SQLStore) CreateUserTx ¶
func (store *SQLStore) CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error)
func (*SQLStore) DeleteBlogTx ¶
func (store *SQLStore) DeleteBlogTx(ctx context.Context, arg DeleteBlogTxParams) (DeleteBlogTxResult, error)
DeleteBlogTx performs a deletion of a blog and all its associated data. It deletes the blog, its comments, and its favorites within a database transaction
func (*SQLStore) VerifyEmailTx ¶
func (store *SQLStore) VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error)
type Session ¶
type Session struct { ID uuid.UUID `json:"id"` UserID uuid.UUID `json:"user_id"` RefreshToken string `json:"refresh_token"` UserAgent string `json:"user_agent"` ClientIp string `json:"client_ip"` IsBlocked bool `json:"is_blocked"` ExpiresAt time.Time `json:"expires_at"` CreatedAt time.Time `json:"created_at"` }
type Store ¶
type Store interface { Querier DeleteBlogTx(ctx context.Context, arg DeleteBlogTxParams) (DeleteBlogTxResult, error) CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error) VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error) }
store defines all the functions related to execute db queries and also contains code for transactions in DB
type UpdateBlogParams ¶
type UpdateCommentParams ¶
type UpdateUserParams ¶
type UpdateVerifyEmailParams ¶
type User ¶
type User struct { ID uuid.UUID `json:"id"` Username string `json:"username"` HashedPassword string `json:"hashed_password"` FullName string `json:"full_name"` Email string `json:"email"` IsEmailVerified bool `json:"is_email_verified"` PasswordChangedAt time.Time `json:"password_changed_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
type VerifyEmail ¶
type VerifyEmailTxParams ¶
type VerifyEmailTxResult ¶
type VerifyEmailTxResult struct { User User VerifyEmail VerifyEmail }