postgres

package
v0.0.0-...-60da083 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatLimitOffset

func FormatLimitOffset(limit, offset int) string

FormatLimitOffset returns a LIMIT/OFFSET clause or an empty string if none is specified.

func NewSessionStore

func NewSessionStore(db *DB) *postgresstore.PostgresStore

Types

type DB

type DB struct {

	// Connection string
	DSN string
	// Application logger
	Logger todo.Logger
	// EnableQueryLogging toggles INFO logging of underlying SQL queries.
	EnableQueryLogging bool

	// Now returns current time in UTC rounded to the nearest microsecond
	Now func() time.Time
	// contains filtered or unexported fields
}

DB is a database driver wrapper which exposes utility methods for interacting with Postgres.

func New

func New(dsn string) *DB

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context) (*Tx, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) Migrate

func (db *DB) Migrate() error

func (*DB) Open

func (db *DB) Open(ctx context.Context) error

type ItemListService

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

func NewItemListService

func NewItemListService(db *DB) *ItemListService

func (*ItemListService) CreateItem

func (svc *ItemListService) CreateItem(ctx context.Context, item *todo.Item) error

func (*ItemListService) CreateList

func (svc *ItemListService) CreateList(ctx context.Context, list *todo.List) error

func (*ItemListService) DeleteItem

func (svc *ItemListService) DeleteItem(ctx context.Context, id int) error

func (*ItemListService) DeleteList

func (svc *ItemListService) DeleteList(ctx context.Context, id int) error

func (*ItemListService) FindItemByID

func (svc *ItemListService) FindItemByID(ctx context.Context, id int) (*todo.Item, error)

func (*ItemListService) FindItems

func (svc *ItemListService) FindItems(ctx context.Context, f todo.ItemFilter) ([]*todo.Item, error)

func (*ItemListService) FindListByID

func (svc *ItemListService) FindListByID(ctx context.Context, id int) (*todo.List, error)

func (*ItemListService) FindLists

func (svc *ItemListService) FindLists(ctx context.Context, f todo.ListFilter) ([]*todo.List, error)

func (*ItemListService) UpdateItem

func (svc *ItemListService) UpdateItem(ctx context.Context, id int, upd todo.ItemUpdate) (*todo.Item, error)

func (*ItemListService) UpdateList

func (svc *ItemListService) UpdateList(ctx context.Context, id int, upd todo.ListUpdate) (*todo.List, error)

type Logger

type Logger struct {
	todo.Logger
}

Logger implements a pgx.Logger which logs SQL queries

func (*Logger) Log

func (l *Logger) Log(ctx context.Context, level pgx.LogLevel, message string, data map[string]interface{})

type Time

type Time time.Time

Time is a helper type used on time.Time to ensure that records read/written to postgres are properly formatted and in UTC time rounded to the nearest microsecond.

func (*Time) Scan

func (t *Time) Scan(value interface{}) error

Scan reads a time value from the database.

func (*Time) Value

func (t *Time) Value() (driver.Value, error)

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx is a transaction wrapper with configurable now time parameter.

type UserService

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

func NewUserService

func NewUserService(db *DB) *UserService

func (*UserService) CreateUser

func (svc *UserService) CreateUser(ctx context.Context, user *todo.User) error

func (*UserService) DeleteUser

func (svc *UserService) DeleteUser(ctx context.Context, id int) error

func (*UserService) FindUserByAPIKey

func (svc *UserService) FindUserByAPIKey(ctx context.Context, apiKey string) (*todo.User, error)

func (*UserService) FindUserByID

func (svc *UserService) FindUserByID(ctx context.Context, id int) (*todo.User, error)

func (*UserService) FindUserByName

func (svc *UserService) FindUserByName(ctx context.Context, name string) (*todo.User, error)

func (*UserService) FindUsers

func (svc *UserService) FindUsers(ctx context.Context, f todo.UserFilter) ([]*todo.User, error)

func (*UserService) LoginUser

func (svc *UserService) LoginUser(ctx context.Context, user *todo.User) error

func (*UserService) UpdateUser

func (svc *UserService) UpdateUser(ctx context.Context, id int, upd todo.UserUpdate) (*todo.User, error)

Jump to

Keyboard shortcuts

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