Documentation
¶
Index ¶
- Constants
- func CloseConnections(connections []*Connection) error
- func CloseDB() error
- func GetDB(enforceConsistency ...bool) *sql.DB
- func GetReadDB() *sql.DB
- func GetWriteDB() *sql.DB
- func InitDB(rwConfig DatabaseConfig, roConfigs ...DatabaseConfig) error
- type APIKey
- type APIKeyRepository
- type APIKeyRepositoryPostgres
- func (r *APIKeyRepositoryPostgres) Count() (int64, error)
- func (r *APIKeyRepositoryPostgres) CountByUserId(userId Id) (int64, error)
- func (r *APIKeyRepositoryPostgres) Create(apiKey *APIKey) error
- func (r *APIKeyRepositoryPostgres) Delete(id Id) error
- func (r *APIKeyRepositoryPostgres) DeleteExpired() (int64, error)
- func (r *APIKeyRepositoryPostgres) GetById(id Id) (*APIKey, error)
- func (r *APIKeyRepositoryPostgres) GetByKey(key string) (*APIKey, error)
- func (r *APIKeyRepositoryPostgres) ListByUserId(userId Id, limit, offset int) ([]*APIKey, error)
- type AsyncTask
- type AsyncTaskMeta
- type AsyncTaskMetaRepository
- type AsyncTaskMetaRepositoryPostgres
- func (r *AsyncTaskMetaRepositoryPostgres) Create(id Id, key, value string) error
- func (r *AsyncTaskMetaRepositoryPostgres) Delete(id Id, key string) error
- func (r *AsyncTaskMetaRepositoryPostgres) Get(id Id, key string) (*AsyncTaskMeta, error)
- func (r *AsyncTaskMetaRepositoryPostgres) ListByAsyncTaskId(id Id) ([]*AsyncTaskMeta, error)
- func (r *AsyncTaskMetaRepositoryPostgres) Update(id Id, key, value string) error
- func (r *AsyncTaskMetaRepositoryPostgres) Upsert(id Id, key, value string) error
- type AsyncTaskRepository
- type AsyncTaskRepositoryPostgres
- func (r *AsyncTaskRepositoryPostgres) Complete(id Id, result string) error
- func (r *AsyncTaskRepositoryPostgres) CountByStatus(status string) (int64, error)
- func (r *AsyncTaskRepositoryPostgres) Create(task *AsyncTask) error
- func (r *AsyncTaskRepositoryPostgres) Fail(id Id, message string) error
- func (r *AsyncTaskRepositoryPostgres) ListByStatus(status string) ([]*AsyncTask, error)
- func (r *AsyncTaskRepositoryPostgres) MarkRunning(id Id) error
- type Config
- type ConfigRepository
- type ConfigRepositoryPostgres
- func (r *ConfigRepositoryPostgres) Create(key, value string) error
- func (r *ConfigRepositoryPostgres) Delete(key string) error
- func (r *ConfigRepositoryPostgres) Get(key string) (*Config, error)
- func (r *ConfigRepositoryPostgres) List() ([]*Config, error)
- func (r *ConfigRepositoryPostgres) Update(key, value string) error
- type Connection
- type DatabaseConfig
- type Id
- type Session
- type SessionRepository
- type SessionRepositoryPostgres
- func (r *SessionRepositoryPostgres) Count() (int64, error)
- func (r *SessionRepositoryPostgres) CountByUserId(userId Id) (int64, error)
- func (r *SessionRepositoryPostgres) Create(session *Session) error
- func (r *SessionRepositoryPostgres) Delete(id Id) error
- func (r *SessionRepositoryPostgres) DeleteByToken(token string) error
- func (r *SessionRepositoryPostgres) DeleteByUserId(userId Id) error
- func (r *SessionRepositoryPostgres) DeleteExpired() (int64, error)
- func (r *SessionRepositoryPostgres) GetById(id Id) (*Session, error)
- func (r *SessionRepositoryPostgres) GetByToken(token string) (*Session, error)
- func (r *SessionRepositoryPostgres) GetByUserId(userId Id) ([]*Session, error)
- func (r *SessionRepositoryPostgres) IsValid(token string) (bool, error)
- func (r *SessionRepositoryPostgres) UpdateExpiration(id Id, expiresAt time.Time) error
- type User
- type UserMeta
- type UserMetaRepository
- type UserMetaRepositoryPostgres
- func (r *UserMetaRepositoryPostgres) Create(id Id, key, value string) error
- func (r *UserMetaRepositoryPostgres) Delete(id Id, key string) error
- func (r *UserMetaRepositoryPostgres) Get(id Id, key string) (*UserMeta, error)
- func (r *UserMetaRepositoryPostgres) ListByUser(id Id) ([]*UserMeta, error)
- func (r *UserMetaRepositoryPostgres) Update(id Id, key, value string) error
- func (r *UserMetaRepositoryPostgres) Upsert(id Id, key, value string) error
- type UserRepository
- type UserRepositoryPostgres
- func (r *UserRepositoryPostgres) Count() (int64, error)
- func (r *UserRepositoryPostgres) Create(user *User) error
- func (r *UserRepositoryPostgres) Delete(id Id) error
- func (r *UserRepositoryPostgres) GetByAPIKey(apiKey string) (*User, error)
- func (r *UserRepositoryPostgres) GetByEmail(email string) (*User, error)
- func (r *UserRepositoryPostgres) GetById(id Id) (*User, error)
- func (r *UserRepositoryPostgres) List(limit, offset int) ([]*User, error)
- func (r *UserRepositoryPostgres) Update(user *User) error
- func (r *UserRepositoryPostgres) UpdateLastLogin(id Id) error
Constants ¶
const ( AsyncTaskStatusPending = "pending" AsyncTaskStatusRunning = "running" AsyncTaskStatusCompleted = "completed" AsyncTaskStatusFailed = "failed" AsyncTaskTypeNoop = "mut.noop" )
const ( UserRoleAdmin = "admin" UserRoleRegular = "regular" UserRoleReadOnly = "readonly" UserLanguageEN = "en" UserLanguageFR = "fr" UserThemeDefault = "default" UserThemeBlue = "blue" UserThemeSlate = "slate" UserThemeEmerald = "emerald" UserThemeDark = "dark" )
User role, language and theme constants
Variables ¶
This section is empty.
Functions ¶
func CloseConnections ¶
func CloseConnections(connections []*Connection) error
CloseConnections closes the database connections.
func GetDB ¶
GetDB returns a database connection, load-balancing reads unless enforceConsistency is true.
func GetReadDB ¶
GetReadDB round-robins across the read-write connection and configured read-only connections.
func InitDB ¶
func InitDB(rwConfig DatabaseConfig, roConfigs ...DatabaseConfig) error
InitDB initializes the global database connections.
Types ¶
type APIKey ¶
type APIKey struct {
Id Id
UserId Id
Name string
Key string
ExpiresAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
APIKey is the DB row for a user API key.
type APIKeyRepository ¶
type APIKeyRepository interface {
Create(apiKey *APIKey) error
GetById(id Id) (*APIKey, error)
GetByKey(key string) (*APIKey, error)
ListByUserId(userId Id, limit, offset int) ([]*APIKey, error)
Delete(id Id) error
DeleteExpired() (int64, error)
Count() (int64, error)
CountByUserId(userId Id) (int64, error)
}
APIKeyRepository is the interface for API key CRUD.
func NewAPIKeyRepository ¶
func NewAPIKeyRepository(db *sql.DB) APIKeyRepository
NewAPIKeyRepository returns the repository for the current driver
type APIKeyRepositoryPostgres ¶
type APIKeyRepositoryPostgres struct {
// contains filtered or unexported fields
}
APIKeyRepositoryPostgres implements APIKeyRepository for PostgreSQL
func (*APIKeyRepositoryPostgres) Count ¶
func (r *APIKeyRepositoryPostgres) Count() (int64, error)
Count returns the total number of API keys
func (*APIKeyRepositoryPostgres) CountByUserId ¶
func (r *APIKeyRepositoryPostgres) CountByUserId(userId Id) (int64, error)
CountByUserId returns the total number of API keys by user Id
func (*APIKeyRepositoryPostgres) Create ¶
func (r *APIKeyRepositoryPostgres) Create(apiKey *APIKey) error
Create inserts a row
func (*APIKeyRepositoryPostgres) Delete ¶
func (r *APIKeyRepositoryPostgres) Delete(id Id) error
Delete removes a API key
func (*APIKeyRepositoryPostgres) DeleteExpired ¶
func (r *APIKeyRepositoryPostgres) DeleteExpired() (int64, error)
DeleteExpired removes expired API keys
func (*APIKeyRepositoryPostgres) GetById ¶
func (r *APIKeyRepositoryPostgres) GetById(id Id) (*APIKey, error)
GetById returns a API key by Id
func (*APIKeyRepositoryPostgres) GetByKey ¶
func (r *APIKeyRepositoryPostgres) GetByKey(key string) (*APIKey, error)
GetByKey returns a API key by raw key
func (*APIKeyRepositoryPostgres) ListByUserId ¶
func (r *APIKeyRepositoryPostgres) ListByUserId(userId Id, limit, offset int) ([]*APIKey, error)
ListByUserId returns a paginated list of API keys by user Id.
type AsyncTask ¶
type AsyncTask struct {
Id Id
Type string
Status string
Payload *string
Result *string
Error *string
Attempts int
Priority int
RunAt *time.Time
LockedAt *time.Time
CompletedAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
AsyncTask is a single row in the async_tasks table.
type AsyncTaskMeta ¶
type AsyncTaskMeta struct {
Id Id
AsyncTaskId Id
Key string
Value string
CreatedAt time.Time
UpdatedAt time.Time
}
AsyncTaskMeta is a single row in the async_tasks_meta table.
type AsyncTaskMetaRepository ¶
type AsyncTaskMetaRepository interface {
Create(id Id, key, value string) error
Get(id Id, key string) (*AsyncTaskMeta, error)
Update(id Id, key, value string) error
Delete(id Id, key string) error
ListByAsyncTaskId(id Id) ([]*AsyncTaskMeta, error)
Upsert(id Id, key, value string) error
}
AsyncTaskMetaRepository is the interface for async task metadata CRUD.
func NewAsyncTaskMetaRepository ¶
func NewAsyncTaskMetaRepository(db *sql.DB) AsyncTaskMetaRepository
NewAsyncTaskMetaRepository returns the repository for async task metadata.
type AsyncTaskMetaRepositoryPostgres ¶
type AsyncTaskMetaRepositoryPostgres struct {
// contains filtered or unexported fields
}
func (*AsyncTaskMetaRepositoryPostgres) Create ¶
func (r *AsyncTaskMetaRepositoryPostgres) Create(id Id, key, value string) error
Create inserts an async task metadata row. TODO: remove if not used in future.
func (*AsyncTaskMetaRepositoryPostgres) Delete ¶
func (r *AsyncTaskMetaRepositoryPostgres) Delete(id Id, key string) error
Delete deletes an async task metadata row. TODO: remove if not used in future.
func (*AsyncTaskMetaRepositoryPostgres) Get ¶
func (r *AsyncTaskMetaRepositoryPostgres) Get(id Id, key string) (*AsyncTaskMeta, error)
Get returns async task metadata by key. TODO: remove if not used in future.
func (*AsyncTaskMetaRepositoryPostgres) ListByAsyncTaskId ¶
func (r *AsyncTaskMetaRepositoryPostgres) ListByAsyncTaskId(id Id) ([]*AsyncTaskMeta, error)
ListByAsyncTaskId lists async task metadata rows by async task id. TODO: remove if not used in future.
type AsyncTaskRepository ¶
type AsyncTaskRepository interface {
Create(task *AsyncTask) error
MarkRunning(id Id) error
Complete(id Id, result string) error
Fail(id Id, message string) error
CountByStatus(status string) (int64, error)
ListByStatus(status string) ([]*AsyncTask, error)
}
AsyncTaskRepository is the interface for async task persistence.
func NewAsyncTaskRepository ¶
func NewAsyncTaskRepository(db *sql.DB) AsyncTaskRepository
NewAsyncTaskRepository returns an async task repository.
type AsyncTaskRepositoryPostgres ¶
type AsyncTaskRepositoryPostgres struct {
// contains filtered or unexported fields
}
func (*AsyncTaskRepositoryPostgres) Complete ¶
func (r *AsyncTaskRepositoryPostgres) Complete(id Id, result string) error
Complete marks a task as completed.
func (*AsyncTaskRepositoryPostgres) CountByStatus ¶
func (r *AsyncTaskRepositoryPostgres) CountByStatus(status string) (int64, error)
CountByStatus counts async task rows by status.
func (*AsyncTaskRepositoryPostgres) Create ¶
func (r *AsyncTaskRepositoryPostgres) Create(task *AsyncTask) error
Create inserts an async task row.
func (*AsyncTaskRepositoryPostgres) Fail ¶
func (r *AsyncTaskRepositoryPostgres) Fail(id Id, message string) error
Fail marks a task as failed. TODO: remove if not used in future.
func (*AsyncTaskRepositoryPostgres) ListByStatus ¶
func (r *AsyncTaskRepositoryPostgres) ListByStatus(status string) ([]*AsyncTask, error)
ListByStatus lists async tasks with the given status.
func (*AsyncTaskRepositoryPostgres) MarkRunning ¶
func (r *AsyncTaskRepositoryPostgres) MarkRunning(id Id) error
MarkRunning sets a task to running.
type ConfigRepository ¶
type ConfigRepository interface {
Create(key, value string) error
Get(key string) (*Config, error)
Update(key, value string) error
Delete(key string) error
List() ([]*Config, error)
}
ConfigRepository is the interface for config CRUD.
func NewConfigRepository ¶
func NewConfigRepository(db *sql.DB) ConfigRepository
NewConfigRepository returns the config repository.
type ConfigRepositoryPostgres ¶
type ConfigRepositoryPostgres struct {
// contains filtered or unexported fields
}
ConfigRepositoryPostgres implements ConfigRepository for PostgreSQL.
func (*ConfigRepositoryPostgres) Create ¶
func (r *ConfigRepositoryPostgres) Create(key, value string) error
Create inserts a row
func (*ConfigRepositoryPostgres) Delete ¶
func (r *ConfigRepositoryPostgres) Delete(key string) error
Delete removes a config. TODO: remove if not used in future.
func (*ConfigRepositoryPostgres) Get ¶
func (r *ConfigRepositoryPostgres) Get(key string) (*Config, error)
Get returns a config by key
func (*ConfigRepositoryPostgres) List ¶
func (r *ConfigRepositoryPostgres) List() ([]*Config, error)
List returns a list of configs. TODO: remove if not used in future.
func (*ConfigRepositoryPostgres) Update ¶
func (r *ConfigRepositoryPostgres) Update(key, value string) error
Update updates a config
type Connection ¶
Connection is the database connection.
func NewConnection ¶
func NewConnection(config DatabaseConfig) (*Connection, error)
NewConnection creates a new database connection based on the driver
func (*Connection) Ping ¶
func (c *Connection) Ping() error
Ping checks if the database connection is alive. TODO: remove if not used in future.
type DatabaseConfig ¶
type DatabaseConfig struct {
Driver string
Host string
Port int
Username string
Password string
Database string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime int
}
DatabaseConfig holds database connection configuration.
type Id ¶
type Id string
Id is a PostgreSQL UUID key that implements sql.Scanner and driver.Valuer.
type Session ¶
type Session struct {
Id Id
Token string
UserId Id
IPAddress *string
UserAgent *string
ExpiresAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
Session is the DB row for a user session.
type SessionRepository ¶
type SessionRepository interface {
Create(session *Session) error
GetByToken(token string) (*Session, error)
GetById(id Id) (*Session, error)
GetByUserId(userId Id) ([]*Session, error)
Delete(id Id) error
DeleteByToken(token string) error
DeleteByUserId(userId Id) error
DeleteExpired() (int64, error)
IsValid(token string) (bool, error)
UpdateExpiration(id Id, expiresAt time.Time) error
Count() (int64, error)
CountByUserId(userId Id) (int64, error)
}
SessionRepository is the interface for session CRUD.
func NewSessionRepository ¶
func NewSessionRepository(db *sql.DB) SessionRepository
NewSessionRepository returns the repository for the current driver
type SessionRepositoryPostgres ¶
type SessionRepositoryPostgres struct {
// contains filtered or unexported fields
}
SessionRepositoryPostgres implements SessionRepository for PostgreSQL
func (*SessionRepositoryPostgres) Count ¶
func (r *SessionRepositoryPostgres) Count() (int64, error)
Count returns the total number of sessions
func (*SessionRepositoryPostgres) CountByUserId ¶
func (r *SessionRepositoryPostgres) CountByUserId(userId Id) (int64, error)
CountByUserId returns the total number of sessions by user Id. TODO: remove if not used in future.
func (*SessionRepositoryPostgres) Create ¶
func (r *SessionRepositoryPostgres) Create(session *Session) error
Create inserts a row
func (*SessionRepositoryPostgres) Delete ¶
func (r *SessionRepositoryPostgres) Delete(id Id) error
Delete removes a session
func (*SessionRepositoryPostgres) DeleteByToken ¶
func (r *SessionRepositoryPostgres) DeleteByToken(token string) error
DeleteByToken removes a session by token. TODO: remove if not used in future.
func (*SessionRepositoryPostgres) DeleteByUserId ¶
func (r *SessionRepositoryPostgres) DeleteByUserId(userId Id) error
DeleteByUserId removes a session by user Id
func (*SessionRepositoryPostgres) DeleteExpired ¶
func (r *SessionRepositoryPostgres) DeleteExpired() (int64, error)
DeleteExpired removes expired sessions
func (*SessionRepositoryPostgres) GetById ¶
func (r *SessionRepositoryPostgres) GetById(id Id) (*Session, error)
GetById returns a session by Id. TODO: remove if not used in future.
func (*SessionRepositoryPostgres) GetByToken ¶
func (r *SessionRepositoryPostgres) GetByToken(token string) (*Session, error)
GetByToken returns a session by token
func (*SessionRepositoryPostgres) GetByUserId ¶
func (r *SessionRepositoryPostgres) GetByUserId(userId Id) ([]*Session, error)
GetByUserId returns a list of sessions by user Id
func (*SessionRepositoryPostgres) IsValid ¶
func (r *SessionRepositoryPostgres) IsValid(token string) (bool, error)
IsValid checks if a session is valid. TODO: remove if not used in future.
func (*SessionRepositoryPostgres) UpdateExpiration ¶
func (r *SessionRepositoryPostgres) UpdateExpiration(id Id, expiresAt time.Time) error
UpdateExpiration updates the expiration time of a session. TODO: remove if not used in future.
type User ¶
type User struct {
Id Id
Name string
Email string
Password string
Role string
IsActive bool
LastLoginAt time.Time
Language string
Theme string
CreatedAt time.Time
UpdatedAt time.Time
}
User is the DB row for a user.
type UserMeta ¶
type UserMeta struct {
Id Id
Key string
Value string
UserId Id
CreatedAt time.Time
UpdatedAt time.Time
}
UserMeta is extra metadata for a user.
type UserMetaRepository ¶
type UserMetaRepository interface {
Create(id Id, key, value string) error
Get(id Id, key string) (*UserMeta, error)
Update(id Id, key, value string) error
Delete(id Id, key string) error
ListByUser(id Id) ([]*UserMeta, error)
Upsert(id Id, key, value string) error
}
UserMetaRepository is the interface for user metadata CRUD.
func NewUserMetaRepository ¶
func NewUserMetaRepository(db *sql.DB) UserMetaRepository
NewUserMetaRepository returns the repository for the current driver
type UserMetaRepositoryPostgres ¶
type UserMetaRepositoryPostgres struct {
// contains filtered or unexported fields
}
UserMetaRepositoryPostgres implements UserMetaRepository for PostgreSQL
func (*UserMetaRepositoryPostgres) Create ¶
func (r *UserMetaRepositoryPostgres) Create(id Id, key, value string) error
Create inserts a user meta. TODO: remove if not used in future.
func (*UserMetaRepositoryPostgres) Delete ¶
func (r *UserMetaRepositoryPostgres) Delete(id Id, key string) error
Delete removes a user meta. TODO: remove if not used in future.
func (*UserMetaRepositoryPostgres) Get ¶
func (r *UserMetaRepositoryPostgres) Get(id Id, key string) (*UserMeta, error)
Get returns a user meta. TODO: remove if not used in future.
func (*UserMetaRepositoryPostgres) ListByUser ¶
func (r *UserMetaRepositoryPostgres) ListByUser(id Id) ([]*UserMeta, error)
ListByUser returns a list of user meta. TODO: remove if not used in future.
type UserRepository ¶
type UserRepository interface {
Create(user *User) error
GetById(id Id) (*User, error)
GetByAPIKey(apiKey string) (*User, error)
GetByEmail(email string) (*User, error)
Update(user *User) error
UpdateLastLogin(id Id) error
Delete(id Id) error
List(limit, offset int) ([]*User, error)
Count() (int64, error)
}
UserRepository is the interface for user CRUD.
func NewUserRepository ¶
func NewUserRepository(db *sql.DB) UserRepository
NewUserRepository returns the repository for the current driver
type UserRepositoryPostgres ¶
type UserRepositoryPostgres struct {
// contains filtered or unexported fields
}
UserRepositoryPostgres implements UserRepository for PostgreSQL
func (*UserRepositoryPostgres) Count ¶
func (r *UserRepositoryPostgres) Count() (int64, error)
Count returns the total number of users
func (*UserRepositoryPostgres) Create ¶
func (r *UserRepositoryPostgres) Create(user *User) error
Create inserts a row
func (*UserRepositoryPostgres) Delete ¶
func (r *UserRepositoryPostgres) Delete(id Id) error
Delete removes a user
func (*UserRepositoryPostgres) GetByAPIKey ¶
func (r *UserRepositoryPostgres) GetByAPIKey(apiKey string) (*User, error)
GetByAPIKey returns a user by API key (raw key lookup)
func (*UserRepositoryPostgres) GetByEmail ¶
func (r *UserRepositoryPostgres) GetByEmail(email string) (*User, error)
GetByEmail returns a user by email
func (*UserRepositoryPostgres) GetById ¶
func (r *UserRepositoryPostgres) GetById(id Id) (*User, error)
GetById returns a user by Id
func (*UserRepositoryPostgres) List ¶
func (r *UserRepositoryPostgres) List(limit, offset int) ([]*User, error)
List returns a list of users
func (*UserRepositoryPostgres) Update ¶
func (r *UserRepositoryPostgres) Update(user *User) error
Update updates a user
func (*UserRepositoryPostgres) UpdateLastLogin ¶
func (r *UserRepositoryPostgres) UpdateLastLogin(id Id) error
UpdateLastLogin updates the last login timestamp