Documentation
¶
Index ¶
- func NewPostgresNoteRepository(db *pgxpool.Pool) (repository.NoteRepository, error)
- func NewPostgresNoteRepositoryWithOpts(db *pgxpool.Pool, opts ...RepositoryOption) (repository.NoteRepository, error)
- func NewPostgresUserRepository(db *pgxpool.Pool) (repository.UserRepository, error)
- func NewPostgresUserRepositoryWithOpts(db *pgxpool.Pool, opts ...RepositoryOption) (repository.UserRepository, error)
- type BaseRepository
- func (r *BaseRepository) ClearTransaction()
- func (r *BaseRepository) Exec(ctx context.Context, sql string, args ...interface{}) (int64, error)
- func (r *BaseRepository) GetDB() interface{}
- func (r *BaseRepository) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (r *BaseRepository) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- func (r *BaseRepository) SetTransaction(tx pgx.Tx)
- func (r *BaseRepository) WithContext(ctx context.Context) (context.Context, context.CancelFunc)
- type PostgresNoteRepository
- func (r *PostgresNoteRepository) Create(note *model.Note) error
- func (r *PostgresNoteRepository) DeleteByID(id string) error
- func (r *PostgresNoteRepository) GetAllNotes() ([]*model.Note, error)
- func (r *PostgresNoteRepository) GetAllNotesByUserID(userID string) ([]*model.Note, error)
- func (r *PostgresNoteRepository) GetByID(id string) (*model.Note, error)
- func (r *PostgresNoteRepository) GetListByUserID(userID string, limit, offset int) ([]*model.Note, error)
- func (r *PostgresNoteRepository) Update(note *model.Note) error
- type PostgresTransactionManager
- type PostgresUserRepository
- func (r *PostgresUserRepository) Create(user *model.User) error
- func (r *PostgresUserRepository) DeleteByID(id string) error
- func (r *PostgresUserRepository) GetAllUsers() ([]*model.User, error)
- func (r *PostgresUserRepository) GetByID(id string) (*model.User, error)
- func (r *PostgresUserRepository) GetUserByEmail(email string) (*model.User, error)
- func (r *PostgresUserRepository) GetUserByUsername(username string) (*model.User, error)
- func (r *PostgresUserRepository) Update(user *model.User) error
- type RepositoryOption
- type TransactionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPostgresNoteRepository ¶
func NewPostgresNoteRepository(db *pgxpool.Pool) (repository.NoteRepository, error)
NewPostgresNoteRepository создает новый экземпляр репозитория заметок с PostgreSQL
func NewPostgresNoteRepositoryWithOpts ¶
func NewPostgresNoteRepositoryWithOpts(db *pgxpool.Pool, opts ...RepositoryOption) (repository.NoteRepository, error)
NewPostgresNoteRepositoryWithOpts создает новый экземпляр репозитория заметок с PostgreSQL с опциями
func NewPostgresUserRepository ¶
func NewPostgresUserRepository(db *pgxpool.Pool) (repository.UserRepository, error)
NewPostgresUserRepository создает новый экземпляр репозитория пользователей с PostgreSQL
func NewPostgresUserRepositoryWithOpts ¶
func NewPostgresUserRepositoryWithOpts(db *pgxpool.Pool, opts ...RepositoryOption) (repository.UserRepository, error)
NewPostgresUserRepositoryWithOpts создает новый экземпляр репозитория пользователей с PostgreSQL с опциями
Types ¶
type BaseRepository ¶
type BaseRepository struct {
// contains filtered or unexported fields
}
BaseRepository содержит общую логику для всех репозиториев
func NewBaseRepository ¶
func NewBaseRepository(db *pgxpool.Pool, timeout time.Duration) *BaseRepository
NewBaseRepository создает новый экземпляр базового репозитория
func (*BaseRepository) ClearTransaction ¶
func (r *BaseRepository) ClearTransaction()
ClearTransaction убирает транзакцию
func (*BaseRepository) GetDB ¶
func (r *BaseRepository) GetDB() interface{}
GetDB возвращает пул подключений или транзакцию, если она установлена
func (*BaseRepository) Query ¶
func (r *BaseRepository) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
Query выполняет запрос и возвращает несколько строк
func (*BaseRepository) SetTransaction ¶
func (r *BaseRepository) SetTransaction(tx pgx.Tx)
SetTransaction устанавливает транзакцию для репозитория
func (*BaseRepository) WithContext ¶
func (r *BaseRepository) WithContext(ctx context.Context) (context.Context, context.CancelFunc)
WithContext возвращает контекст с таймаутом
type PostgresNoteRepository ¶
type PostgresNoteRepository struct {
*BaseRepository
}
PostgresNoteRepository реализация интерфейсов репозитория для заметок с использованием PostgreSQL
func (*PostgresNoteRepository) Create ¶
func (r *PostgresNoteRepository) Create(note *model.Note) error
Create добавляет новую заметку в базу данных
func (*PostgresNoteRepository) DeleteByID ¶
func (r *PostgresNoteRepository) DeleteByID(id string) error
DeleteByID удаляет заметку по её ID
func (*PostgresNoteRepository) GetAllNotes ¶
func (r *PostgresNoteRepository) GetAllNotes() ([]*model.Note, error)
GetAllNotes возвращает все заметки
func (*PostgresNoteRepository) GetAllNotesByUserID ¶
func (r *PostgresNoteRepository) GetAllNotesByUserID(userID string) ([]*model.Note, error)
GetAllNotesByUserID возвращает все заметки пользователя по его ID
func (*PostgresNoteRepository) GetByID ¶
func (r *PostgresNoteRepository) GetByID(id string) (*model.Note, error)
GetByID возвращает заметку по её ID
func (*PostgresNoteRepository) GetListByUserID ¶
func (r *PostgresNoteRepository) GetListByUserID(userID string, limit, offset int) ([]*model.Note, error)
GetListByUserID возвращает список заметок пользователя с пагинацией
type PostgresTransactionManager ¶
type PostgresTransactionManager struct {
// contains filtered or unexported fields
}
PostgresTransactionManager реализация TransactionManager для PostgreSQL
func NewPostgresTransactionManager ¶
func NewPostgresTransactionManager(db *pgxpool.Pool) *PostgresTransactionManager
NewPostgresTransactionManager создает новый менеджер транзакций
func (*PostgresTransactionManager) WithinTransaction ¶
func (tm *PostgresTransactionManager) WithinTransaction(ctx context.Context, fn func(tx pgx.Tx) error) error
WithinTransaction выполняет функцию в транзакции
type PostgresUserRepository ¶
type PostgresUserRepository struct {
*BaseRepository
}
PostgresUserRepository реализация интерфейсов репозитория для пользователей с использованием PostgreSQL
func (*PostgresUserRepository) Create ¶
func (r *PostgresUserRepository) Create(user *model.User) error
Create добавляет нового пользователя в базу данных
func (*PostgresUserRepository) DeleteByID ¶
func (r *PostgresUserRepository) DeleteByID(id string) error
DeleteByID удаляет пользователя по его ID
func (*PostgresUserRepository) GetAllUsers ¶
func (r *PostgresUserRepository) GetAllUsers() ([]*model.User, error)
GetAllUsers возвращает всех пользователей
func (*PostgresUserRepository) GetByID ¶
func (r *PostgresUserRepository) GetByID(id string) (*model.User, error)
GetByID возвращает пользователя по его ID
func (*PostgresUserRepository) GetUserByEmail ¶
func (r *PostgresUserRepository) GetUserByEmail(email string) (*model.User, error)
GetUserByEmail возвращает пользователя по его email
func (*PostgresUserRepository) GetUserByUsername ¶
func (r *PostgresUserRepository) GetUserByUsername(username string) (*model.User, error)
GetUserByUsername возвращает пользователя по его имени пользователя
type RepositoryOption ¶
type RepositoryOption func(*BaseRepository)
RepositoryOption функция для настройки репозитория
func WithTimeout ¶
func WithTimeout(timeout time.Duration) RepositoryOption
WithTimeout устанавливает таймаут для операций