Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load into map[string]interface{} #83

Closed
bgaifullin opened this issue Apr 10, 2017 · 5 comments
Closed

Load into map[string]interface{} #83

bgaifullin opened this issue Apr 10, 2017 · 5 comments

Comments

@bgaifullin
Copy link

Allow to use map[string]interface{} in function Load,
where key is column name, value is column value.

result := make(map[string]interface{})
count, err := s.Select("a", "b").From("table1").Where("a=1").Load(&result)
// expected result contains 2 items, a and b with appropriate column values.
@kumarsiva07
Copy link

How do i use map array to load more than one row?

@bgaifullin
Copy link
Author

just pass []map[string]interface{} to method Load. you can check how this is implemented in https://github.com/mailru/dbr

@bgaifullin
Copy link
Author

bgaifullin commented Jun 21, 2017

I close this issue, since PR was declined.

@kumarsiva07
Copy link

mtObj := make(map[string]interface{})
tx.SelectBySql("SELECT ID FROM Contacts where ID=? and NAME=? limit 1", values...).Loads(&mtObj)
fmt.Prtintln(mtObj["NAME"])

This prints Address.
screen shot 2017-06-22 at 2 34 25 am

@bgaifullin
Copy link
Author

bgaifullin commented Jun 22, 2017

When you load values into map[string]interface{}, there is no information about type, and value will be stored as is. ([]byte)

You are responsible for converting value into required type:

for example:

// to string
string(v.([]byte))
// to int64
strconv.ParseInt(string(v.([]byte)), 10, 64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants