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 Join
- 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) 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) 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) 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 RawUpdate
- 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) 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
- type Where
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 CommonExec ¶ added in v0.1.0
func CommonQuery ¶ added in v0.1.0
func Contains ¶ added in v0.1.0
func Contains(v DatabaseType, a []DatabaseType) bool
func RecycleSql ¶
func RecycleSql(sql *Sql)
func SetColVarType ¶ added in v0.1.0
func SetResultValue ¶ added in v0.1.0
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 }
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 Mssql ¶ added in v0.1.0
func GetMssqlDB ¶ added in v0.1.0
func GetMssqlDB() *Mssql
func (*Mssql) ExecWithConnection ¶ added in v0.1.0
type Mysql ¶ added in v0.1.0
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) ExecWithConnection ¶ added in v0.1.0
func (*Mysql) QueryWithConnection ¶ added in v0.1.0
func (*Mysql) WithTransaction ¶ added in v0.1.0
func (*Mysql) WithTransactionByLevel ¶ added in v0.1.0
type Postgresql ¶ added in v0.1.0
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) 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
type Sql ¶
type Sql struct { dialect.SqlComponent // contains filtered or unexported fields }
func WithDriver ¶
func WithDriverAndConnection ¶ added in v0.1.0
func (*Sql) ShowColumns ¶
func (*Sql) ShowTables ¶
func (*Sql) WhereNotIn ¶
func (*Sql) WithConnection ¶ added in v0.1.0
type SqlTxStruct ¶ added in v0.1.0
type Sqlite ¶ added in v0.1.0
func GetSqliteDB ¶ added in v0.1.0
func GetSqliteDB() *Sqlite
func (*Sqlite) ExecWithConnection ¶ added in v0.1.0
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.