db

package
v1.2.26 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 200

Documentation

Index

Constants

View Source
const (
	// DriverMysql is a const value of mysql driver.
	DriverMysql = "mysql"
	// DriverSqlite is a const value of sqlite driver.
	DriverSqlite = "sqlite"
	// DriverPostgresql is a const value of postgresql driver.
	DriverPostgresql = "postgresql"
	// DriverMssql is a const value of mssql driver.
	DriverMssql = "mssql"
	// DriverOceanBase is a const value of oceanbase driver.
	DriverOceanBase = "oceanbase"
)
View Source
const (
	INSERT = 0
	DELETE = 1
	UPDATE = 2
	QUERY  = 3
)

Variables

View Source
var (
	// StringTypeList is a DatabaseType list of string.
	StringTypeList = []DatabaseType{Date, Time, Year, Datetime, Timestamptz, Timestamp, Timetz,
		Varchar, Char, Mediumtext, Longtext, Tinytext,
		Text, JSON, Blob, Tinyblob, Mediumblob, Longblob,
		Interval, Point, Bpchar,
		Line, Lseg, Box, Path, Polygon, Circle, Cidr, Inet, Macaddr, Character, Varyingcharacter,
		Nchar, Nativecharacter, Nvarchar, Clob, Binary, Varbinary, Enum, Set, Geometry, Multilinestring,
		Multipolygon, Linestring, Multipoint, Geometrycollection, Name, UUID, Timestamptz,
		Name, UUID, Inet}

	// BoolTypeList is a DatabaseType list of bool.
	BoolTypeList = []DatabaseType{Bool, Boolean}

	// IntTypeList is a DatabaseType list of integer.
	IntTypeList = []DatabaseType{Int4, Int2, Int8,
		Int,
		Tinyint,
		Mediumint,
		Smallint,
		Smallserial, Serial, Bigserial,
		Integer,
		Bigint}

	// FloatTypeList is a DatabaseType list of float.
	FloatTypeList = []DatabaseType{Float, Float4, Float8, Double, Real, Doubleprecision}

	// UintTypeList is a DatabaseType list of uint.
	UintTypeList = []DatabaseType{Decimal, Bit, Money, Numeric}
)
View Source
var SQLPool = sync.Pool{
	New: func() interface{} {
		return &SQL{
			SQLComponent: dialect.SQLComponent{
				Fields:     make([]string, 0),
				TableName:  "",
				Args:       make([]interface{}, 0),
				Wheres:     make([]dialect.Where, 0),
				Leftjoins:  make([]dialect.Join, 0),
				UpdateRaws: make([]dialect.RawUpdate, 0),
				WhereRaws:  "",
				Order:      "",
				Group:      "",
				Limit:      "",
			},
			diver:   nil,
			dialect: nil,
		}
	},
}

SQLPool is a object pool of SQL.

Functions

func CheckError added in v1.2.7

func CheckError(err error, t int) bool

func CommonBeginTxWithLevel added in v1.1.0

func CommonBeginTxWithLevel(db *sql.DB, level sql.IsolationLevel) *sql.Tx

CommonBeginTxWithLevel starts a transaction with given transaction isolation level and db connection.

func CommonExec

func CommonExec(db *sql.DB, query string, args ...interface{}) (sql.Result, error)

CommonExec is a common method of exec.

func CommonExecWithTx added in v1.1.0

func CommonExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

CommonExecWithTx is a common method of exec.

func CommonQuery

func CommonQuery(db *sql.DB, query string, args ...interface{}) ([]map[string]interface{}, error)

CommonQuery is a common method of query.

func CommonQueryWithTx added in v1.1.0

func CommonQueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

CommonQueryWithTx is a common method of query.

func Contains

func Contains(v DatabaseType, a []DatabaseType) bool

Contains check the given DatabaseType is in the list or not.

func GetAggregationExpression added in v1.2.3

func GetAggregationExpression(driver, field, headField, delimiter string) string

func RecycleSQL added in v1.0.8

func RecycleSQL(sql *SQL)

RecycleSQL clear the SQL and put into the pool.

func SetColVarType

func SetColVarType(colVar *[]interface{}, i int, typeName string)

SetColVarType set the column type.

func SetResultValue

func SetResultValue(result *map[string]interface{}, index string, colVar interface{}, typeName string)

SetResultValue set the result value.

Types

type Base added in v1.1.6

type Base struct {
	DbList  map[string]*sql.DB
	Once    sync.Once
	Configs config.DatabaseList
}

Base is a common Connection.

func (*Base) Close added in v1.1.6

func (db *Base) Close() []error

Close implements the method Connection.Close.

func (*Base) CreateDB added in v1.2.15

func (db *Base) CreateDB(name string, beans ...interface{}) error

func (*Base) GetConfig added in v1.2.15

func (db *Base) GetConfig(name string) config.Database

func (*Base) GetDB added in v1.1.6

func (db *Base) GetDB(key string) *sql.DB

GetDB implements the method Connection.GetDB.

type Connection

type Connection interface {
	// Query is the query method of sql.
	Query(query string, args ...interface{}) ([]map[string]interface{}, error)

	// Exec is the exec method of sql.
	Exec(query string, args ...interface{}) (sql.Result, error)

	// QueryWithConnection is the query method with given connection of sql.
	QueryWithConnection(conn, query string, args ...interface{}) ([]map[string]interface{}, error)
	QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)
	QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

	// ExecWithConnection is the exec method with given connection of sql.
	ExecWithConnection(conn, query string, args ...interface{}) (sql.Result, error)
	ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)
	ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

	BeginTxWithReadUncommitted() *sql.Tx
	BeginTxWithReadCommitted() *sql.Tx
	BeginTxWithRepeatableRead() *sql.Tx
	BeginTx() *sql.Tx
	BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

	BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx
	BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx
	BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx
	BeginTxAndConnection(conn string) *sql.Tx
	BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

	// InitDB initialize the database connections.
	InitDB(cfg map[string]config.Database) Connection

	// GetName get the connection name.
	Name() string

	Close() []error

	GetDelimiter() string
	GetDelimiter2() string
	GetDelimiters() []string

	GetDB(key string) *sql.DB

	GetConfig(name string) config.Database

	CreateDB(name string, beans ...interface{}) error
}

Connection is a connection handler of database.

func GetConnection

func GetConnection(srvs service.List) Connection

func GetConnectionByDriver

func GetConnectionByDriver(driver string) Connection

GetConnectionByDriver return the Connection by given driver name.

func GetConnectionFromService added in v1.1.2

func GetConnectionFromService(srv interface{}) Connection

type DatabaseType

type DatabaseType string

DatabaseType is the database field type.

