Last active
July 11, 2018 05:19
-
-
Save kenshaw/82ee0ce0334eb42971a33c64a79dcd08 to your computer and use it in GitHub Desktop.
This file contains 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
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