repo

package
v0.0.0-...-646d846 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Unlicense Imports: 7 Imported by: 0

Documentation

Overview

Package repo contains a database persistence strategy for our domain models. All interactions with the database should be implemented in this package; no higher-level concept (e.g. request handlers) should execute database queries directly.

The repo package contains unit tests that are executed against an actual database instance, provided by Docker Compose. This gives us confidence that our repo code actually works, ensuring that our queries are valid, and our model mapping is correct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Database *pgxpool.Pool
}

Client provides access to all supported database interactions.

func NewClient

func NewClient(pool *pgxpool.Pool) *Client

NewClient returns a new repo client.

func (*Client) CreateAccount

func (c *Client) CreateAccount(ctx context.Context, a *domain.Account) (*domain.Account, error)

CreateAccount inserts an account into the database.

func (*Client) CreateTask

func (c *Client) CreateTask(ctx context.Context, t *domain.Task) (*domain.Task, error)

CreateTask inserts a task into the database.

func (*Client) DeleteTaskByIDAndAccountID

func (c *Client) DeleteTaskByIDAndAccountID(ctx context.Context, taskID, accountID int64) error

DeleteTask deletes a task from the database.

func (*Client) GetAccountByID

func (c *Client) GetAccountByID(ctx context.Context, id int64) (*domain.Account, error)

GetAccountByID fetches an account by id from the database or returns nil if not found.

func (*Client) GetAccountByUsername

func (c *Client) GetAccountByUsername(ctx context.Context, username string) (*domain.Account, error)

GetAccountByUsername fetches an account by username from the database or returns nil if not found.

func (*Client) GetAllTasksByAccountID

func (c *Client) GetAllTasksByAccountID(ctx context.Context, accountID int64) ([]*domain.Task, error)

GetAllTasksByAccountID fetches all tasks by account from the database.

func (*Client) GetTaskByIDAndAccountID

func (c *Client) GetTaskByIDAndAccountID(ctx context.Context, taskID, accountID int64) (*domain.Task, error)

GetTaskByIDAndAccountID fetches a task by ID and account from the database, or returns nil if not found.

func (*Client) MarkIncompleteTasksCompleteByAccountID

func (c *Client) MarkIncompleteTasksCompleteByAccountID(ctx context.Context, accountID int64) (int64, error)

MarkIncompleteTasksCompleteByAccountID marks all incomplete tasks for an account complete.

func (*Client) UpdateTask

func (c *Client) UpdateTask(ctx context.Context, t *domain.Task) (*domain.Task, error)

UpdateTask updates a task in the database.

Jump to

Keyboard shortcuts

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