const (
	Int       DatabaseType = "INT"
	Tinyint   DatabaseType = "TINYINT"
	Mediumint DatabaseType = "MEDIUMINT"
	Smallint  DatabaseType = "SMALLINT"
	Bigint    DatabaseType = "BIGINT"
	Bit       DatabaseType = "BIT"
	Int8      DatabaseType = "INT8"
	Int4      DatabaseType = "INT4"
	Int2      DatabaseType = "INT2"

	Integer     DatabaseType = "INTEGER"
	Numeric     DatabaseType = "NUMERIC"
	Smallserial DatabaseType = "SMALLSERIAL"
	Serial      DatabaseType = "SERIAL"
	Bigserial   DatabaseType = "BIGSERIAL"
	Money       DatabaseType = "MONEY"

	Real    DatabaseType = "REAL"
	Float   DatabaseType = "FLOAT"
	Float4  DatabaseType = "FLOAT4"
	Float8  DatabaseType = "FLOAT8"
	Double  DatabaseType = "DOUBLE"
	Decimal DatabaseType = "DECIMAL"

	Doubleprecision DatabaseType = "DOUBLEPRECISION"

	Date      DatabaseType = "DATE"
	Time      DatabaseType = "TIME"
	Year      DatabaseType = "YEAR"
	Datetime  DatabaseType = "DATETIME"
	Timestamp DatabaseType = "TIMESTAMP"

	Text       DatabaseType = "TEXT"
	Longtext   DatabaseType = "LONGTEXT"
	Mediumtext DatabaseType = "MEDIUMTEXT"
	Tinytext   DatabaseType = "TINYTEXT"

	Varchar DatabaseType = "VARCHAR"
	Char    DatabaseType = "CHAR"
	Bpchar  DatabaseType = "BPCHAR"
	JSON    DatabaseType = "JSON"

	Blob       DatabaseType = "BLOB"
	Tinyblob   DatabaseType = "TINYBLOB"
	Mediumblob DatabaseType = "MEDIUMBLOB"
	Longblob   DatabaseType = "LONGBLOB"

	Interval DatabaseType = "INTERVAL"
	Boolean  DatabaseType = "BOOLEAN"
	Bool     DatabaseType = "BOOL"

	Point   DatabaseType = "POINT"
	Line    DatabaseType = "LINE"
	Lseg    DatabaseType = "LSEG"
	Box     DatabaseType = "BOX"
	Path    DatabaseType = "PATH"
	Polygon DatabaseType = "POLYGON"
	Circle  DatabaseType = "CIRCLE"

	Cidr    DatabaseType = "CIDR"
	Inet    DatabaseType = "INET"
	Macaddr DatabaseType = "MACADDR"

	Character        DatabaseType = "CHARACTER"
	Varyingcharacter DatabaseType = "VARYINGCHARACTER"
	Nchar            DatabaseType = "NCHAR"
	Nativecharacter  DatabaseType = "NATIVECHARACTER"
	Nvarchar         DatabaseType = "NVARCHAR"
	Clob             DatabaseType = "CLOB"

	Binary    DatabaseType = "BINARY"
	Varbinary DatabaseType = "VARBINARY"
	Enum      DatabaseType = "ENUM"
	Set       DatabaseType = "SET"

	Geometry DatabaseType = "GEOMETRY"

	Multilinestring    DatabaseType = "MULTILINESTRING"
	Multipolygon       DatabaseType = "MULTIPOLYGON"
	Linestring         DatabaseType = "LINESTRING"
	Multipoint         DatabaseType = "MULTIPOINT"
	Geometrycollection DatabaseType = "GEOMETRYCOLLECTION"

	Name DatabaseType = "NAME"
	UUID DatabaseType = "UUID"

	Timestamptz DatabaseType = "TIMESTAMPTZ"
	Timetz      DatabaseType = "TIMETZ"
)

func DT

func DT(s string) DatabaseType

DT turn the string value into DatabaseType.

func GetDTAndCheck

func GetDTAndCheck(s string) DatabaseType

GetDTAndCheck check the DatabaseType.

type H

type H map[string]interface{}

H is a shorthand of map.

type Mssql

type Mssql struct {
	Base
}

Mssql is a Connection of mssql.

func GetMssqlDB

func GetMssqlDB() *Mssql

GetMssqlDB return the global mssql connection.

func (*Mssql) BeginTx added in v1.1.0

func (db *Mssql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Mssql) BeginTxAndConnection added in v1.1.0

func (db *Mssql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Mssql) BeginTxWithLevel added in v1.1.0

func (db *Mssql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Mssql) BeginTxWithLevelAndConnection added in v1.1.0

func (db *Mssql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Mssql) BeginTxWithReadCommitted added in v1.1.0

func (db *Mssql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Mssql) BeginTxWithReadCommittedAndConnection added in v1.1.0

func (db *Mssql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Mssql) BeginTxWithReadUncommitted added in v1.1.0

func (db *Mssql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Mssql) BeginTxWithReadUncommittedAndConnection added in v1.1.0

func (db *Mssql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Mssql) BeginTxWithRepeatableRead added in v1.1.0

func (db *Mssql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Mssql) BeginTxWithRepeatableReadAndConnection added in v1.1.0

func (db *Mssql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Mssql) Exec

func (db *Mssql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Mssql) ExecWith added in v1.2.18

func (db *Mssql) ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

func (*Mssql) ExecWithConnection

func (db *Mssql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Mssql) ExecWithTx added in v1.1.0

func (db *Mssql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Mssql) GetDelimiter

func (db *Mssql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Mssql) GetDelimiter2 added in v1.2.18

func (db *Mssql) GetDelimiter2() string

GetDelimiter2 implements the method Connection.GetDelimiter2.

func (*Mssql) GetDelimiters added in v1.2.18

func (db *Mssql) GetDelimiters() []string

GetDelimiters implements the method Connection.GetDelimiters.

func (*Mssql) InitDB

func (db *Mssql) InitDB(cfgs map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Mssql) Name added in v1.1.2

func (db *Mssql) Name() string

Name implements the method Connection.Name.

func (*Mssql) Query

func (db *Mssql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Mssql) QueryWith added in v1.2.18

