Documentation
¶
Overview ¶
Example of connecting to different database types
Example of checking database health ¶
Example of executing queries with different database types ¶
Example of implementing the repository pattern with the db package ¶
Example of executing queries with retries ¶
Example of using transactions with different database types
Index ¶
- type MongoUserRepository
- type Product
- type SQLUserRepository
- func (r *SQLUserRepository) Create(ctx context.Context, user *User) error
- func (r *SQLUserRepository) Delete(ctx context.Context, id string) error
- func (r *SQLUserRepository) FindActive(ctx context.Context) ([]User, error)
- func (r *SQLUserRepository) GetByID(ctx context.Context, id string) (*User, error)
- func (r *SQLUserRepository) Update(ctx context.Context, user *User) error
- type User
- type UserEntity
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoUserRepository ¶
type MongoUserRepository struct {
}
MongoUserRepository implements UserRepository for MongoDB
func NewMongoUserRepository ¶
func NewMongoUserRepository() *MongoUserRepository
NewMongoUserRepository creates a new MongoUserRepository
type SQLUserRepository ¶
type SQLUserRepository struct {
}
SQLUserRepository implements UserRepository for SQL databases
func NewSQLUserRepository ¶
func NewSQLUserRepository() *SQLUserRepository
NewSQLUserRepository creates a new SQLUserRepository
func (*SQLUserRepository) Create ¶
func (r *SQLUserRepository) Create(ctx context.Context, user *User) error
Create inserts a new user
func (*SQLUserRepository) Delete ¶
func (r *SQLUserRepository) Delete(ctx context.Context, id string) error
Delete removes a user by ID
func (*SQLUserRepository) FindActive ¶
func (r *SQLUserRepository) FindActive(ctx context.Context) ([]User, error)
FindActive finds all active users
type UserEntity ¶
UserEntity represents a user in the system
type UserRepository ¶
type UserRepository interface {
GetByID(ctx context.Context, id string) (*User, error)
Create(ctx context.Context, user *User) error
Update(ctx context.Context, user *User) error
Delete(ctx context.Context, id string) error
FindActive(ctx context.Context) ([]User, error)
}
UserRepository defines the interface for user data access
Click to show internal directories.
Click to hide internal directories.