Exemple #1
0
func convertSqlValueToFieldValue(o interface{}, f reflect.StructField) reflect.Value {
	if f.Type.Kind() == reflect.String {
		return reflect.ValueOf(toolkit.ConvertToString(o))
	} else if f.Type.Kind() == reflect.Int {
		return reflect.ValueOf(toolkit.ConvertToInt(o))
	} else if f.Type.Kind() == reflect.Float64 {
		return reflect.ValueOf(toolkit.ConvertToFloat64(o))
	} else if f.Type.Kind() == reflect.Struct {
		//convert time
		if f.Type.PkgPath() == "time" && f.Type.Name() == "Time" {
			return reflect.ValueOf(toolkit.ConvertToTime(o))

		}
	}
	return reflect.Zero(f.Type)
}
Exemple #2
0
func (this *Orm) Count(o ModelInterface) (int, error) {
	defer this.qb.Reset()
	this.qb.Table(ModelTableName(o))
	sql, args := this.qb.Count()
	dbrows, err := this.db.All(sql, args...)
	//fmt.Println(sql)
	//fmt.Println(dbrows)
	if err != nil || len(dbrows) != 1 {
		return 0, err
	} else {
		if val, exists := dbrows[0]["num"]; exists {
			return toolkit.ConvertToInt(val), nil
		}
		return 0, nil
	}
}
Exemple #3
0
func GetInt(request *http.Request, key interface{}) int {
	return toolkit.ConvertToInt(Get(request, key))
}