Documentation
¶
Index ¶
- func MustStartPostgresContainer() (func(ctx context.Context, opts ...testcontainers.TerminateOption) error, ...)
- func PrepareModel(modelName string, onnxFilePath string) (string, 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 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 PrepareModel ¶
PrepareModel downloads the model if it doesn't exist and returns the model path
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 ¶
func NewPrettyHandler ¶
func NewPrettyHandler( out io.Writer, opts PrettyHandlerOptions, ) *PrettyHandler
type PrettyHandlerOptions ¶
type PrettyHandlerOptions struct {
SlogOpts slog.HandlerOptions
}