postgres

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigToken = gioc.NewToken("PostgresConfig")
View Source
var DataSourceToken = gioc.NewToken("PostgresDataSource")
View Source
var Module = gioc.NewModule("PostgresModule").
	Global().
	Provide(
		gioc.FactoryProvider(
			DataSourceToken,
			gioc.NewFactory(
				[]gioc.Token{react.ApplicationContextToken, ConfigToken},
				gioc.Singleton,
				func(injections gioc.Injections) (ds *pgxext.DataSource, err error) {
					ctx := gioc.MustResolve[context.Context](react.ApplicationContextToken, injections)
					config := gioc.MustResolve[*Config](ConfigToken, injections)

					clientConfig := &pgxext.Config{}
					if clientConfig, err = clientConfig.WithURL(config.URL); err != nil {
						return nil, err
					}

					return pgxext.NewDataSource(ctx, clientConfig)
				},
			),
			true,
		),
	)

Functions

func ForRepositories

func ForRepositories(constructors []RepositoryConstructor) *gioc.Module

func ProvideConfig added in v0.2.0

func ProvideConfig(config *Config) gioc.IProvider

Types

type Config

type Config struct {
	URL string `env:"POSTGRES_URL"`
}

type RepositoryConstructor

type RepositoryConstructor struct {
	Token       gioc.Token
	Constructor func(*pgxext.DataSource) (any, error)
}

func Repository

func Repository[T any](token gioc.Token, constructor func(*pgxext.DataSource) *T) RepositoryConstructor

Jump to

Keyboard shortcuts

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