Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlx

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 1

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

Boot is a no-op for SQLX provider.

Boot SQLX Provider 无启动逻辑。

func (*Provider) DependsOn

func (p *Provider) DependsOn() []string

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

func (p *Provider) IsDefer() bool

IsDefer returns false, SQLX should be initialized immediately for DB connection.

IsDefer 返回 false,SQLX 应立即初始化以建立数据库连接。

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name "orm.sqlx".

Name 返回 Provider 名称 "orm.sqlx"。

func (*Provider) Provides

func (p *Provider) Provides() []string

Provides returns the SQLX contract key.

Provides 返回 SQLX 契约键。

func (*Provider) Register

func (p *Provider) Register(c runtimecontract.Container) error

Register binds the SQLX DB factory to the container. Core logic: Parse config, normalize driver, open connection, apply pool settings.

Register 将 SQLX 数据库工厂绑定到容器。 核心逻辑:解析配置、标准化驱动名称、打开连接、应用连接池设置。

Jump to

Keyboard shortcuts

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