Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupDb ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.