component

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package component provides PostgreSQL lifecycle integration for bootstrap.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Component

func Component() bootstrap.IComponent

Component wraps LoadFromEnv as a bootstrap.IComponent. Init calls LoadFromEnv; Close closes the default connection pool.

This component only establishes the connection pool. Schema migration should be registered as a separate bootstrap.Func step immediately after:

AddParallel(component.Component()).
Add(bootstrap.Func("migrate", func() error {
    db.AutoMigrate(...)
    return nil
}, nil))
Example

ExampleComponent shows how Component() is used in a bootstrap registration chain. It reads PostgreSQL connection parameters from env during Init():

db.host, db.port, db.name, db.schema, db.username, db.password, db.query.exec.mode

NewPostgres performs an eager connectivity check — if the database is unreachable Init() returns an error immediately so bootstrap aborts startup.

Schema migration should be registered as a separate step immediately after:

bootstrap.New(envComp.Component(...), logComp.Component()).
    Add(dbComp.Component()).
    Add(bootstrap.Func("migrate", func() error {
        db.AutoMigrate(...)
        return nil
    }, nil)).
    Run()

postgres.InitDefault uses sync.Once — only the first Init call per process takes effect. In this example the database is unreachable (testdata points to 127.0.0.1:1) so Init returns an error.

package main

import (
	"fmt"

	dbComp "github.com/phcp-tech/common-library-golang/dbsqlc/postgres/component"
)

func main() {
	c := dbComp.Component()
	fmt.Println(c != nil)
}
Output:
true

Types

This section is empty.

Jump to

Keyboard shortcuts

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