sqlx

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

zero-sqlx

zero-sqlx supports leader-follower read-write separation.

installation

go get github.com/chenquan/zero-sqlx

features

  • Full tracing
  • Read and write separation
  • Allows specified leader db execution
  • Adaptive circuit breaker
  • P2c algorithm

how to use it

DB:
  Leader: leader
  Followers:
    - follower1
    - follower2
type Config struct{
  DB DBConf
}

var c config.Config
conf.MustLoad(*configFile, &c, conf.UseEnv())


mysql := NewMultipleSqlConn("mysql", c.DB)
var name string
mysql.QueryRow(&name, "SELECT name FROM user WHERE id = 1")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFollowerAvailable = errors.New("no follower available")

Functions

func ForceLeaderContext added in v0.3.0

func ForceLeaderContext(ctx context.Context) context.Context

func NewMultipleSqlConn

func NewMultipleSqlConn(driverName string, conf DBConf, opts ...SqlOption) sqlx.SqlConn

NewMultipleSqlConn returns a SqlConn that supports leader-follower read/write separation.

Types

type DBConf

type DBConf struct {
	Leader    string
	Followers []string `json:",optional"`
}

type SqlOption

type SqlOption func(*sqlOptions)

func WithAccept

func WithAccept(accept func(err error) bool) SqlOption

Jump to

Keyboard shortcuts

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