func (db *Mssql) QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

func (*Mssql) QueryWithConnection

func (db *Mssql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Mssql) QueryWithTx added in v1.1.0

func (db *Mssql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type Mysql

type Mysql struct {
	Base
}

Mysql is a Connection of mysql.

func GetMysqlDB

func GetMysqlDB() *Mysql

GetMysqlDB return the global mysql connection.

func (*Mysql) BeginTx added in v1.1.0

func (db *Mysql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Mysql) BeginTxAndConnection added in v1.1.0

func (db *Mysql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Mysql) BeginTxWithLevel added in v1.1.0

func (db *Mysql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Mysql) BeginTxWithLevelAndConnection added in v1.1.0

func (db *Mysql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Mysql) BeginTxWithReadCommitted added in v1.1.0

func (db *Mysql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Mysql) BeginTxWithReadCommittedAndConnection added in v1.1.0

func (db *Mysql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Mysql) BeginTxWithReadUncommitted added in v1.1.0

func (db *Mysql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Mysql) BeginTxWithReadUncommittedAndConnection added in v1.1.0

func (db *Mysql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Mysql) BeginTxWithRepeatableRead added in v1.1.0

func (db *Mysql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Mysql) BeginTxWithRepeatableReadAndConnection added in v1.1.0

func (db *Mysql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Mysql) Exec

func (db *Mysql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Mysql) ExecWith added in v1.2.18

func (db *Mysql) ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

func (*Mysql) ExecWithConnection

func (db *Mysql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Mysql) ExecWithTx added in v1.1.0

func (db *Mysql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Mysql) GetDelimiter

func (db *Mysql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Mysql) GetDelimiter2 added in v1.2.18

func (db *Mysql) GetDelimiter2() string

GetDelimiter2 implements the method Connection.GetDelimiter2.

func (*Mysql) GetDelimiters added in v1.2.18

func (db *Mysql) GetDelimiters() []string

GetDelimiters implements the method Connection.GetDelimiters.

func (*Mysql) InitDB

func (db *Mysql) InitDB(cfgs map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Mysql) Name added in v1.1.2

func (db *Mysql) Name() string

Name implements the method Connection.Name.

func (*Mysql) Query

func (db *Mysql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Mysql) QueryWith added in v1.2.18

func (db *Mysql) QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

func (*Mysql) QueryWithConnection

func (db *Mysql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Mysql) QueryWithTx added in v1.1.0

func (db *Mysql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type OceanBase added in v1.2.25

type OceanBase struct {
	Base
}

OceanBase is a Connection of OceanBase.

func GetOceanBaseDB added in v1.2.25

func GetOceanBaseDB() *OceanBase

GetOceanBaseDB return the global OceanBase connection.

func (*OceanBase) BeginTx added in v1.2.25

func (db *OceanBase) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*OceanBase) BeginTxAndConnection added in v1.2.25

func (db *OceanBase) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*OceanBase) BeginTxWithLevel added in v1.2.25

func (db *OceanBase) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*OceanBase) BeginTxWithLevelAndConnection added in v1.2.25

func (db *OceanBase) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*OceanBase) BeginTxWithReadCommitted added in v1.2.25

func (db *OceanBase) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*OceanBase) BeginTxWithReadCommittedAndConnection added in v1.2.25

func (db *OceanBase) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*OceanBase) BeginTxWithReadUncommitted added in v1.2.25

func (db *OceanBase) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*OceanBase) BeginTxWithReadUncommittedAndConnection added in v1.2.25

func (db *OceanBase) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*OceanBase) BeginTxWithRepeatableRead added in v1.2.25

func (db *OceanBase) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*OceanBase) BeginTxWithRepeatableReadAndConnection added in v1.2.25

func (db *OceanBase) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*OceanBase) Exec added in v1.2.25

func (db *OceanBase) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*OceanBase) ExecWith added in v1.2.25

func (db *OceanBase) ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

func (*OceanBase) ExecWithConnection added in v1.2.25

func (db *OceanBase) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*OceanBase) ExecWithTx added in v1.2.25

func (db *OceanBase) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*OceanBase) GetDelimiter added in v1.2.25

func (db *OceanBase) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*OceanBase) GetDelimiter2 added in v1.2.25

func (db *OceanBase) GetDelimiter2() string

