mbt

package module
v1.3.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.0.2

type Config struct {
	Pkg             string        // 生成的xml文件的包名
	DriverName      string        // 驱动名称。例如: mysql,postgreSQL...
	DSN             string        // 数据库连接信息。例如: "root:root@(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Local"
	MaxOpenConn     int           // 最大的并发打开连接数。例如: 这个值是5则表示==>连接池中最多有5个并发打开的连接,如果5个连接都已经打开被使用,并且应用程序需要另一个连接的话,那么应用程序将被迫等待,直到5个打开的连接其中的一个被释放并变为空闲。
	MaxIdleConn     int           // 最大的空闲连接数。注意: MaxIdleConn 应该始终小于或等于 MaxOpenConn,设置比 MaxOpenConn 更多的空闲连接数是没有意义的,因为你最多也就能拿到所有打开的连接,剩余的空闲连接依然保持的空闲。
	ConnMaxLifetime time.Duration // 连接的最大生命周期(默认值:0)。设置为0的话意味着没有最大生命周期,连接总是可重用。注意: ConnMaxLifetime 越短,从零开始创建连接的频率就越高!
	ConnMaxIdleTime time.Duration
	PrintSql        bool // 设置是否打印SQL语句
	PrintXml        bool // 是否打印 xml文件信息
	PrintWarn       bool // 是否打印警告
	TxEnable        bool // 是否启用嵌套事务(如果使用嵌套事务,则必须设置 TxEnable == true)
}

type Engine

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

func New

func New(cfg *Config) (*Engine, *sql.DB, error)

func (*Engine) Driver added in v1.2.5

func (it *Engine) Driver(driverType string) string

输入参数为: mysql,mymysql,postgres,sqlite3或者sqlite,mssql,oci8,tidb,cockroachDB 返回值为: 这些数据库的驱动地址!

func (*Engine) ID added in v1.1.0

func (it *Engine) ID(node int64) Id

生成雪花算法的ID

func (*Engine) One added in v1.1.3

func (it *Engine) One(mapperPtr interface{}) *Engine

func (*Engine) Register added in v1.1.0

func (it *Engine) Register(h H) *Engine

func (*Engine) Run added in v1.1.0

func (it *Engine) Run()

func (*Engine) Tx added in v1.2.6

func (it *Engine) Tx(mapperPtr interface{})

===================== 以下几个函数只给嵌套事务使用 =================================

type H added in v1.1.0

type H map[interface{}]interface{}

type Id added in v1.2.3

type Id int64

func (Id) Base2 added in v1.2.3

func (f Id) Base2() string

Base2 returns a string base2 of the snowflake ID

func (Id) Base32 added in v1.2.3

func (f Id) Base32() string

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func (Id) Base36 added in v1.2.3

func (f Id) Base36() string

Base36 returns a base36 string of the snowflake ID

func (Id) Base58 added in v1.2.3

func (f Id) Base58() string

Base58 returns a base58 string of the snowflake ID

func (Id) Base64 added in v1.2.3

func (f Id) Base64() string

Base64 returns a base64 string of the snowflake ID

func (Id) Bytes added in v1.2.3

func (f Id) Bytes() []byte

Bytes returns a byte slice of the snowflake ID

func (Id) Int64 added in v1.2.3

func (f Id) Int64() int64

Int64 returns an int64 of the snowflake ID

func (Id) IntBytes added in v1.2.3

func (f Id) IntBytes() [8]byte

IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.

func (Id) MarshalJSON added in v1.2.3

func (f Id) MarshalJSON() ([]byte, error)

MarshalJSON returns a json byte array string of the snowflake ID.

func (Id) Node added in v1.2.3

func (f Id) Node() int64

Node returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.

func (Id) Step added in v1.2.3

func (f Id) Step() int64

Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.

func (Id) String added in v1.2.3

func (f Id) String() string

String returns a string of the snowflake ID

func (Id) Time added in v1.2.3

func (f Id) Time() int64

Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.

func (*Id) UnmarshalJSON added in v1.2.3

func (f *Id) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.

type Propagation added in v1.2.3

type Propagation int
const (
	Required   Propagation = iota //(默认)如果当前有事务,就用当前事务。如果当前没有事务,就新建一个事务 。have tx ? join : new tx()
	Support                       //支持当前事务,如果当前没有事务,就以非事务方式执行。  have tx ? join(): session.exec()
	Mandatory                     //支持当前事务,如果当前没有事务,则返回事务嵌套错误。  have tx ? join() : return error
	News                          //新建一个全新Session开启一个全新事务,如果当前存在事务,则把当前事务挂起。 have tx ? stop old。  -> new session().new tx()
	NotSupport                    //以非事务方式执行操作,如果当前存在事务,则新建一个Session以非事务方式执行操作,并把当前事务挂起。  have tx ? stop old。 -> new session().exec()
	Never                         //以非事务方式执行操作,如果当前存在事务,则返回事务嵌套错误。    have tx ? return error: session.exec()
	Nested                        //如果当前事务存在,则在嵌套事务内执行,如嵌套事务回滚,则只会在嵌套事务内回滚,不会影响当前事务。如果当前没有事务,则进行与Required类似的操作。
)

type Session

type Session interface {
	Begin(p *Propagation) error
	Commit() error
	Rollback() error
	Id() string
	Close()
	LastPropagation() *Propagation
	// contains filtered or unexported methods
}

type Tx added in v1.0.2

type Tx func() Session

Jump to

Keyboard shortcuts

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