Documentation ¶
Index ¶
- Variables
- func NewDB(URL string, dopts *Options) (*bun.DB, error)
- func SetPool(sqldb *sql.DB, opts *Options)
- type Callback
- type Option
- func WithConnMaxIdleTimeMS(ConnMaxIdleTimeMS int) Option
- func WithConnMaxLifetimeMS(ConnMaxLifetimeMS int) Option
- func WithDiscardUnknownColumns() Option
- func WithInstance(cli *bun.DB) Option
- func WithLogger(logger logrus.FieldLogger) Option
- func WithMaxIdleConns(MaxIdleConns int) Option
- func WithMaxOpenConns(MaxOpenConns int) Option
- func WithParallelCallback() Option
- func WithQueryTimeoutMS(QueryTimeout int) Option
- func WithURL(URL string) Option
- type Options
- type Proxy
- func (proxy *Proxy) Init(opts ...Option) error
- func (proxy *Proxy) IsOk() bool
- func (proxy *Proxy) NewCtx() (ctx context.Context, cancel context.CancelFunc)
- func (proxy *Proxy) Regist(cb Callback) error
- func (proxy *Proxy) SetConnect(cli *bun.DB, parallelcallback bool) error
- func (proxy *Proxy) SetQueryTimeout(timeout time.Duration)
Constants ¶
This section is empty.
Variables ¶
var DB = New()
DB 默认的数据库代理对象
var DefaultOpts = Options{
URL: "sqlite://:memory:?cache=shared",
}
var ErrProxyAllreadySettedUniversalClient = errors.New("代理不能重复设置客户端对象")
ErrProxyAllreadySettedUniversalClient 代理已经设置过redis客户端对象
var ErrProxyNotYetSettedUniversalClient = errors.New("代理还未设置客户端对象")
ErrProxyNotYetSettedUniversalClient 代理还未设置客户端对象
var ErrUnSupportSchema = errors.New("未支持的数据库管理服务类型")
ErrUnSupportSchema 未支持的数据库管理服务类型
var ErrUnknownClientType = errors.New("未知的redis客户端类型")
ErrUnknownClientType 未知的redis客户端类型
Functions ¶
Types ¶
type Option ¶
type Option interface {
Apply(*Options)
}
Option configures how we set up the connection.
func WithConnMaxIdleTimeMS ¶
WithConnMaxIdleTimeMS 设置连接池的最大空闲连接超时时间,单位ms
func WithConnMaxLifetimeMS ¶
WithConnMaxLifetimeMS 设置连接池的最大连接超时时间,单位ms
func WithDiscardUnknownColumns ¶
func WithDiscardUnknownColumns() Option
WithDiscardUnknownColumns 设置当有未知列时不报错
func WithInstance ¶ added in v0.0.7
func WithLogger ¶ added in v0.0.5
func WithLogger(logger logrus.FieldLogger) Option
WithLogger 用于添加logger方便debug
func WithMaxIdleConns ¶
WithMaxIdleConns 设置连接池的最大空闲连接数
func WithParallelCallback ¶
func WithParallelCallback() Option
WithParallelCallback 设置初始化后回调并行执行而非串行执行
func WithQueryTimeoutMS ¶ added in v0.0.5
WithQueryTimeoutMS 设置最大请求超时,单位ms
type Options ¶
type Options struct { URL string // 只在Init方法中生效 Cli *bun.DB // 只在Init方法中生效 Parallelcallback bool // 只在Init方法中生效 QueryTimeout time.Duration // 只在Init方法中生效 MaxOpenConns int ConnMaxLifetime time.Duration MaxIdleConns int ConnMaxIdleTime time.Duration DiscardUnknownColumns bool Logger logrus.FieldLogger }
Option 设置key行为的选项 @attribute MaxTTL time.Duration 为0则不设置过期 @attribute AutoRefresh string 需要为crontab格式的字符串,否则不会自动定时刷新
type Proxy ¶
Proxy bun客户端的代理
func (*Proxy) NewCtx ¶
func (proxy *Proxy) NewCtx() (ctx context.Context, cancel context.CancelFunc)
NewCtx 根据注册的超时时间构造一个上下文
func (*Proxy) SetConnect ¶
SetConnect 设置连接的客户端 @params cli *bun.DB bun的DB对象
func (*Proxy) SetQueryTimeout ¶ added in v0.0.6
SetQueryTimeout 设置连接的请求超时 @params timeout time.Duration