Exemple #1
0
func getColumns(dbase database.DBInter, model interface{}) (columns []string) {
	ind := reflect.Indirect(reflect.ValueOf(model))
	typeOfM := ind.Type()
	for i := 0; i < ind.NumField(); i++ {
		columns = append(columns, dbase.QuoteIdentifier(strings.ToLower(typeOfM.Field(i).Name)))
	}
	return columns
}
Exemple #2
0
func getColumnsAndData(dbase database.DBInter, model interface{}) (columns []string, data []interface{}) {
	ind := reflect.Indirect(reflect.ValueOf(model))
	typeOfM := ind.Type()
	for i := 0; i < ind.NumField(); i++ {
		if typeOfM.Field(i).Name != "Id" {
			columns = append(columns, dbase.QuoteIdentifier(columnName(typeOfM.Field(i).Name)))
			field := ind.Field(i).Interface()
			switch field.(type) {
			case time.Time:
				data = append(data, field.(time.Time).UTC())
			default:
				data = append(data, field)
			}
		}
	}
	return columns, data
}