Documentation
¶
Overview ¶
Package sqlx provides SQLX ORM integration for gorp framework. SQLX is a lighter alternative to GORM, suitable for scenarios requiring raw SQL. Supported drivers: mysql, postgres/postgresql/pgsql (via pgx). Configuration via config.yaml:
SQLX ORM 包,提供基于 jmoiron/sqlx 的轻量级数据库操作能力。 SQLX 是比 GORM 更轻量的选择,适用于需要原生 SQL 的场景。 支持的驱动: mysql, postgres/postgresql/pgsql(通过 pgx)。 通过 config.yaml 配置:
database: driver: mysql dsn: "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4" max_open_conns: 100 max_idle_conns: 10 conn_max_lifetime: "30m"
Eg:
// 注册 Provider app.Register(sqlx.NewProvider()) // 使用 SQLX db := c.MustMake(datacontract.SQLXKey).(*sqlx.DB) db.Select(&users, "SELECT * FROM users")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct{}
Provider registers the SQLX DB contract.
Provider 注册 SQLX 数据库契约。
func NewProvider ¶
func NewProvider() *Provider
NewProvider creates a new SQLX provider instance.
NewProvider 创建新的 SQLX Provider 实例。
func (*Provider) Boot ¶
func (p *Provider) Boot(runtimecontract.Container) error
Boot is a no-op for SQLX provider.
Boot SQLX Provider 无启动逻辑。
func (*Provider) DependsOn ¶
DependsOn returns the keys this provider depends on. SQLX provider depends on Config for database configuration.
DependsOn 返回该 provider 依赖的 key。 SQLX provider 依赖 Config 获取数据库配置。
func (*Provider) IsDefer ¶
IsDefer returns false, SQLX should be initialized immediately for DB connection.
IsDefer 返回 false,SQLX 应立即初始化以建立数据库连接。