repository

package
v0.0.0-...-9067f3d Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package repository provides a database client and a set of methods for interacting with the database.

The repository package abstracts away the details of interacting with the database, allowing the rest of the application to use a simpler, higher-level API for accessing the data. By centralizing database access in the repository package, it helps to ensure consistency and maintainability of the data access layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUniqueUsername

func GenerateUniqueUsername() string

GenerateUniqueUsername generates a unique username for testing

Types

type DbClient

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

DbClient is a wrapper around the sql.DB struct It is used to connect to the database and execute queries Safe for concurrent use by multiple goroutines

func NewDBClient

func NewDBClient() *DbClient

NewDBClient returns a new instance of DbClient

func (*DbClient) Close

func (c *DbClient) Close()

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*DbClient) Connect

func (c *DbClient) Connect(config config.PostgreSQL)

Connect establishes a connection to PostgreSQL database when provided with a valid config FIXME unable to specify schema name via search_path=auth https://github.com/go-pg/pg/issues/351#issuecomment-474875596

type EventRepository

type EventRepository interface {
	CreateEvent(ctx context.Context, event *model.Event) error
	Close() error
}

EventRepository is an interface for interacting with the event table

func NewEventRepository

func NewEventRepository(c *DbClient) EventRepository

NewEventRepository creates a new event repository

type MockEventRepository

type MockEventRepository struct {
	Events []*model.Event
}

MockEventRepository is a mock implementation of the EventRepository interface

func (*MockEventRepository) Close

func (r *MockEventRepository) Close() error

Close closes the repository prepared statements

func (*MockEventRepository) CreateEvent

func (r *MockEventRepository) CreateEvent(_ context.Context, event *model.Event) error

CreateEvent creates a new event

type MockSessionRepository

type MockSessionRepository struct {
	Sessions []*model.Session
}

MockSessionRepository is a mock implementation of the SessionRepository interface

func (*MockSessionRepository) Close

func (r *MockSessionRepository) Close() error

Close no-op

func (*MockSessionRepository) CreateSession

func (r *MockSessionRepository) CreateSession(_ context.Context, session *model.Session) error

CreateSession creates a new session

func (*MockSessionRepository) GetSessions

func (r *MockSessionRepository) GetSessions(_ context.Context, userID uuid.UUID) ([]*model.Session, error)

GetSessions gets all sessions for a user

func (*MockSessionRepository) RemoveSession

func (r *MockSessionRepository) RemoveSession(_ context.Context, sessionID string) error

RemoveSession removes a session

func (*MockSessionRepository) RemoveSessions

func (r *MockSessionRepository) RemoveSessions(_ context.Context, userID uuid.UUID) error

RemoveSessions removes all sessions for a user

type MockUserRepository

type MockUserRepository struct {
	Users []*model.User
}

MockUserRepository is a mock implementation of the UserRepository interface

func (*MockUserRepository) Close

func (r *MockUserRepository) Close() error

Close closes the repository prepared statements

func (*MockUserRepository) CreateUser

func (r *MockUserRepository) CreateUser(ctx context.Context, user *model.User) error

CreateUser creates a new user

func (*MockUserRepository) ExistsUser

func (r *MockUserRepository) ExistsUser(_ context.Context, username string) bool

ExistsUser checks if a user exists

func (*MockUserRepository) GetUser

func (r *MockUserRepository) GetUser(_ context.Context, user *model.User) error

GetUser gets a user by username or ID

type SessionRepository

type SessionRepository interface {
	CreateSession(ctx context.Context, session *model.Session) error
	GetSessions(ctx context.Context, userID uuid.UUID) ([]*model.Session, error)
	RemoveSession(ctx context.Context, sessionID string) error
	RemoveSessions(ctx context.Context, userID uuid.UUID) error
	Close() error
}

SessionRepository is an interface for interacting with the session table

func NewSessionRepository

func NewSessionRepository(c *DbClient) SessionRepository

NewSessionRepository creates a new session repository

type UserRepository

type UserRepository interface {
	CreateUser(ctx context.Context, user *model.User) error
	ExistsUser(ctx context.Context, username string) bool
	GetUser(ctx context.Context, user *model.User) error
	Close() error
}

UserRepository is an interface for interacting with the user table

func NewUserRepository

func NewUserRepository(c *DbClient) UserRepository

NewUserRepository creates a new user repository

Jump to

Keyboard shortcuts

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