Documentation
¶
Index ¶
- Constants
- Variables
- func AsSQLHook(constructor any) fx.Option
- func AsSQLHooks(constructors ...any) fx.Option
- func AsSQLSeed(constructor any) fx.Option
- func AsSQLSeeds(constructors ...any) fx.Option
- func NewFxSQLPrimaryDatabase(p FxSQLPrimaryDatabaseParam) *sql.DB
- func RunFxSQLMigration(command string, args ...string) fx.Option
- func RunFxSQLMigrationAndShutdown(command string, args ...string) fx.Option
- func RunFxSQLSeeds(names ...string) fx.Option
- func RunFxSQLSeedsAndShutdown(names ...string) fx.Option
- type Database
- type DatabasePool
- type FxSQLDatabasePoolParam
- type FxSQLMigratorParam
- type FxSQLPrimaryDatabaseParam
- type FxSQLSeederParam
- type Migrator
- type MigratorLogger
- type Seed
- type Seeder
Constants ¶
const ModuleName = "sql"
ModuleName is the module name.
const PrimaryDatabaseName = "primary"
Variables ¶
var FxSQLModule = fx.Module( ModuleName, fx.Provide( NewFxSQLDatabasePool, NewFxSQLPrimaryDatabase, NewFxSQLMigrator, NewFxSQLSeeder, ), )
FxSQLModule is the Fx SQL module.
Functions ¶
func AsSQLHooks ¶
AsSQLHooks registers a list of [sql.Hook] into Fx.
func AsSQLSeeds ¶
AsSQLSeeds registers a list of Seed into Fx.
func NewFxSQLPrimaryDatabase ¶ added in v1.4.0
func NewFxSQLPrimaryDatabase(p FxSQLPrimaryDatabaseParam) *sql.DB
NewFxSQLPrimaryDatabase returns the primary database.
func RunFxSQLMigration ¶
RunFxSQLMigration runs database migrations with a context.
func RunFxSQLMigrationAndShutdown ¶
RunFxSQLMigrationAndShutdown runs database migrations with a context and shutdown.
func RunFxSQLSeeds ¶
RunFxSQLSeeds runs database seeds with a context.
func RunFxSQLSeedsAndShutdown ¶ added in v1.3.0
RunFxSQLSeedsAndShutdown runs database seeds with a context and shutdown.
Types ¶
type DatabasePool ¶ added in v1.4.0
type DatabasePool struct {
// contains filtered or unexported fields
}
func NewDatabasePool ¶ added in v1.4.0
func NewDatabasePool(primary *Database, auxiliaries ...*Database) *DatabasePool
func NewFxSQLDatabasePool ¶ added in v1.4.0
func NewFxSQLDatabasePool(p FxSQLDatabasePoolParam) (*DatabasePool, error)
NewFxSQLDatabasePool returns a DatabasePool instance.
func (*DatabasePool) Auxiliaries ¶ added in v1.4.0
func (p *DatabasePool) Auxiliaries() map[string]*Database
func (*DatabasePool) Auxiliary ¶ added in v1.4.0
func (p *DatabasePool) Auxiliary(name string) (*Database, error)
func (*DatabasePool) Primary ¶ added in v1.4.0
func (p *DatabasePool) Primary() *Database
type FxSQLDatabasePoolParam ¶ added in v1.4.0
type FxSQLDatabasePoolParam struct {
fx.In
LifeCycle fx.Lifecycle
Config *config.Config
Logger *log.Logger
Hooks []yokaisql.Hook `group:"sql-hooks"`
}
FxSQLDatabasePoolParam allows injection of the required dependencies in NewFxSQLDatabasePool.
type FxSQLMigratorParam ¶
FxSQLMigratorParam allows injection of the required dependencies in NewFxSQLMigrator.
type FxSQLPrimaryDatabaseParam ¶ added in v1.4.0
type FxSQLPrimaryDatabaseParam struct {
fx.In
Pool *DatabasePool
}
FxSQLPrimaryDatabaseParam allows injection of the required dependencies in [FxSQLPrimaryDatabase].
type FxSQLSeederParam ¶
type FxSQLSeederParam struct {
fx.In
Db *sql.DB
Logger *log.Logger
Seeds []Seed `group:"sql-seeds"`
}
FxSQLSeederParam allows injection of the required dependencies in NewFxSQLSeeder.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is a database migrator based on Goose.
func NewFxSQLMigrator ¶
func NewFxSQLMigrator(p FxSQLMigratorParam) *Migrator
NewFxSQLMigrator returns a Migrator instance.
func NewMigrator ¶
NewMigrator returns a new Migrator instance.
type MigratorLogger ¶ added in v1.1.0
type MigratorLogger struct {
// contains filtered or unexported fields
}
MigratorLogger is a logger compatible with Goose.
func NewMigratorLogger ¶ added in v1.1.0
func NewMigratorLogger(logger *log.Logger, stdout bool) *MigratorLogger
NewMigratorLogger returns a new MigratorLogger instance.
func (*MigratorLogger) Fatalf ¶ added in v1.1.0
func (l *MigratorLogger) Fatalf(format string, v ...interface{})
Fatalf logs with fatal level, and prints to stdout if configured to do so.
func (*MigratorLogger) Printf ¶ added in v1.1.0
func (l *MigratorLogger) Printf(format string, v ...interface{})
Printf logs with info level, and prints to stdout if configured to do so.
type Seeder ¶
type Seeder struct {
// contains filtered or unexported fields
}
Seeder is a database seeder.
func NewFxSQLSeeder ¶
func NewFxSQLSeeder(p FxSQLSeederParam) *Seeder
NewFxSQLSeeder returns a Seeder instance.