GetDelimiter2 implements the method Connection.GetDelimiter2.

func (*OceanBase) GetDelimiters added in v1.2.25

func (db *OceanBase) GetDelimiters() []string

GetDelimiters implements the method Connection.GetDelimiters.

func (*OceanBase) InitDB added in v1.2.25

func (db *OceanBase) InitDB(cfgs map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*OceanBase) Name added in v1.2.25

func (db *OceanBase) Name() string

Name implements the method Connection.Name.

func (*OceanBase) Query added in v1.2.25

func (db *OceanBase) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*OceanBase) QueryWith added in v1.2.25

func (db *OceanBase) QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

func (*OceanBase) QueryWithConnection added in v1.2.25

func (db *OceanBase) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*OceanBase) QueryWithTx added in v1.2.25

func (db *OceanBase) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type Postgresql

type Postgresql struct {
	Base
}

Postgresql is a Connection of postgresql.

func GetPostgresqlDB

func GetPostgresqlDB() *Postgresql

GetPostgresqlDB return the global postgresql connection.

func (*Postgresql) BeginTx added in v1.1.0

func (db *Postgresql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Postgresql) BeginTxAndConnection added in v1.1.0

func (db *Postgresql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Postgresql) BeginTxWithLevel added in v1.1.0

func (db *Postgresql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Postgresql) BeginTxWithLevelAndConnection added in v1.1.0

func (db *Postgresql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Postgresql) BeginTxWithReadCommitted added in v1.1.0

func (db *Postgresql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Postgresql) BeginTxWithReadCommittedAndConnection added in v1.1.0

func (db *Postgresql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Postgresql) BeginTxWithReadUncommitted added in v1.1.0

func (db *Postgresql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Postgresql) BeginTxWithReadUncommittedAndConnection added in v1.1.0

func (db *Postgresql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Postgresql) BeginTxWithRepeatableRead added in v1.1.0

func (db *Postgresql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Postgresql) BeginTxWithRepeatableReadAndConnection added in v1.1.0

func (db *Postgresql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Postgresql) Exec

func (db *Postgresql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Postgresql) ExecWith added in v1.2.18

func (db *Postgresql) ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

func (*Postgresql) ExecWithConnection

func (db *Postgresql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Postgresql) ExecWithTx added in v1.1.0

func (db *Postgresql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Postgresql) GetDelimiter

func (db *Postgresql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Postgresql) GetDelimiter2 added in v1.2.18

func (db *Postgresql) GetDelimiter2() string

GetDelimiter2 implements the method Connection.GetDelimiter2.

func (*Postgresql) GetDelimiters added in v1.2.18

func (db *Postgresql) GetDelimiters() []string

GetDelimiters implements the method Connection.GetDelimiters.

func (*Postgresql) InitDB

func (db *Postgresql) InitDB(cfgList map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Postgresql) Name added in v1.1.2

func (db *Postgresql) Name() string

Name implements the method Connection.Name.

func (*Postgresql) Query

func (db *Postgresql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Postgresql) QueryWith added in v1.2.18

func (db *Postgresql) QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

func (*Postgresql) QueryWithConnection

func (db *Postgresql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Postgresql) QueryWithTx added in v1.1.0

func (db *Postgresql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type SQL added in v1.0.8

type SQL struct {
	dialect.SQLComponent
	// contains filtered or unexported fields
}

SQL wraps the Connection and driver dialect methods.

func Table

func Table(table string) *SQL

TableName return a SQL with given table and default connection.

func WithDriver

func WithDriver(conn Connection) *SQL

WithDriver return a SQL with given driver.

func WithDriverAndConnection

func WithDriverAndConnection(connName string, conn Connection) *SQL

WithDriverAndConnection return a SQL with given driver and connection name.

func (*SQL) All added in v1.0.8

func (sql *SQL) All() ([]map[string]interface{}, error)

All query all the result and return.

func (*SQL) Avg added in v1.1.0

func (sql *SQL) Avg(field string) (interface{}, error)

Avg find the average value of given field.

func (*SQL) Count added in v1.0.8

func (sql *SQL) Count() (int64, error)

Count query the count of query results.

func (*SQL) Delete added in v1.0.8

func (sql *SQL) Delete() error

Delete exec the delete method.

func (*SQL) Exec added in v1.0.8

func (sql *SQL) Exec() (int64, error)

Exec exec the exec method.

func (*SQL) Find added in v1.0.8

func (sql *SQL) Find(arg interface{}) (map[string]interface{}, error)

Find query the sql result with given id assuming that primary key name is "id".

func (*SQL) First added in v1.0.8

func (sql *SQL) First() (map[string]interface{}, error)

First query the result and return the first row.

func (*SQL) GroupBy added in v1.1.6

func (sql *SQL) GroupBy(fields ...string) *SQL

func (*SQL) GroupByRaw added in v1.2.6

func (sql *SQL) GroupByRaw(group string) *SQL

GroupByRaw set group by.

func (*SQL) Insert added in v1.0.8

func (sql *SQL) Insert(values dialect.H) (int64, error)

Insert exec the insert method of given key/value pairs.

func (*SQL) LeftJoin added in v1.0.8

func (sql *SQL) LeftJoin(table string, fieldA string, operation string, fieldB string) *SQL

LeftJoin add a left join info.

func (*SQL) Max added in v1.1.0

func (sql *SQL) Max(field string) (interface{}, error)

Max find the maximal value of given field.

func (*SQL) Min added in v1.1.0

func (sql *SQL) Min(field string) (interface{}, error)

Min find the minimal value of given field.

func (*SQL) OrderBy added in v1.0.8

func (sql *SQL) OrderBy(fields ...string) *SQL

OrderBy set order fields.

func (*SQL) OrderByRaw added in v1.2.6

func (sql *SQL) OrderByRaw(order string) *SQL

OrderByRaw set order by.

func (*SQL) Select added in v1.0.8

func (sql *SQL) Select(fields ...string) *SQL

Select set select fields.

func (*SQL) ShowColumns added in v1.0.8

func (sql *SQL) ShowColumns() ([]map[string]interface{}, error)

ShowColumns show columns info.

func (*SQL) ShowColumnsWithComment added in v1.2.25

func (sql *SQL) ShowColumnsWithComment(database string) ([]map[string]interface{}, error)

ShowColumnsWithComment show columns info.

func (*SQL) ShowTables added in v1.0.8

func (sql *SQL) ShowTables() ([]string, error)

ShowTables show table info.

func (*SQL) Skip added in v1.0.8

func (sql *SQL) Skip(offset int) *SQL

Skip set offset value.

func (*SQL) Sum added in v1.1.0

func (sql *SQL) Sum(field string) (float64, error)

Sum sum the value of given field.

func (*SQL) Table added in v1.0.8

func (sql *SQL) Table(table string) *SQL

TableName set table of SQL.

func (*SQL) Take added in v1.0.8

func (sql *SQL) Take(take int) *SQL

Take set limit value.

func (*SQL) Update added in v1.0.8

func (sql *SQL) Update(values dialect.H) (int64, error)

Update exec the update method of given key/value pairs.

func (*SQL) UpdateRaw added in v1.0.8

func (sql *SQL) UpdateRaw(raw string, args ...interface{}) *SQL

UpdateRaw set UpdateRaw.

func (*SQL) Where added in v1.0.8

func (sql *SQL) Where(field string, operation string, arg interface{}) *SQL

Where add the where operation and argument value.

func (*SQL) WhereIn added in v1.0.8

func (sql *SQL) WhereIn(field string, arg []interface{}) *SQL

WhereIn add the where operation of "in" and argument values.

func (*SQL) WhereNotIn added in v1.0.8

func (sql *SQL) WhereNotIn(field string, arg []interface{}) *SQL

WhereNotIn add the where operation of "not in" and argument values.

func (*SQL) WhereRaw added in v1.0.8

func (sql *SQL) WhereRaw(raw string, args ...interface{}) *SQL

WhereRaw set WhereRaws and arguments.

func (*SQL) WithConnection added in v1.0.8

func (sql *SQL) WithConnection(conn string) *SQL

WithConnection set the connection name of SQL.

func (*SQL) WithDriver added in v1.1.2

func (sql *SQL) WithDriver(conn Connection) *SQL

WithDriver return a SQL with given driver.

func (*SQL) WithTransaction added in v1.1.0

func (sql *SQL) WithTransaction(fn TxFn) (res map[string]interface{}, err error)

WithTransaction call the callback function within the transaction and catch the error.

func (*SQL) WithTransactionByLevel added in v1.1.0

func (sql *SQL) WithTransactionByLevel(level dbsql.IsolationLevel, fn TxFn) (res map[string]interface{}, err error)

WithTransactionByLevel call the callback function within the transaction of given transaction level and catch the error.

func (*SQL) WithTx added in v1.1.0

func (sql *SQL) WithTx(tx *dbsql.Tx) *SQL

WithTx set the database transaction object of SQL.

type SQLTx added in v1.0.8

type SQLTx struct {
	Tx *sql.Tx
}

SQLTx is an in-progress database transaction.

type Sqlite

type Sqlite struct {
	Base
}

Sqlite is a Connection of sqlite.

func GetSqliteDB

func GetSqliteDB() *Sqlite

GetSqliteDB return the global sqlite connection.

func (*Sqlite) BeginTx added in v1.1.0

func (db *Sqlite) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Sqlite) BeginTxAndConnection added in v1.1.0

