Skip to content

Instantly share code, notes, and snippets.

@kenshaw
Last active July 11, 2018 05:19
Show Gist options
  • Save kenshaw/82ee0ce0334eb42971a33c64a79dcd08 to your computer and use it in GitHub Desktop.
Save kenshaw/82ee0ce0334eb42971a33c64a79dcd08 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"log"
"github.com/xo/dburl"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
db, err := dburl.Open("mssql://user:pass@localhost/database")
if err != nil {
return err
}
defer db.Close()
im, err := GetImageByID(db, "1515")
if err != nil {
return err
}
log.Printf("image: %+v\n", im)
return nil
}
type Image struct {
ImageSeq string
HotelCode string
ImageURL string
}
func GetImageByID(db *sql.DB, seqID string) (*Image, error) {
var res Image
const sqlstr = `select ImageSeq, HotelCode, ImageUrl from HOTEL.dbo.tbl_Hotel_Master_Images where ImageSeq = $1`
err := db.QueryRow(sqlstr, seqID).Scan(&res.ImageSeq, &res.HotelCode, &res.ImageURL)
if err != nil {
return nil, err
}
return &res, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment