-
Notifications
You must be signed in to change notification settings - Fork 20
Snippets vscode
comraderat edited this page May 3, 2020
·
3 revisions
##Gochan contains some/a snippet(s) for vscode to make development slightly easier
This snippet can be used for querying the database for scanning the resulting rows to a slice of some object. The name of the array is the name of a single object + s.
Triggers: 'queryscan', 'scan-rows'
Snippet:
rows, err := QuerySQL('sql')
if err != nil {
return nil, err
}
var itemnames []elementType
for rows.Next() {
var itemname elementType
err = rows.Scan()
if err != nil {
return nil, err
}
itemnames = append(itemnames, itemname)
}
return itemnames, nil
Example:
rows, err := QuerySQL("Select * from balls")
if err != nil {
return nil, err
}
var balls []Ball
for rows.Next() {
var ball Ball
err = rows.Scan(&ball.size, &ball.color)
if err != nil {
return nil, err
}
balls = append(balls, ball)
}
return balls, nil