Documentation
¶
Index ¶
- func CheckValidTask(task interface{}) error
- func CheckValidTaskWithParameters(task interface{}, parameters ...interface{}) error
- func GetInputParametersFromTask(task interface{}) ([]reflect.Type, error)
- func GetOutputParametersFromTask(task interface{}) ([]reflect.Type, error)
- func GetTaskNameFromFunction(f interface{}) (string, error)
- func GetTaskNameFromInterface(task interface{}) (string, error)
- func LenSyncMap(m *sync.Map) int
- func MustStartPostgresContainer() (func(ctx context.Context, opts ...testcontainers.TerminateOption) error, ...)
- func SetTestDatabaseConfigEnvs(t *testing.T, port string)
- type Database
- func (d *Database) CheckTableExistance(tableName string) (bool, error)
- func (d *Database) Close() error
- func (d *Database) ConnectToDatabase(dbConfig *DatabaseConfiguration, logger *slog.Logger)
- func (d *Database) CreateCombinedIndex(tableName string, columnName1 string, columnName2 string) error
- func (d *Database) CreateIndex(tableName string, columnName string) error
- func (d *Database) CreateIndexes(tableName string, columnNames ...string) error
- func (d *Database) CreateUniqueCombinedIndex(tableName string, columnName1 string, columnName2 string) error
- func (d *Database) DropIndex(tableName string, jsonMapKey string) error
- func (d *Database) Health() map[string]string
- type DatabaseConfiguration
- type Error
- type PrettyHandler
- type PrettyHandlerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckValidTask ¶
func CheckValidTask(task interface{}) error
CheckValidTask checks if the provided task is a valid function. It returns an error if the task is nil, not a function, or if its value is nil.
func CheckValidTaskWithParameters ¶
func CheckValidTaskWithParameters(task interface{}, parameters ...interface{}) error
CheckValidTaskWithParameters checks if the provided task and parameters are valid. It checks if the task is a valid function and if the parameters match the task's input types.
func GetInputParametersFromTask ¶
GetInputParametersFromTask retrieves the input parameters of the provided task. It checks if the task is a valid function and returns its input parameter types.
func GetOutputParametersFromTask ¶
GetOutputParametersFromTask retrieves the output parameters of the provided task. It checks if the task is a valid function and returns its output parameter types.
func GetTaskNameFromFunction ¶
GetTaskNameFromFunction retrieves the name of the function from the provided task. It checks if the task is a valid function and returns its name.
func GetTaskNameFromInterface ¶
GetTaskNameFromInterface retrieves the name of the task from the provided interface. It checks if the task is a string or a function and returns its name accordingly.
func LenSyncMap ¶ added in v1.46.0
LenSyncMap returns the number of entries in a sync.Map.
func MustStartPostgresContainer ¶
func MustStartPostgresContainer() (func(ctx context.Context, opts ...testcontainers.TerminateOption) error, string, error)
MustStartPostgresContainer starts a PostgreSQL container for testing purposes. It uses the timescale/timescaledb image with PostgreSQL 17. It returns a function to terminate the container, the port on which the database is accessible, and an error if the container could not be started.
func SetTestDatabaseConfigEnvs ¶
SetTestDatabaseConfigEnvs sets the environment variables for the test database configuration. It sets the host, port, database name, username, password, schema, and table drop options for the test database.
Types ¶
type Database ¶
Database represents a service that interacts with a database.
func NewDatabase ¶
func NewDatabase(name string, dbConfig *DatabaseConfiguration, logger *slog.Logger) *Database
func NewDatabaseWithDB ¶
func NewTestDatabase ¶
func NewTestDatabase(config *DatabaseConfiguration) *Database
NewTestDatabase creates a new Database instance for testing purposes. It initializes the database with the provided configuration and the name "test_db". It returns a pointer to the new Database instance.
func (*Database) CheckTableExistance ¶
CheckTableExistance checks if a table with the specified name exists in the database. It queries the information_schema.tables to check for the existence of the table. It returns true if the table exists, false otherwise, and an error if the query fails.
func (*Database) Close ¶
Close closes the database connection. It logs a message indicating the disconnection from the specific database. If the connection is successfully closed, it returns nil. If an error occurs while closing the connection, it returns the error.
func (*Database) ConnectToDatabase ¶
func (d *Database) ConnectToDatabase(dbConfig *DatabaseConfiguration, logger *slog.Logger)
Internal function for the service creation to connect to a database. DatabaseConfiguration must contain uri, username and password. It initializes the database connection and sets the Instance field of the Database struct.
func (*Database) CreateCombinedIndex ¶
func (d *Database) CreateCombinedIndex(tableName string, columnName1 string, columnName2 string) error
CreateCombinedIndex creates a combined index on the specified columns of the specified table. It uses the PostgreSQL CREATE INDEX statement to create the index. If the index already exists, it will not create a new one. It returns an error if the index creation fails.
func (*Database) CreateIndex ¶
CreateIndex creates an index on the specified column of the specified table. It uses the PostgreSQL CREATE INDEX statement to create the index. If the index already exists, it will not create a new one. It returns an error if the index creation fails.
func (*Database) CreateIndexes ¶
CreateIndexes creates indexes on the specified columns of the specified table. It iterates over the column names and calls CreateIndex for each one. It returns an error if any of the index creations fail.
func (*Database) CreateUniqueCombinedIndex ¶
func (d *Database) CreateUniqueCombinedIndex(tableName string, columnName1 string, columnName2 string) error
CreateUniqueCombinedIndex creates a unique combined index on the specified columns of the specified table. It uses the PostgreSQL CREATE UNIQUE INDEX statement to create the index. If the index already exists, it will not create a new one. It returns an error if the index creation fails.
type DatabaseConfiguration ¶
type DatabaseConfiguration struct {
Host string
Port string
Database string
Username string
Password string
Schema string
SSLMode string
WithTableDrop bool
}
func NewDatabaseConfiguration ¶
func NewDatabaseConfiguration() (*DatabaseConfiguration, error)
NewDatabaseConfiguration creates a new DatabaseConfiguration instance. It reads the database configuration from environment variables. It returns a pointer to the new DatabaseConfiguration instance or an error if any required environment variable is not set.
func (*DatabaseConfiguration) DatabaseConnectionString ¶
func (d *DatabaseConfiguration) DatabaseConnectionString() string
type PrettyHandler ¶ added in v1.9.0
func NewPrettyHandler ¶ added in v1.9.0
func NewPrettyHandler( out io.Writer, opts PrettyHandlerOptions, ) *PrettyHandler
type PrettyHandlerOptions ¶ added in v1.9.0
type PrettyHandlerOptions struct {
SlogOpts slog.HandlerOptions
}