db

package
v0.0.0-...-40cf777 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package db contains comment related CRUD functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID          string    `db:"comment_id"`
	Description string    `db:"description"`
	UserID      string    `db:"user_id"`
	PostID      string    `db:"post_id"`
	DateCreated time.Time `db:"date_created"`
	DateUpdated time.Time `db:"date_updated"`
}

Comment represent the structure we need for moving data between the app and the database.

type Post

type Post struct {
	ID          string    `db:"post_id"`
	Title       string    `db:"title"`
	Description string    `db:"description"`
	UserID      string    `db:"user_id"`
	DateCreated time.Time `db:"date_created"`
	DateUpdated time.Time `db:"date_updated"`
}

type PostComment

type PostComment struct {
	ID                 string    `db:"post_id"`
	Title              string    `db:"title"`
	Description        string    `db:"description"`
	UserID             string    `db:"user_id"`
	DateCreated        time.Time `db:"date_created"`
	DateUpdated        time.Time `db:"date_updated"`
	CommentID          string    `db:"comment_id"`
	CommentDescription string    `db:"comment_description"`
	CommentUserID      string    `db:"comment_user_id"`
	CommentDateCreated time.Time `db:"comment_date_created"`
	CommentDateUpdated time.Time `db:"comment_date_updated"`
}

type Store

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

Store manages the set of API's for comment access.

func NewStore

func NewStore(log *zap.SugaredLogger, db *sqlx.DB) Store

NewStore constructs a data for api access.

func (Store) Create

func (s Store) Create(ctx context.Context, c Comment) error

Create inserts a new comment into the database.

func (Store) CreatePost

func (s Store) CreatePost(ctx context.Context, p Post) error

func (Store) Delete

func (s Store) Delete(ctx context.Context, commentID string) error

Delete removes a comment from the database.

func (Store) DeletePost

func (s Store) DeletePost(ctx context.Context, postID string) error

func (Store) Query

func (s Store) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Comment, error)

Query retrieves a list of existing comments from the database.

func (Store) QueryByID

func (s Store) QueryByID(ctx context.Context, commentID string) (Comment, error)

QueryByID gets the specified comment from the database.

func (Store) QueryByPostID

func (s Store) QueryByPostID(ctx context.Context, postID string) ([]Comment, error)

func (Store) QueryByUserID

func (s Store) QueryByUserID(ctx context.Context, userID string) ([]Comment, error)

func (Store) QueryPostsByPostID

func (s Store) QueryPostsByPostID(ctx context.Context, postID string) ([]PostComment, error)

func (Store) Tran

func (s Store) Tran(tx sqlx.ExtContext) Store

Tran return new Store with transaction in it.

func (Store) Update

func (s Store) Update(ctx context.Context, c Comment) error

Update replaces a comment document in the database.

func (Store) UpdatePost

func (s Store) UpdatePost(ctx context.Context, p Post) error

func (Store) WithinTran

func (s Store) WithinTran(ctx context.Context, fn func(sqlx.ExtContext) error) error

WithinTran runs passed function and do commit/rollback at the end.

Jump to

Keyboard shortcuts

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