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 post related CRUD functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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"`
}

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

type Store

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

Store manages the set of API's for post 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, p Post) error

Create inserts a new post into the database.

func (Store) Delete

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

Delete removes a post from the database.

func (Store) Query

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

Query retrieves a list of existing posts from the database.

func (Store) QueryByID

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

QueryByID gets the specified post from the database.

func (Store) QueryByUserID

func (s Store) QueryByUserID(ctx context.Context, userID string) ([]Post, 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, p Post) error

Update replaces a post document in the database.

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