Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. func main() {
  2. var bulkid int64
  3. bulkid = 47
  4. FetchSendTBL(bulkid)
  5. }
  6.  
  7. type SendTBLFields struct {
  8. Bulk_id int64
  9. User_id string
  10. }
  11.  
  12. type TBLConfig struct {
  13. Name string
  14. RowKeys []string
  15. RangKeys []string
  16. NameOfTBLFields interface{}
  17. }
  18.  
  19. var SendTBLConfig = TBLConfig{
  20. Name: "sendtbl", /* SendTBL */
  21. RowKeys: []string{"Bulk_id"},
  22. RangKeys: []string{},
  23. NameOfTBLFields: SendTBLFields{},
  24. }
  25.  
  26. func FetchSendTBL(ids ...interface{}) {
  27. SelectRow(SendTBLConfig, ids)
  28. }
  29.  
  30. func SelectRow(TBLConfig TBLConfig, ids ...interface{}) {
  31. tableName := TBLConfig.Name
  32. tablePrimaryKeys := TBLConfig.RowKeys
  33.  
  34. where := []string{}
  35. for _, key := range tablePrimaryKeys {
  36. where = append(where, strings.ToLower(fmt.Sprintf("%q", key))+" = ?")
  37. }
  38.  
  39. session := ConnectionSession.Session()
  40. err := session.Query(fmt.Sprintf(`SELECT * FROM %q WHERE %s LIMIT 1`, tableName, strings.Join(where, " AND ")), ids...).Scan(&bulk_id);
  41.  
  42. if err != nil {
  43. fmt.Print(err)
  44. }
  45.  
  46. fmt.Println("result ", bulk_id)
  47.  
  48. }
  49.  
  50. func SelectRows(TBLConfig TBLConfig, ids ...interface{}) {}
Add Comment
Please, Sign In to add comment