db

package
v0.0.0-...-f01271b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("resourse not found")
	ErrForbidden = errors.New("action forbidden")
)

Functions

func AutoMigrate

func AutoMigrate(config config.Config)

func Close

func Close(conn *pgx.Conn)

func Connect

func Connect(config config.Config) *pgx.Conn

func Drop

func Drop(config config.Config)

func InitTestDB

func InitTestDB(config *config.Config)

func Nullable

func Nullable[T any](row *T, err error) (*T, error)

func NullableID

func NullableID(row string, err error) (string, error)

Types

type AddCommentParams

type AddCommentParams struct {
	ID        string `json:"id"`
	AuthorID  string `json:"author_id"`
	ArticleID string `json:"article_id"`
	Body      string `json:"body"`
}

type Article

type Article struct {
	ID          string    `json:"id"`
	AuthorID    string    `json:"author_id"`
	Slug        string    `json:"slug"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Body        string    `json:"body"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type ArticleTag

type ArticleTag struct {
	ArticleID string `json:"article_id"`
	TagID     string `json:"tag_id"`
}

type Comment

type Comment struct {
	ID        string    `json:"id"`
	AuthorID  string    `json:"author_id"`
	ArticleID string    `json:"article_id"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type ConduitStore

type ConduitStore struct {
	*Queries // implements Querier
	// contains filtered or unexported fields
}

func (*ConduitStore) CreateArticleTx

func (store *ConduitStore) CreateArticleTx(
	ctx context.Context,
	arg CreateArticleTxParams,
) (*CreateArticleTxResult, error)

func (*ConduitStore) DeleteArticleTx

func (store *ConduitStore) DeleteArticleTx(
	ctx context.Context,
	arg DeleteArticleTxParams,
) error

func (*ConduitStore) DeleteCommentTx

func (store *ConduitStore) DeleteCommentTx(
	ctx context.Context,
	arg DeleteCommentTxParams,
) error

func (*ConduitStore) FavoriteArticleTx

func (store *ConduitStore) FavoriteArticleTx(
	ctx context.Context,
	arg FavoriteArticleTxParams,
) (*FavoriteArticleTxResult, error)

func (*ConduitStore) UnfavoriteArticleTx

func (store *ConduitStore) UnfavoriteArticleTx(
	ctx context.Context,
	arg UnfavoriteArticleTxParams,
) (*UnfavoriteArticleTxResult, error)

func (*ConduitStore) UpdateArticleTx

func (store *ConduitStore) UpdateArticleTx(
	ctx context.Context,
	arg UpdateArticleTxParams,
) (*UpdateArticleTxResult, error)

type CreateArticleParams

type CreateArticleParams struct {
	ID          string `json:"id"`
	AuthorID    string `json:"author_id"`
	Slug        string `json:"slug"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Body        string `json:"body"`
}

type CreateArticleTagParams

type CreateArticleTagParams struct {
	ArticleID string `json:"article_id"`
	TagID     string `json:"tag_id"`
}

type CreateArticleTxParams

type CreateArticleTxParams struct {
	CreateArticleParams
	Tags []string
}

type CreateArticleTxResult

type CreateArticleTxResult struct {
	Article *Article
	Tags    []string
	User    *User
}

type CreateTagParams

type CreateTagParams struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type CreateUserParams

type CreateUserParams struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type DBTX

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
}

type DeleteArticleTxParams

type DeleteArticleTxParams struct {
	UserID string
	Slug   string
}

type DeleteCommentTxParams

type DeleteCommentTxParams struct {
	CommentID string
	UserID    string
}

type DoesFavoriteExistParams

type DoesFavoriteExistParams struct {
	UserID    string `json:"user_id"`
	ArticleID string `json:"article_id"`
}

type Favorite

type Favorite struct {
	ArticleID string `json:"article_id"`
	UserID    string `json:"user_id"`
}

type FavoriteArticleParams

type FavoriteArticleParams struct {
	UserID    string `json:"user_id"`
	ArticleID string `json:"article_id"`
}

type FavoriteArticleTxParams

type FavoriteArticleTxParams struct {
	UserID string
	Slug   string
}

type FavoriteArticleTxResult

type FavoriteArticleTxResult struct {
	Article   *GetArticleBySlugRow
	Favorited bool
	Following bool
}

type Follow

type Follow struct {
	FollowerID  string `json:"follower_id"`
	FollowingID string `json:"following_id"`
}

type FollowUserParams

type FollowUserParams struct {
	FollowerID  string `json:"follower_id"`
	FollowingID string `json:"following_id"`
}

type GetArticleAuthorIDBySlugRow

type GetArticleAuthorIDBySlugRow struct {
	ID       string `json:"id"`
	AuthorID string `json:"author_id"`
}

type GetArticleBySlugRow

type GetArticleBySlugRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount int64       `json:"favorites_count"`
	TagList        interface{} `json:"tag_list"`
	AuthorID       string      `json:"author_id"`
	Username       string      `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetArticlesByAuthorParams

type GetArticlesByAuthorParams struct {
	Username string `json:"username"`
	Limit    int32  `json:"limit"`
	Offset   int32  `json:"offset"`
	Column4  string `json:"column_4"`
}

type GetArticlesByAuthorRow

type GetArticlesByAuthorRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount *int64      `json:"favorites_count"`
	Favorited      bool        `json:"favorited"`
	Following      bool        `json:"following"`
	TagList        interface{} `json:"tag_list"`
	Username       *string     `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetArticlesByFavoritedParams

type GetArticlesByFavoritedParams struct {
	Username string `json:"username"`
	Limit    int32  `json:"limit"`
	Offset   int32  `json:"offset"`
	Column4  string `json:"column_4"`
}

type GetArticlesByFavoritedRow

type GetArticlesByFavoritedRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount *int64      `json:"favorites_count"`
	Favorited      bool        `json:"favorited"`
	Following      bool        `json:"following"`
	TagList        interface{} `json:"tag_list"`
	Username       *string     `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetArticlesByTagParams

type GetArticlesByTagParams struct {
	Name    string `json:"name"`
	Limit   int32  `json:"limit"`
	Offset  int32  `json:"offset"`
	Column4 string `json:"column_4"`
}

type GetArticlesByTagRow

type GetArticlesByTagRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount *int64      `json:"favorites_count"`
	Favorited      bool        `json:"favorited"`
	Following      bool        `json:"following"`
	TagList        interface{} `json:"tag_list"`
	Username       *string     `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetArticlesFeedParams

type GetArticlesFeedParams struct {
	UserID string `json:"user_id"`
	Limit  int32  `json:"limit"`
	Offset int32  `json:"offset"`
}

type GetArticlesFeedRow

type GetArticlesFeedRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount *int64      `json:"favorites_count"`
	Favorited      bool        `json:"favorited"`
	TagList        interface{} `json:"tag_list"`
	Username       *string     `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetArticlesParams

type GetArticlesParams struct {
	Limit   int32  `json:"limit"`
	Offset  int32  `json:"offset"`
	Column3 string `json:"column_3"`
}

type GetArticlesRow

type GetArticlesRow struct {
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Title          string      `json:"title"`
	Description    string      `json:"description"`
	Body           string      `json:"body"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	FavoritesCount *int64      `json:"favorites_count"`
	Favorited      bool        `json:"favorited"`
	Following      bool        `json:"following"`
	TagList        interface{} `json:"tag_list"`
	Username       *string     `json:"username"`
	Bio            *string     `json:"bio"`
	Image          *string     `json:"image"`
}

type GetCommentsBySlugRow

