Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 49 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. type company struct {
  2. Id          int
  3. Name        string
  4. }
  5.  
  6. comp.InitModel(newDbConnection(), &comp)
  7.    
  8. //m.caller = pointer to the ptr to comp (struct)
  9. callerV := reflect.ValueOf(m.caller)
  10. CallerField := callerV.Elem()
  11. var values []interface{}
  12. for _, e := range m.columns {
  13.     values = append(values, CallerField.FieldByName(e.name).Addr().Interface())
  14. }
  15. err := r.Scan(values...)
  16. if err != nil {
  17.     return err
  18. }
  19.    
  20. var companies []company
  21. comp.InitModel(newDbConnection(), &comp)
  22. comp.FindAll(&companies) //in this is the db query and scan
  23. fmt.Println(companies) //here should be the result
  24.    
  25. func (m *Model) FindAll(test []interface{}, c *Condition) error {
  26.  
  27. //get the sql statement from the struct
  28. stmt := PrepairStmt(m, c)
  29.  
  30. rows, err := m.db.Query(stmt.selectParse(), c.arguments...)
  31. if err != nil {
  32.     return err
  33. }
  34. defer rows.Close()
  35.  
  36. callerV := reflect.ValueOf(m.caller)
  37. CallerField := callerV.Elem()
  38. for rows.Next() {
  39.  
  40.     var values []interface{}
  41.     for _, e := range m.columns {
  42.         values = append(values, CallerField.FieldByName(e.name).Addr().Interface())
  43.     }
  44.  
  45.     err = rows.Scan(values...)
  46.     if err != nil {
  47.         return err
  48.     }
  49.  
  50.     valuePtr := reflect.New(reflect.TypeOf(test).Elem())
  51.     test = reflect.Append(test,reflect.ValueOf(values))
  52. }
  53.  
  54. return nil
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top