db

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 16 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 added in v0.1.0

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

func CommonQuery added in v0.1.0

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

func Contains added in v0.1.0

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

func Exec

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

func Query

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

func RecycleSql

func RecycleSql(sql *Sql)

func SetColVarType added in v0.1.0

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

func SetResultValue added in v0.1.0

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{}, *sql.Rows)
	Exec(query string, args ...interface{}) sql.Result
	QueryWithConnection(conn, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
	ExecWithConnection(conn, query string, args ...interface{}) sql.Result
	InitDB(cfg map[string]config.Database)
	GetName() string
	GetDelimiter() string
}

func GetConnection

func GetConnection() Connection

func GetConnectionByDriver

func GetConnectionByDriver(driver string) Connection

type DatabaseType added in v0.1.0

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 added in v0.1.0

func DT(s string) DatabaseType

func GetDTAndCheck added in v0.1.0

func GetDTAndCheck(s string) DatabaseType

type H

type H map[string]interface{}

type Mssql added in v0.1.0

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

func GetMssqlDB added in v0.1.0

func GetMssqlDB() *Mssql

func (*Mssql) Exec added in v0.1.0

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

func (*Mssql) ExecWithConnection added in v0.1.0

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

func (*Mssql) GetDelimiter added in v0.2.0

func (db *Mssql) GetDelimiter() string

func (*Mssql) GetName added in v0.1.0

func (db *Mssql) GetName() string

func (*Mssql) InitDB added in v0.1.0

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

func (*Mssql) Query added in v0.1.0

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

func (*Mssql) QueryWithConnection added in v0.1.0

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

type Mysql added in v0.1.0

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

func GetMysqlDB added in v0.1.0

func GetMysqlDB() *Mysql

func (*Mysql) BeginTransactions added in v0.1.0

func (db *Mysql) BeginTransactions() *SqlTxStruct

func (*Mysql) BeginTransactionsWithLevel added in v0.1.0

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

func (*Mysql) BeginTransactionsWithReadCommitted added in v0.1.0

func (db *Mysql) BeginTransactionsWithReadCommitted() *SqlTxStruct

func (*Mysql) BeginTransactionsWithReadUncommitted added in v0.1.0

func (db *Mysql) BeginTransactionsWithReadUncommitted() *SqlTxStruct

func (*Mysql) BeginTransactionsWithRepeatableRead added in v0.1.0

func (db *Mysql) BeginTransactionsWithRepeatableRead() *SqlTxStruct

func (*Mysql) Exec added in v0.1.0

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

func (*Mysql) ExecWithConnection added in v0.1.0

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

func (*Mysql) GetDelimiter added in v0.2.0

func (db *Mysql) GetDelimiter() string

func (*Mysql) GetName added in v0.1.0

func (db *Mysql) GetName() string

func (*Mysql) InitDB added in v0.1.0

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

func (*Mysql) Query added in v0.1.0

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

func (*Mysql) QueryWithConnection added in v0.1.0

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

func (*Mysql) WithTransaction added in v0.1.0

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

func (*Mysql) WithTransactionByLevel added in v0.1.0

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

type Postgresql added in v0.1.0

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

func GetPostgresqlDB added in v0.1.0

func GetPostgresqlDB() *Postgresql

func (*Postgresql) Exec added in v0.1.0

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

func (*Postgresql) ExecWithConnection added in v0.1.0

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

func (*Postgresql) GetDelimiter added in v0.2.0

func (db *Postgresql) GetDelimiter() string

func (*Postgresql) GetName added in v0.1.0

func (db *Postgresql) GetName() string

func (*Postgresql) InitDB added in v0.1.0

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

func (*Postgresql) Query added in v0.1.0

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

func (*Postgresql) QueryWithConnection added in v0.1.0

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

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 added in v0.1.0

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 added in v0.1.0

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

type SqlTxStruct added in v0.1.0

type SqlTxStruct struct {
	Tx *sql.Tx
}

func (*SqlTxStruct) Exec added in v0.1.0

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

func (*SqlTxStruct) Query added in v0.1.0

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

type Sqlite added in v0.1.0

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

func GetSqliteDB added in v0.1.0

func GetSqliteDB() *Sqlite

func (*Sqlite) Exec added in v0.1.0

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

func (*Sqlite) ExecWithConnection added in v0.1.0

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

func (*Sqlite) GetDelimiter added in v0.2.0

func (db *Sqlite) GetDelimiter() string

func (*Sqlite) GetName added in v0.1.0

func (db *Sqlite) GetName() string

func (*Sqlite) InitDB added in v0.1.0

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

func (*Sqlite) Query added in v0.1.0

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

func (*Sqlite) QueryWithConnection added in v0.1.0

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

type TxFn added in v0.1.0

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

type Value added in v0.1.0

type Value string

func GetValueFromDatabaseType added in v0.1.0

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

func (Value) String added in v0.1.0

func (v Value) String() string

func (Value) ToInt64 added in v0.1.0

func (v Value) ToInt64() int64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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