core

package
v0.0.0-...-fd14d52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupDb

func SetupDb(ctx context.Context, migrationFiles fs.FS) (*bun.DB, error)

SetupDb initializes and configures a database connection using environment variables. It creates a connection pool, runs migrations, and returns a *bun.DB instance.

Parameters:

  • ctx: A context.Context for managing the database operations.
  • migrationFiles: An fs.FS containing the migration files to be applied.

Returns:

  • *bun.DB: A pointer to the configured bun.DB instance.
  • error: An error if any step in the setup process fails.

The function performs the following steps: 1. Creates a database configuration from environment variables. 2. Parses the configuration to create a connection pool. 3. Opens a SQL database from the pool. 4. Initializes a bun.DB instance with the SQL database. 5. Pings the database to ensure connectivity. 6. Runs database migrations using the provided migration files.

If any step fails, it returns an error with a descriptive message.

Types

type DbConfig

type DbConfig struct {
	// contains filtered or unexported fields
}

func (*DbConfig) ConnectionString

func (config *DbConfig) ConnectionString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL