Documentation
¶
Index ¶
- Constants
- Variables
- func Bind(app *runtime.App, db *Database) error
- func Close()
- func Gorm(ctxs ...context.Context) *gorm.DB
- func GormFrom(app *runtime.App) *gorm.DB
- func Init(cfg Config, mode string) error
- func InitWithConfig(cfg Config, mode string) error
- func InstrumentGorm(db *gorm.DB) error
- func InstrumentPgxPoolConfig(cfg *pgxpool.Config) error
- func PGX(ctxs ...context.Context) *pgxpool.Pool
- func PGXFrom(app *runtime.App) *pgxpool.Pool
- func PGXTransaction(ctx context.Context, fn func(tx pgx.Tx) error) error
- func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB
- func QuoteTablePath(path string) string
- func SchemaName(model interface{}) string
- func Table(model interface{}) string
- func TableName(model interface{}) string
- func TableOf[T any](db *Database) string
- func TablePath(model interface{}) string
- func TablePathWithName(model any, table string) string
- func TableWithName(model any, table string) string
- func Transaction(ctx context.Context, fn func(tx *gorm.DB) error) error
- type Config
- type Database
- func (db *Database) Close() error
- func (db *Database) SchemaName(model any) string
- func (db *Database) Table(model any) string
- func (db *Database) TableName(model any) string
- func (db *Database) TablePath(model any) string
- func (db *Database) TablePathWithName(model any, table string) string
- func (db *Database) TableWithName(model any, table string) string
- type Page
Constants ¶
View Source
const KeyDatabase runtime.Key = "database"
Variables ¶
Functions ¶
func InitWithConfig ¶
func InstrumentGorm ¶ added in v0.1.4
func InstrumentPgxPoolConfig ¶ added in v0.1.4
func QuoteTablePath ¶ added in v0.1.4
func SchemaName ¶ added in v0.1.4
func SchemaName(model interface{}) string
SchemaName 获取模型所在 schema。模型未声明 schema 时返回配置中的默认 schema。
func TableName ¶
func TableName(model interface{}) string
TableName 获取模型表名(含 GORM TablePrefix,不含 schema,不带 SQL 引号)。
func TablePath ¶ added in v0.1.4
func TablePath(model interface{}) string
TablePath 获取模型完整表名(含 schema,不带 SQL 引号)。
func TablePathWithName ¶ added in v0.1.4
func TableWithName ¶ added in v0.1.4
Types ¶
type Config ¶
type Config struct {
Driver string `mapstructure:"driver" yaml:"driver"`
DSN string `mapstructure:"dsn" yaml:"dsn"`
TablePrefix string `mapstructure:"table_prefix" yaml:"table_prefix"`
Schema string `mapstructure:"schema" yaml:"schema"`
MaxOpenConns int `mapstructure:"max_open_conns" yaml:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns" yaml:"max_idle_conns"`
ConnMaxLifetime int `mapstructure:"conn_max_lifetime" yaml:"conn_max_lifetime"`
LogLevel string `mapstructure:"log_level" yaml:"log_level"`
}
type Database ¶
func (*Database) SchemaName ¶ added in v0.1.4
func (*Database) TablePathWithName ¶ added in v0.1.4
Source Files
¶
Click to show internal directories.
Click to hide internal directories.