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 ¶
- func GenerateUniqueUsername() string
- type DbClient
- type EventRepository
- type MockEventRepository
- type MockSessionRepository
- func (r *MockSessionRepository) Close() error
- func (r *MockSessionRepository) CreateSession(_ context.Context, session *model.Session) error
- func (r *MockSessionRepository) GetSessions(_ context.Context, userID uuid.UUID) ([]*model.Session, error)
- func (r *MockSessionRepository) RemoveSession(_ context.Context, sessionID string) error
- func (r *MockSessionRepository) RemoveSessions(_ context.Context, userID uuid.UUID) error
- type MockUserRepository
- type SessionRepository
- type UserRepository
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 (*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 ¶
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 ¶
CreateEvent creates a new event
type MockSessionRepository ¶
MockSessionRepository is a mock implementation of the SessionRepository interface
func (*MockSessionRepository) CreateSession ¶
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 ¶
RemoveSessions removes all sessions for a user
type MockUserRepository ¶
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 ¶
CreateUser creates a new user
func (*MockUserRepository) ExistsUser ¶
func (r *MockUserRepository) ExistsUser(_ context.Context, username string) bool
ExistsUser checks if a user exists
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