pg

package
v0.0.0-...-1f9e35f Latest Latest
Warning

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

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

Documentation

Overview

Package pg provides memory storage functionality for users.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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, u user.User) error

Create inserts a new user into the database.

func (Store) Delete

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

Delete removes a user from the database.

func (Store) Query

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

Query retrieves a list of existing users from the database.

func (Store) QueryByEmail

func (s Store) QueryByEmail(ctx context.Context, email string) (user.User, error)

QueryByEmail gets the specified user from the database by email.

func (Store) QueryByID

func (s Store) QueryByID(ctx context.Context, userID string) (user.User, error)

QueryByID gets the specified user from the database.

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, u user.User) error

Update replaces a user 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.

type User

type User struct {
	ID           string         `db:"user_id"`
	Name         string         `db:"name"`
	Email        string         `db:"email"`
	PasswordHash []byte         `db:"password_hash"`
	Roles        pq.StringArray `db:"roles"`
	DateCreated  time.Time      `db:"date_created"`
	DateUpdated  time.Time      `db:"date_updated"`
}

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

Jump to

Keyboard shortcuts

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