Created
October 23, 2019 07:29
-
-
Save nanmu42/36526e24b86f487826b059deccb81229 to your computer and use it in GitHub Desktop.
Golang SQL scanner and valuer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// QueryParams every key is a query param | |
type QueryParams map[string]QueryParam | |
// Scan satisfies SQL scanner interface | |
func (q *QueryParams) Scan(src interface{}) error { | |
b, ok := src.([]byte) | |
if !ok { | |
return errors.New("type assertion to []byte failed") | |
} | |
return json.Unmarshal(b, q) | |
} | |
// Value satisfies SQL Valuer interface | |
func (q QueryParams) Value() (driver.Value, error) { | |
return json.Marshal(q) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment