db

package
v0.0.0-...-ab07b4f Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package db contains image related CRUD functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	ID           string    `db:"image_id"`      // Unique identifier.
	ImageURL     string    `db:"image_url"`     // Display image URL to the path on file system containing image.
	UserID       string    `db:"user_id"`       // ID of the user who created the image.
	DateUploaded time.Time `db:"date_uploaded"` // When the image was uploaded.
}

Image represents an individual image.

type Store

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

Store manages the set of APIs for user 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, image Image) error

Create adds an Image to the database. It returns the created Image with fields like ID and DateUploaded populated.

func (Store) Delete

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

Delete removes the Image identified by a given ID.

func (Store) Query

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

Query gets all Images from the database.

func (Store) QueryByID

func (s Store) QueryByID(ctx context.Context, imageID string) (Image, error)

QueryByID finds the Image identified by a given ID.

func (Store) QueryByUserID

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

QueryByUserID finds the Image identified by a given User ID.

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, image Image) error

Update modifies metadata about an Image. It will error if the specified ID is invalid or does not reference an existing Image.

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