func (db *Sqlite) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Sqlite) BeginTxWithLevel added in v1.1.0

func (db *Sqlite) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Sqlite) BeginTxWithLevelAndConnection added in v1.1.0

func (db *Sqlite) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Sqlite) BeginTxWithReadCommitted added in v1.1.0

func (db *Sqlite) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Sqlite) BeginTxWithReadCommittedAndConnection added in v1.1.0

func (db *Sqlite) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Sqlite) BeginTxWithReadUncommitted added in v1.1.0

func (db *Sqlite) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Sqlite) BeginTxWithReadUncommittedAndConnection added in v1.1.0

func (db *Sqlite) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Sqlite) BeginTxWithRepeatableRead added in v1.1.0

func (db *Sqlite) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Sqlite) BeginTxWithRepeatableReadAndConnection added in v1.1.0

func (db *Sqlite) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Sqlite) Exec

func (db *Sqlite) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Sqlite) ExecWith added in v1.2.18

func (db *Sqlite) ExecWith(tx *sql.Tx, conn, query string, args ...interface{}) (sql.Result, error)

func (*Sqlite) ExecWithConnection

func (db *Sqlite) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Sqlite) ExecWithTx added in v1.1.0

func (db *Sqlite) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Sqlite) GetDelimiter

func (db *Sqlite) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Sqlite) GetDelimiter2 added in v1.2.18

func (db *Sqlite) GetDelimiter2() string

GetDelimiter2 implements the method Connection.GetDelimiter2.

func (*Sqlite) GetDelimiters added in v1.2.18

func (db *Sqlite) GetDelimiters() []string

GetDelimiters implements the method Connection.GetDelimiters.

func (*Sqlite) InitDB

func (db *Sqlite) InitDB(cfgList map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Sqlite) Name added in v1.1.2

func (db *Sqlite) Name() string

Name implements the method Connection.Name.

func (*Sqlite) Query

func (db *Sqlite) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Sqlite) QueryWith added in v1.2.18

func (db *Sqlite) QueryWith(tx *sql.Tx, conn, query string, args ...interface{}) ([]map[string]interface{}, error)

func (*Sqlite) QueryWithConnection

func (db *Sqlite) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Sqlite) QueryWithTx added in v1.1.0

func (db *Sqlite) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type TxFn

type TxFn func(tx *dbsql.Tx) (error, map[string]interface{})

TxFn is the transaction callback function.

type Value

type Value string

Value is a string.

func GetValueFromDatabaseType

func GetValueFromDatabaseType(typ DatabaseType, value interface{}, json bool) Value

func GetValueFromJSONOfDatabaseType added in v1.2.0

func GetValueFromJSONOfDatabaseType(typ DatabaseType, value interface{}) Value

GetValueFromJSONOfDatabaseType return Value of given DatabaseType and interface from JSON string value.

func GetValueFromSQLOfDatabaseType added in v1.2.0

func GetValueFromSQLOfDatabaseType(typ DatabaseType, value interface{}) Value

GetValueFromDatabaseType return Value of given DatabaseType and interface.

func (Value) HTML added in v1.2.7

func (v Value) HTML() template.HTML

HTML return the template.HTML value.

func (Value) String

func (v Value) String() string

String return the string value.

func (Value) ToInt64

func (v Value) ToInt64() int64

ToInt64 turn the string to a int64.

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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