db

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: Apache-2.0 Imports: 12 Imported by: 175

Documentation

Index

Constants

View Source
const (
	DriverMysql      = "mysql"
	DriverMssql      = "mssql"
	DriverSqlite     = "sqlite"
	DriverPostgresql = "postgresql"
)

Variables

View Source
var DB = Sqlite{
	DbList: map[string]*sql.DB{},
}
View Source
var MssqlDB = Mssql{
	DbList: map[string]*sql.DB{},
}
View Source
var MysqlDB = Mysql{
	DbList: map[string]*sql.DB{},
}
View Source
var PostgresqlDB = Postgresql{
	DbList: map[string]*sql.DB{},
}
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:  "",
			},
			diver:   nil,
			dialect: nil,
		}
	},
}

Functions

func CommonExec

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

func CommonQuery

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

func Contains

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

func Exec

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

func Query

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

func RecycleSql

func RecycleSql(sql *Sql)

func SetColVarType

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

func SetResultValue

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

Types

type Connection

type Connection interface {
	Query(query string, args ...interface{}) ([]map[string]interface{}, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryWithConnection(conn, query string, args ...interface{}) ([]map[string]interface{}, error)
	ExecWithConnection(conn, query string, args ...interface{}) (sql.Result, error)
	InitDB(cfg map[string]config.Database)
	GetName() string
	GetDelimiter() string
}

func GetConnection

func GetConnection() Connection

func GetConnectionByDriver

func GetConnectionByDriver(driver string) Connection

type DatabaseType

type DatabaseType string
const (
	Int       DatabaseType = "INT"
	Tinyint   DatabaseType = "TINYINT"
	Mediumint DatabaseType = "MEDIUMINT"
	Smallint  DatabaseType = "SMALLINT"
	Bigint    DatabaseType = "BIGINT"
	Bit       DatabaseType = "BIT"
	Int4      DatabaseType = "INT4"

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

	Real    DatabaseType = "REAL"
	Float   DatabaseType = "FLOAT"
	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"
	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"
)

func DT

func DT(s string) DatabaseType

func GetDTAndCheck

func GetDTAndCheck(s string) DatabaseType

type H

type H map[string]interface{}

type Mssql

type Mssql struct {
	DbList map[string]*sql.DB
	Once   sync.Once
}

func GetMssqlDB

func GetMssqlDB() *Mssql

func (*Mssql) Exec

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

func (*Mssql) ExecWithConnection

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

func (*Mssql) GetDelimiter

func (db *Mssql) GetDelimiter() string

func (*Mssql) GetName

func (db *Mssql) GetName() string

func (*Mssql) InitDB

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

func (*Mssql) Query

func (db *Mssql) Query(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)

type Mysql

type Mysql struct {
	DbList map[string]*sql.DB
	Once   sync.Once
}

func GetMysqlDB

func GetMysqlDB() *Mysql

func (*Mysql) BeginTransactions

func (db *Mysql) BeginTransactions() *SqlTx

func (*Mysql) BeginTransactionsWithLevel

func (db *Mysql) BeginTransactionsWithLevel(level sql.IsolationLevel) *SqlTx

func (*Mysql) BeginTransactionsWithReadCommitted

func (db *Mysql) BeginTransactionsWithReadCommitted() *SqlTx

func (*Mysql) BeginTransactionsWithReadUncommitted

func (db *Mysql) BeginTransactionsWithReadUncommitted() *SqlTx

func (*Mysql) BeginTransactionsWithRepeatableRead

func (db *Mysql) BeginTransactionsWithRepeatableRead() *SqlTx

func (*Mysql) Exec

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

func (*Mysql) ExecWithConnection

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

func (*Mysql) GetDelimiter

func (db *Mysql) GetDelimiter() string

func (*Mysql) GetName

func (db *Mysql) GetName() string

func (*Mysql) InitDB

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

func (*Mysql) Query

func (db *Mysql) Query(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)

func (*Mysql) WithTransaction

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

func (*Mysql) WithTransactionByLevel

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

type Postgresql

type Postgresql struct {
	DbList map[string]*sql.DB
	Once   sync.Once
}

func GetPostgresqlDB

func GetPostgresqlDB() *Postgresql

func (*Postgresql) Exec

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

func (*Postgresql) ExecWithConnection

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

func (*Postgresql) GetDelimiter

func (db *Postgresql) GetDelimiter() string

func (*Postgresql) GetName

func (db *Postgresql) GetName() string

func (*Postgresql) InitDB

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

func (*Postgresql) Query

func (db *Postgresql) Query(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)

type Sql

type Sql struct {
	dialect.SqlComponent
	// contains filtered or unexported fields
}

func Table

func Table(table string) *Sql

func WithDriver

func WithDriver(driver string) *Sql

func WithDriverAndConnection

func WithDriverAndConnection(conn, driver string) *Sql

func (*Sql) All

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

func (*Sql) Count

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

func (*Sql) Delete

func (sql *Sql) Delete() error

func (*Sql) Exec

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

func (*Sql) Find

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

func (*Sql) First

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

func (*Sql) Insert

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

func (*Sql) LeftJoin

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

func (*Sql) OrderBy

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

func (*Sql) Select

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

func (*Sql) ShowColumns

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

func (*Sql) ShowTables

func (sql *Sql) ShowTables() ([]map[string]interface{}, error)

func (*Sql) Skip

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

func (*Sql) Table

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

func (*Sql) Take

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

func (*Sql) Update

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

func (*Sql) UpdateRaw

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

func (*Sql) Where

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

func (*Sql) WhereIn

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

func (*Sql) WhereNotIn

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

func (*Sql) WhereRaw

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

func (*Sql) WithConnection

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

type SqlTx added in v1.0.3

type SqlTx struct {
	Tx *sql.Tx
}

func (*SqlTx) Exec added in v1.0.3

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

func (*SqlTx) Query added in v1.0.3

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

type Sqlite

type Sqlite struct {
	DbList map[string]*sql.DB
	Once   sync.Once
}

func GetSqliteDB

func GetSqliteDB() *Sqlite

func (*Sqlite) Exec

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

func (*Sqlite) ExecWithConnection

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

func (*Sqlite) GetDelimiter

func (db *Sqlite) GetDelimiter() string

func (*Sqlite) GetName

func (db *Sqlite) GetName() string

func (*Sqlite) InitDB

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

func (*Sqlite) Query

func (db *Sqlite) Query(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)

type TxFn

type TxFn func(*SqlTx) (error, map[string]interface{})

type Value

type Value string

func GetValueFromDatabaseType

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

func (Value) String

func (v Value) String() string

func (Value) ToInt64

func (v Value) ToInt64() int64

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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