sql

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

pangu-database

盘古数据库适配

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 数据库类型
	Type string `default:"sqlite3" json:"type" yaml:"type" validate:"required,oneof=mysql sqlite3 mssql oracle psql"`

	// 地址,填写服务器地址
	Addr string `default:"127.0.0.1:3306" json:"addr" validate:"required,uri"`
	// 授权,用户名
	Username string `json:"username,omitempty" yaml:"username"`
	// 授权,密码
	Password string `json:"password,omitempty" yaml:"password"`
	// 连接协议
	Protocol string `default:"tcp" json:"protocol" yaml:"protocol" validate:"required,oneof=tcp udp"`

	// 连接池配置
	Connection ConnectionConfig `json:"connection" yaml:"connection"`

	// 表名的前缀
	Suffix string `json:"suffix,omitempty" yaml:"suffix"`
	// 表名后缀
	Prefix string `json:"prefix,omitempty" yaml:"prefix"`
	// 连接的数据库名
	Schema string `json:"schema" yaml:"schema" validate:"required"`

	// 额外参数
	Parameters string `json:"parameters,omitempty" yaml:"parameters"`
	// SQLite填写数据库文件的路径
	Path string `default:"data.db" json:"path,omitempty" yaml:"path"`
	// 是否连接时使用Ping测试数据库连接是否完好
	Ping bool `default:"true" json:"ping" yaml:"ping"`
	// 是否显示SQL执行语句
	Show bool `default:"false" json:"show" yaml:"show"`
}

Config 数据库配置

type ConnectionConfig

type ConnectionConfig struct {
	// 最大打开连接数
	MaxOpen int `default:"150" yaml:"maxOpen" json:"maxOpen"`
	// 最大休眠连接数
	MaxIdle int `default:"30" yaml:"maxIdle" json:"maxIdle"`
	// 每个连接最大存活时间
	MaxLifetime time.Duration `default:"5s" yaml:"maxLifetime" json:"maxLifetime"`
}

ConnectionConfig 连接池配置

type Session

type Session struct {
	*xorm.Session
}

Session 描述一个事务

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx 事务控制

func (*Tx) Do

func (t *Tx) Do(fun txFun, fields ...gox.Field) (err error)

func (*Tx) Dop

func (t *Tx) Dop(fun txpFun, params []interface{}, fields ...gox.Field) (err error)

Jump to

Keyboard shortcuts

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