type GetCommentsBySlugRow struct {
	ID        string    `json:"id"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	AuthorID  *string   `json:"author_id"`
	Username  *string   `json:"username"`
	Bio       *string   `json:"bio"`
	Image     *string   `json:"image"`
}

type IsFollowingListParams

type IsFollowingListParams struct {
	FollowerID  string   `json:"follower_id"`
	FollowingID []string `json:"following_id"`
}

type IsFollowingParams

type IsFollowingParams struct {
	FollowerID  string `json:"follower_id"`
	FollowingID string `json:"following_id"`
}

type Querier

type Querier interface {
	AddComment(ctx context.Context, arg AddCommentParams) (*Comment, error)
	CountArticles(ctx context.Context) (int64, error)
	CountArticlesByAuthor(ctx context.Context, username string) (int64, error)
	CountArticlesByFavorited(ctx context.Context, username string) (int64, error)
	CountArticlesByTag(ctx context.Context, name string) (int64, error)
	CountArticlesFeed(ctx context.Context, followerID string) (int64, error)
	CreateArticle(ctx context.Context, arg CreateArticleParams) (*Article, error)
	CreateArticleTag(ctx context.Context, arg CreateArticleTagParams) (*ArticleTag, error)
	CreateTag(ctx context.Context, arg CreateTagParams) (string, error)
	CreateUser(ctx context.Context, arg CreateUserParams) (*User, error)
	DeleteArticle(ctx context.Context, slug string) error
	DeleteComment(ctx context.Context, id string) error
	DoesFavoriteExist(ctx context.Context, arg DoesFavoriteExistParams) (bool, error)
	DoesUserExist(ctx context.Context, id string) (bool, error)
	FavoriteArticle(ctx context.Context, arg FavoriteArticleParams) error
	FollowUser(ctx context.Context, arg FollowUserParams) error
	GetArticleAuthorID(ctx context.Context, slug string) (string, error)
	GetArticleAuthorIDBySlug(ctx context.Context, slug string) (*GetArticleAuthorIDBySlugRow, error)
	GetArticleBySlug(ctx context.Context, slug string) (*GetArticleBySlugRow, error)
	GetArticleIDBySlug(ctx context.Context, slug string) (string, error)
	GetArticles(ctx context.Context, arg GetArticlesParams) ([]*GetArticlesRow, error)
	GetArticlesByAuthor(ctx context.Context, arg GetArticlesByAuthorParams) ([]*GetArticlesByAuthorRow, error)
	GetArticlesByFavorited(ctx context.Context, arg GetArticlesByFavoritedParams) ([]*GetArticlesByFavoritedRow, error)
	GetArticlesByTag(ctx context.Context, arg GetArticlesByTagParams) ([]*GetArticlesByTagRow, error)
	GetArticlesFeed(ctx context.Context, arg GetArticlesFeedParams) ([]*GetArticlesFeedRow, error)
	GetCommentAuthorID(ctx context.Context, id string) (string, error)
	GetCommentsBySlug(ctx context.Context, slug string) ([]*GetCommentsBySlugRow, error)
	GetFollowees(ctx context.Context, followerID string) ([]*Follow, error)
	GetTags(ctx context.Context) ([]string, error)
	GetUser(ctx context.Context, id string) (*User, error)
	GetUserByEmail(ctx context.Context, email string) (*User, error)
	GetUserByUsername(ctx context.Context, username string) (*User, error)
	IsFollowing(ctx context.Context, arg IsFollowingParams) (bool, error)
	IsFollowingList(ctx context.Context, arg IsFollowingListParams) ([]bool, error)
	UnfavoriteArticle(ctx context.Context, arg UnfavoriteArticleParams) error
	UnfollowUser(ctx context.Context, arg UnfollowUserParams) error
	UpdateArticle(ctx context.Context, arg UpdateArticleParams) (*Article, error)
	UpdateUser(ctx context.Context, arg UpdateUserParams) (*User, error)
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) AddComment

func (q *Queries) AddComment(ctx context.Context, arg AddCommentParams) (*Comment, error)

func (*Queries) CountArticles

func (q *Queries) CountArticles(ctx context.Context) (int64, error)

func (*Queries) CountArticlesByAuthor

func (q *Queries) CountArticlesByAuthor(ctx context.Context, username string) (int64, error)

func (*Queries) CountArticlesByFavorited

func (q *Queries) CountArticlesByFavorited(ctx context.Context, username string) (int64, error)

func (*Queries) CountArticlesByTag

func (q *Queries) CountArticlesByTag(ctx context.Context, name string) (int64, error)

func (*Queries) CountArticlesFeed

func (q *Queries) CountArticlesFeed(ctx context.Context, followerID string) (int64, error)

func (*Queries) CreateArticle

func (q *Queries) CreateArticle(ctx context.Context, arg CreateArticleParams) (*Article, error)

func (*Queries) CreateArticleTag

func (q *Queries) CreateArticleTag(ctx context.Context, arg CreateArticleTagParams) (*ArticleTag, error)

func (*Queries) CreateTag

func (q *Queries) CreateTag(ctx context.Context, arg CreateTagParams) (string, error)

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (*User, error)

func (*Queries) DeleteArticle

func (q *Queries) DeleteArticle(ctx context.Context, slug string) error

func (*Queries) DeleteComment

func (q *Queries) DeleteComment(ctx context.Context, id string) error

func (*Queries) DoesFavoriteExist

func (q *Queries) DoesFavoriteExist(ctx context.Context, arg DoesFavoriteExistParams) (bool, error)

func (*Queries) DoesUserExist

func (q *Queries) DoesUserExist(ctx context.Context, id string) (bool, error)

func (*Queries) FavoriteArticle

func (q *Queries) FavoriteArticle(ctx context.Context, arg FavoriteArticleParams) error

func (*Queries) FollowUser

func (q *Queries) FollowUser(ctx context.Context, arg FollowUserParams) error

func (*Queries) GetArticleAuthorID

func (q *Queries) GetArticleAuthorID(ctx context.Context, slug string) (string, error)

func (*Queries) GetArticleAuthorIDBySlug

func (q *Queries) GetArticleAuthorIDBySlug(ctx context.Context, slug string) (*GetArticleAuthorIDBySlugRow, error)

func (*Queries) GetArticleBySlug

func (q *Queries) GetArticleBySlug(ctx context.Context, slug string) (*GetArticleBySlugRow, error)

func (*Queries) GetArticleIDBySlug

func (q *Queries) GetArticleIDBySlug(ctx context.Context, slug string) (string, error)

func (*Queries) GetArticles

func (q *Queries) GetArticles(ctx context.Context, arg GetArticlesParams) ([]*GetArticlesRow, error)

func (*Queries) GetArticlesByAuthor

func (q *Queries) GetArticlesByAuthor(ctx context.Context, arg GetArticlesByAuthorParams) ([]*GetArticlesByAuthorRow, error)

func (*Queries) GetArticlesByFavorited

func (q *Queries) GetArticlesByFavorited(ctx context.Context, arg GetArticlesByFavoritedParams) ([]*GetArticlesByFavoritedRow, error)

func (*Queries) GetArticlesByTag

func (q *Queries) GetArticlesByTag(ctx context.Context, arg GetArticlesByTagParams) ([]*GetArticlesByTagRow, error)

func (*Queries) GetArticlesFeed

func (q *Queries) GetArticlesFeed(ctx context.Context, arg GetArticlesFeedParams) ([]*GetArticlesFeedRow, error)

func (*Queries) GetCommentAuthorID

func (q *Queries) GetCommentAuthorID(ctx context.Context, id string) (string, error)

func (*Queries) GetCommentsBySlug

func (q *Queries) GetCommentsBySlug(ctx context.Context, slug string) ([]*GetCommentsBySlugRow, error)

func (*Queries) GetFollowees

func (q *Queries) GetFollowees(ctx context.Context, followerID string) ([]*Follow, error)

func (*Queries) GetTags

func (q *Queries) GetTags(ctx context.Context) ([]string, error)

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, id string) (*User, error)

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (*User, error)

func (*Queries) GetUserByUsername

func (q *Queries) GetUserByUsername(ctx context.Context, username string) (*User, error)

func (*Queries) IsFollowing

func (q *Queries) IsFollowing(ctx context.Context, arg IsFollowingParams) (bool, error)

func (*Queries) IsFollowingList

func (q *Queries) IsFollowingList(ctx context.Context, arg IsFollowingListParams) ([]bool, error)

func (*Queries) UnfavoriteArticle

func (q *Queries) UnfavoriteArticle(ctx context.Context, arg UnfavoriteArticleParams) error

func (*Queries) UnfollowUser

func (q *Queries) UnfollowUser(ctx context.Context, arg UnfollowUserParams) error

func (*Queries) UpdateArticle

func (q *Queries) UpdateArticle(ctx context.Context, arg UpdateArticleParams) (*Article, error)

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (*User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type Store

type Store interface {
	Querier // Querier gives access sqlc-generated methods
	CreateArticleTx(ctx context.Context, arg CreateArticleTxParams) (*CreateArticleTxResult, error)
	UpdateArticleTx(ctx context.Context, arg UpdateArticleTxParams) (*UpdateArticleTxResult, error)
	FavoriteArticleTx(ctx context.Context, arg FavoriteArticleTxParams) (*FavoriteArticleTxResult, error)
	UnfavoriteArticleTx(ctx context.Context, arg UnfavoriteArticleTxParams) (*UnfavoriteArticleTxResult, error)
	DeleteArticleTx(ctx context.Context, arg DeleteArticleTxParams) error
	DeleteCommentTx(ctx context.Context, arg DeleteCommentTxParams) error
}

func NewConduitStore

func NewConduitStore(db *pgx.Conn) Store

type Tag

type Tag struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type UnfavoriteArticleParams

type UnfavoriteArticleParams struct {
	UserID    string `json:"user_id"`
	ArticleID string `json:"article_id"`
}

type UnfavoriteArticleTxParams

type UnfavoriteArticleTxParams struct {
	UserID string
	Slug   string
}

type UnfavoriteArticleTxResult

type UnfavoriteArticleTxResult struct {
	Article   *GetArticleBySlugRow
	Favorited bool
	Following bool
}

type UnfollowUserParams

type UnfollowUserParams struct {
	FollowerID  string `json:"follower_id"`
	FollowingID string `json:"following_id"`
}

type UpdateArticleParams

type UpdateArticleParams struct {
	Slug        *string `json:"slug"`
	Title       *string `json:"title"`
	Description *string `json:"description"`
	Body        *string `json:"body"`
	ID          string  `json:"id"`
	AuthorID    string  `json:"author_id"`
}

type UpdateArticleTxParams

type UpdateArticleTxParams struct {
	UpdateArticleParams
}

type UpdateArticleTxResult

type UpdateArticleTxResult struct {
	Article   *GetArticleBySlugRow
	Favorited bool
	Following bool
}

type UpdateUserParams

type UpdateUserParams struct {
	Username *string `json:"username"`
	Email    *string `json:"email"`
	Password *string `json:"password"`
	Bio      *string `json:"bio"`
	Image    *string `json:"image"`
	ID       string  `json:"id"`
}

type User

type User struct {
	ID        string    `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Password  string    `json:"password"`
	Bio       *string   `json:"bio"`
	Image     *string   `json:"image"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL