Documentation ¶
Index ¶
- Constants
- Variables
- func CommonExec(db *sql.DB, query string, args ...interface{}) sql.Result
- func CommonQuery(db *sql.DB, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func Contains(v DatabaseType, a []DatabaseType) bool
- func Exec(query string, args ...interface{}) sql.Result
- func Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func RecycleSql(sql *Sql)
- func SetColVarType(colVar *[]interface{}, i int, typeName string)
- func SetResultValue(result *map[string]interface{}, index string, colVar interface{}, ...)
- type Connection
- type DatabaseType
- type H
- type Mssql
- func (db *Mssql) Exec(query string, args ...interface{}) sql.Result
- func (db *Mssql) ExecWithConnection(con string, query string, args ...interface{}) sql.Result
- func (db *Mssql) GetDelimiter() string
- func (db *Mssql) GetName() string
- func (db *Mssql) InitDB(cfglist map[string]config.Database)
- func (db *Mssql) Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func (db *Mssql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- type Mysql
- func (db *Mysql) BeginTransactions() *SqlTxStruct
- func (db *Mysql) BeginTransactionsWithLevel(level sql.IsolationLevel) *SqlTxStruct
- func (db *Mysql) BeginTransactionsWithReadCommitted() *SqlTxStruct
- func (db *Mysql) BeginTransactionsWithReadUncommitted() *SqlTxStruct
- func (db *Mysql) BeginTransactionsWithRepeatableRead() *SqlTxStruct
- func (db *Mysql) Exec(query string, args ...interface{}) sql.Result
- func (db *Mysql) ExecWithConnection(con string, query string, args ...interface{}) sql.Result
- func (db *Mysql) GetDelimiter() string
- func (db *Mysql) GetName() string
- func (db *Mysql) InitDB(cfgs map[string]config.Database)
- func (db *Mysql) Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func (db *Mysql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func (db *Mysql) WithTransaction(fn TxFn) (err error, res map[string]interface{})
- func (db *Mysql) WithTransactionByLevel(level sql.IsolationLevel, fn TxFn) (err error, res map[string]interface{})
- type Postgresql
- func (db *Postgresql) Exec(query string, args ...interface{}) sql.Result
- func (db *Postgresql) ExecWithConnection(con string, query string, args ...interface{}) sql.Result
- func (db *Postgresql) GetDelimiter() string
- func (db *Postgresql) GetName() string
- func (db *Postgresql) InitDB(cfgList map[string]config.Database)
- func (db *Postgresql) Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func (db *Postgresql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- type Sql
- func (sql *Sql) All() ([]map[string]interface{}, error)
- func (sql *Sql) Count() (int64, error)
- func (sql *Sql) Delete() error
- func (sql *Sql) Exec() (int64, error)
- func (sql *Sql) Find(arg interface{}) (map[string]interface{}, error)
- func (sql *Sql) First() (map[string]interface{}, error)
- func (sql *Sql) Insert(values dialect.H) (int64, error)
- func (sql *Sql) LeftJoin(table string, fieldA string, operation string, fieldB string) *Sql
- func (sql *Sql) OrderBy(fields ...string) *Sql
- func (sql *Sql) Select(fields ...string) *Sql
- func (sql *Sql) ShowColumns() ([]map[string]interface{}, error)
- func (sql *Sql) ShowTables() ([]map[string]interface{}, error)
- func (sql *Sql) Skip(offset int) *Sql
- func (sql *Sql) Table(table string) *Sql
- func (sql *Sql) Take(take int) *Sql
- func (sql *Sql) Update(values dialect.H) (int64, error)
- func (sql *Sql) UpdateRaw(raw string, args ...interface{}) *Sql
- func (sql *Sql) Where(field string, operation string, arg interface{}) *Sql
- func (sql *Sql) WhereIn(field string, arg []interface{}) *Sql
- func (sql *Sql) WhereNotIn(field string, arg []interface{}) *Sql
- func (sql *Sql) WhereRaw(raw string, args ...interface{}) *Sql
- func (sql *Sql) WithConnection(conn string) *Sql
- type SqlTxStruct
- type Sqlite
- func (db *Sqlite) Exec(query string, args ...interface{}) sql.Result
- func (db *Sqlite) ExecWithConnection(con string, query string, args ...interface{}) sql.Result
- func (db *Sqlite) GetDelimiter() string
- func (db *Sqlite) GetName() string
- func (db *Sqlite) InitDB(cfgList map[string]config.Database)
- func (db *Sqlite) Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- func (db *Sqlite) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
- type TxFn
- type Value
Constants ¶
View Source
const ( DriverMysql = "mysql" DriverMssql = "mssql" DriverSqlite = "sqlite" DriverPostgresql = "postgresql" )
Variables ¶
View Source
var ( StringTypeList = []DatabaseType{Date, Time, Year, Datetime, Timestamptz, Timestamp, Varchar, Char, Mediumtext, Longtext, Tinytext, Text, Json, Blob, Tinyblob, Mediumblob, Longblob, Interval, Point, 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 = []DatabaseType{Bool, Boolean} IntTypeList = []DatabaseType{Int4, Int, Tinyint, Mediumint, Smallint, Numeric, Smallserial, Serial, Bigserial, Money, Integer, Bigint} FloatTypeList = []DatabaseType{Float, Double, Real, Doubleprecision} UintTypeList = []DatabaseType{Decimal, Bit} )
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 CommonQuery ¶
func Contains ¶
func Contains(v DatabaseType, a []DatabaseType) bool
func RecycleSql ¶
func RecycleSql(sql *Sql)
func SetColVarType ¶
func SetResultValue ¶
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 ¶
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 Mssql ¶
func GetMssqlDB ¶
func GetMssqlDB() *Mssql
func (*Mssql) ExecWithConnection ¶
func (*Mssql) GetDelimiter ¶
type Mysql ¶
func GetMysqlDB ¶
func GetMysqlDB() *Mysql
func (*Mysql) BeginTransactions ¶
func (db *Mysql) BeginTransactions() *SqlTxStruct
func (*Mysql) BeginTransactionsWithLevel ¶
func (db *Mysql) BeginTransactionsWithLevel(level sql.IsolationLevel) *SqlTxStruct
func (*Mysql) BeginTransactionsWithReadCommitted ¶
func (db *Mysql) BeginTransactionsWithReadCommitted() *SqlTxStruct
func (*Mysql) BeginTransactionsWithReadUncommitted ¶
func (db *Mysql) BeginTransactionsWithReadUncommitted() *SqlTxStruct
func (*Mysql) BeginTransactionsWithRepeatableRead ¶
func (db *Mysql) BeginTransactionsWithRepeatableRead() *SqlTxStruct
func (*Mysql) ExecWithConnection ¶
func (*Mysql) GetDelimiter ¶
func (*Mysql) QueryWithConnection ¶
func (*Mysql) WithTransaction ¶
func (*Mysql) WithTransactionByLevel ¶
type Postgresql ¶
func GetPostgresqlDB ¶
func GetPostgresqlDB() *Postgresql
func (*Postgresql) ExecWithConnection ¶
func (db *Postgresql) ExecWithConnection(con string, query string, args ...interface{}) sql.Result
func (*Postgresql) GetDelimiter ¶
func (db *Postgresql) GetDelimiter() string
func (*Postgresql) GetName ¶
func (db *Postgresql) GetName() string
func (*Postgresql) Query ¶
func (db *Postgresql) Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
func (*Postgresql) QueryWithConnection ¶
type Sql ¶
type Sql struct { dialect.SqlComponent // contains filtered or unexported fields }
func WithDriver ¶
func WithDriverAndConnection ¶
func (*Sql) ShowColumns ¶
func (*Sql) ShowTables ¶
func (*Sql) WhereNotIn ¶
func (*Sql) WithConnection ¶
type SqlTxStruct ¶
type Sqlite ¶
func GetSqliteDB ¶
func GetSqliteDB() *Sqlite
func (*Sqlite) ExecWithConnection ¶
func (*Sqlite) GetDelimiter ¶
type TxFn ¶
type TxFn func(*SqlTxStruct) (error, map[string]interface{})
Source Files ¶
Click to show internal directories.
Click to hide internal directories.