Documentation ¶
Index ¶
- Constants
- Variables
- func DurationString(d time.Duration) string
- func GetEmptyValuesByType(types []FieldType) []interface{}
- func GetFieldNames(db *sql.DB, dbName string, tableName string) []string
- func GetValueByTypeAtIndex(row Row, fType FieldType, index int) interface{}
- func GetValuesByType(row Row, types []FieldType) []interface{}
- func ParseDuration(str string) (dur time.Duration, err error)
- func ParseTime(str string, loc *time.Location) (t time.Time, err error)
- func TimeString(t time.Time) string
- type Blob
- type DBWrapper
- func (db DBWrapper) Exec(sqlText string, args ...interface{}) sql.Result
- func (db DBWrapper) ExecErr(sqlText string, args ...interface{}) (sql.Result, error)
- func (db DBWrapper) Query(sqlText string, args ...interface{}) (qr QueryResult)
- func (db DBWrapper) QueryScalar(sqlText string, args ...interface{}) interface{}
- func (db DBWrapper) QueryScalarBool(sqlText string, args ...interface{}) bool
- func (db DBWrapper) QueryScalarBytes(sqlText string, args ...interface{}) []byte
- func (db DBWrapper) QueryScalarFloat(sqlText string, args ...interface{}) float64
- func (db DBWrapper) QueryScalarInt(sqlText string, args ...interface{}) int
- func (db DBWrapper) QueryScalarStr(sqlText string, args ...interface{}) string
- type Date
- type Field
- type FieldType
- type MysqlConfig
- type QueryResult
- type Raw
- type Row
- func (tr Row) Bin(nn int) (bin []byte)
- func (tr Row) Bool(nn int) (val bool)
- func (tr Row) BoolErr(nn int) (val bool, err error)
- func (tr Row) Date(nn int) (val Date)
- func (tr Row) DateErr(nn int) (val Date, err error)
- func (tr Row) Duration(nn int) (val time.Duration)
- func (tr Row) DurationErr(nn int) (val time.Duration, err error)
- func (tr Row) Float(nn int) (val float64)
- func (tr Row) FloatErr(nn int) (val float64, err error)
- func (tr Row) ForceBool(nn int) (val bool)
- func (tr Row) ForceDate(nn int) (val Date)
- func (tr Row) ForceDuration(nn int) (val time.Duration)
- func (tr Row) ForceFloat(nn int) (val float64)
- func (tr Row) ForceInt(nn int) (val int)
- func (tr Row) ForceInt64(nn int) (val int64)
- func (tr Row) ForceLocaltime(nn int) (val time.Time)
- func (tr Row) ForceTime(nn int, loc *time.Location) (val time.Time)
- func (tr Row) ForceUint(nn int) (val uint)
- func (tr Row) ForceUint64(nn int) (val uint64)
- func (tr Row) Int(nn int) (val int)
- func (tr Row) Int64(nn int) (val int64)
- func (tr Row) Int64Err(nn int) (val int64, err error)
- func (tr Row) IntErr(nn int) (val int, err error)
- func (tr Row) Localtime(nn int) (val time.Time)
- func (tr Row) LocaltimeErr(nn int) (t time.Time, err error)
- func (tr Row) Str(nn int) (str string)
- func (tr Row) Time(nn int, loc *time.Location) (val time.Time)
- func (tr Row) TimeErr(nn int, loc *time.Location) (t time.Time, err error)
- func (tr Row) Uint(nn int) (val uint)
- func (tr Row) Uint64(nn int) (val uint64)
- func (tr Row) Uint64Err(nn int) (val uint64, err error)
- func (tr Row) UintErr(nn int) (val uint, err error)
- type Timestamp
Constants ¶
const TimeFormat = "2006-01-02 15:04:05.000000000"
Sandard MySQL datetime format
Variables ¶
var FieldTypeMap map[string]FieldType = map[string]FieldType{ "tinyint": INT, "smallint": INT, "int": INT, "bigint": INT64, "number": INT64, "bool": BOOL, "float": FLOAT64, "double": FLOAT64, "real": FLOAT64, "decimal": FLOAT64, "char": STRING, "varchar": STRING, "text": STRING, "longtext": STRING, "datetime": TIME, "timestamp": TIME, "date": DATE, }
var FieldTypeNameMap map[FieldType]string
Functions ¶
func DurationString ¶
Convert time.Duration to string representation of mysql.TIME
func GetEmptyValuesByType ¶
func GetEmptyValuesByType(types []FieldType) []interface{}
Get the corresponding empty values of types.
func GetFieldNames ¶
Get the names of all fields of this table.
func GetValueByTypeAtIndex ¶
Cast the values in the 'row' into go type specific by 'fType' at index.
func GetValuesByType ¶
Cast the values in the 'row' into go type specific by 'types'.
func ParseDuration ¶
Parse duration from MySQL string format [+-]H+:MM:SS[.UUUUUUUUU]. Leading and trailing spaces are ignored. If format is invalid returns nil.
func ParseTime ¶
Parses string datetime in TimeFormat using loc location. Converts MySQL zero to time.Time zero.
func TimeString ¶
Returns t as string in MySQL format Converts time.Time zero to MySQL zero.
Types ¶
type DBWrapper ¶
func ConnectMysqlDB ¶
func ConnectMysqlDBByConfig ¶
func ConnectMysqlDBByConfig(config MysqlConfig) DBWrapper
func ConnectMysqlDBConnStr ¶
connStr: tcp:<host>:<port>*<db>/<user>/<pwd> name: name of this connection.
func (DBWrapper) Query ¶
func (db DBWrapper) Query(sqlText string, args ...interface{}) (qr QueryResult)
func (DBWrapper) QueryScalar ¶
func (DBWrapper) QueryScalarBool ¶
func (DBWrapper) QueryScalarBytes ¶
func (DBWrapper) QueryScalarFloat ¶
func (DBWrapper) QueryScalarInt ¶
func (DBWrapper) QueryScalarStr ¶
type Date ¶
For MySQL DATE type
func ParseDate ¶
Convert string date in format YYYY-MM-DD to Date. Leading and trailing spaces are ignored.
type FieldType ¶
type FieldType uint8
func GetFieldTypes ¶
Get the types of all fields of this table.
type MysqlConfig ¶
type QueryResult ¶
type QueryResult struct { Cols []string Rows []Row Error error // contains filtered or unexported fields }
func (*QueryResult) ColID ¶
func (q *QueryResult) ColID(colName string) int
type Row ¶
type Row []interface{}
Result row - contains values for any column of received row.
If row is a result of ordinary text query, its element can be []byte slice, contained result text or nil if NULL is returned.
If it is result of prepared statement execution, its element field can be: intX, uintX, floatX, []byte, Date, Time, time.Time (in Local location) or nil
func (Row) BoolErr ¶
Get the nn-th value and return it as bool. Return error if conversion is impossible.
func (Row) DateErr ¶
Get the nn-th value and return it as Date (0000-00-00 if NULL). Return error if conversion is impossible.
func (Row) DurationErr ¶
Get the nn-th value and return it as time.Duration (0 if NULL). Return error if conversion is impossible.
func (Row) Float ¶
Get the nn-th value and return it as float64 (0 if NULL). Panic if conversion is impossible.
func (Row) FloatErr ¶
Get the nn-th value and return it as float64 (0 if NULL). Return error if conversion is impossible.
func (Row) ForceDuration ¶
It is like DurationErr but return 0 if conversion is impossible.
func (Row) ForceFloat ¶
Get the nn-th value and return it as float64. Return 0 if value is NULL or if conversion is impossible.
func (Row) ForceInt ¶
Get the nn-th value and return it as int. Return 0 if value is NULL or conversion is impossible.
func (Row) ForceInt64 ¶
Get the nn-th value and return it as int64. Return 0 if value is NULL or conversion is impossible.
func (Row) ForceLocaltime ¶
It is like LocaltimeErr but returns 0000-00-00 00:00:00 if conversion is impossible.
func (Row) ForceTime ¶
It is like TimeErr but returns 0000-00-00 00:00:00 if conversion is impossible.
func (Row) ForceUint ¶
Get the nn-th value and return it as uint. Return 0 if value is NULL or conversion is impossible.
func (Row) ForceUint64 ¶
Get the nn-th value and return it as uint64. Return 0 if value is NULL or conversion is impossible.
func (Row) Int ¶
Get the nn-th value and return it as int (0 if NULL). Panic if conversion is impossible.
func (Row) Int64 ¶
Get the nn-th value and return it as int64 (0 if NULL). Panic if conversion is impossible.
func (Row) Int64Err ¶
Get the nn-th value and return it as int64 (0 if NULL). Return error if conversion is impossible.
func (Row) IntErr ¶
Get the nn-th value and return it as int (0 if NULL). Return error if conversion is impossible.
func (Row) LocaltimeErr ¶
Get the nn-th value and return it as time.Time in Local location (zero if NULL). Returns error if conversion is impossible. It can convert Date to time.Time.
func (Row) TimeErr ¶
Get the nn-th value and return it as time.Time in loc location (zero if NULL) Returns error if conversion is impossible. It can convert Date to time.Time.
func (Row) Uint ¶
Get the nn-th value and return it as uint (0 if NULL). Panic if conversion is impossible.
func (Row) Uint64 ¶
Get the nn-th value and return it as uint64 (0 if NULL). Panic if conversion is impossible.