本文整理汇总了Golang中github.com/kisielk/sqlstruct.Scan函数的典型用法代码示例。如果您正苦于以下问题:Golang Scan函数的具体用法?Golang Scan怎么用?Golang Scan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AgeDataPoint
// func JSONData(qry string, uri string, filename string) []byte {
func AgeDataPoint(qry string, uri string, filename string, database string, collection string, conn *sql.DB, session *mgo.Session) error {
// conn, err := connect.GetJanusCon()
// if err != nil {
// panic(err)
// }
// defer conn.Close()
rows, err := conn.Query(qry)
if err != nil {
log.Printf(`Error with "%s": %s`, qry, err)
}
allResults := []janusRow{}
i := 1
for rows.Next() {
d := []JanusTestStuff{}
var t JanusTestStuff
err := sqlstruct.Scan(&t, rows)
if err != nil {
log.Print(err)
}
d = append(d, t)
rowURL := fmt.Sprintf("%s/%s#row=%v", uri, filename, i)
aRow := janusRow{rowURL, i, d}
allResults = append(allResults, aRow)
i = i + 1
}
theTable := table{fmt.Sprintf("%s/%s", uri, filename), allResults}
tableSet := []table{}
tableSet = append(tableSet, theTable)
final := cVSW{tableSet}
// session, err := mgo.Dial("127.0.0.1")
// if err != nil {
// panic(err)
// }
// defer session.Close()
// Optional. Switch the session to a Strong behavior.
session.SetMode(mgo.Strong, true)
c := session.DB(database).C(collection)
err = c.Insert(&final)
if err != nil {
log.Printf("Janus func Error %v with %s\n", err, filename)
}
log.Printf("File: %s written", filename)
jm, _ := json.MarshalIndent(final, "", " ")
_ = utils.WriteFile(filename, jm)
// session.Close()
return nil
}
示例2: getComponents
// getComponents returns a course's sections in a given term at
// a given institution. The sections are values of a map whose
// keys are component strings ("LAB", "LEC", ...)
func getComponents(course, term, institution string) ([][]Section, error) {
db, err := sql.Open("postgres", "postgres://localhost:5432/classtime?sslmode=disable")
if err != nil {
return nil, err
}
if db == nil {
return nil, errors.New("DB connection failed")
}
defer db.Close()
var components [][]Section
query := `SELECT * FROM section
WHERE component=$1
AND course=$2
AND term=$3
AND institution=$4
ORDER BY course, component`
courseAndSectionIdToSection := make(map[string]Section)
for _, c := range componentTypes {
rows, err := db.Query(query, c, course, term, institution)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
sections := []Section{}
for rows.Next() {
var section Section
if err := sqlstruct.Scan(§ion, rows); err != nil {
log.Fatal(err)
continue
}
courseAndSectionIdToSection[section.Course.String+section.Section.String] = section
sections = append(sections, section)
}
if len(sections) == 0 {
continue
}
components = append(components, sections)
}
for _, sections := range components {
for _, section := range sections {
if section.AutoEnroll.String != "" {
autoEnrollSection, ok := courseAndSectionIdToSection[section.Course.String+section.AutoEnroll.String]
if ok {
section.AutoEnrollComponent.Scan(autoEnrollSection.Component.String)
}
}
}
}
return components, nil
}
示例3: updateLikes
func updateLikes() {
queryStr := fmt.Sprintf("SELECT %s FROM groupme_posts WHERE posted_at >= NOW() - '1 day'::INTERVAL", sqlstruct.Columns(gmPost{}))
rows, err := config.DB.Query(queryStr)
if err != nil {
return
}
defer rows.Close()
groupedPosts := make(map[string][]gmPost)
for rows.Next() {
var post gmPost
err := sqlstruct.Scan(&post, rows)
if err == nil {
slice := groupedPosts[post.GroupID]
slice = append(slice, post)
groupedPosts[post.GroupID] = slice
}
}
token := os.Getenv("groupMeID")
updated := make(map[int]int)
for key, group := range groupedPosts {
getURL := "https://api.groupme.com/v3/groups/" + key + "/likes?period=day&token=" + token
resp, _ := http.Get(getURL)
body, _ := ioutil.ReadAll(resp.Body)
var wrapper gmMessageWrapper
json.Unmarshal(body, &wrapper)
for _, message := range wrapper.Response.Messages {
for _, post := range group {
if post.MessageID == message.MessageID() {
updated[post.ID] = len(message.FavoritedBy)
}
}
}
}
tx, err := config.DB.Begin()
if err != nil {
return
}
stmt, _ := config.DB.Prepare("UPDATE groupme_posts SET likes=$1 WHERE id=$2")
for updateID, likeCount := range updated {
stmt.Exec(likeCount, updateID)
}
tx.Commit()
}
示例4: GetCertificate
// GetCertificate gets a CertificateRecord indexed by serial.
func GetCertificate(db *sql.DB, serial string) (*CertificateRecord, error) {
cr := new(CertificateRecord)
rows, err := db.Query(fmt.Sprintf(selectSQL, sqlstruct.Columns(*cr)), serial)
if err != nil {
return nil, wrapCertStoreError(err)
}
defer rows.Close()
if rows.Next() {
return cr, wrapCertStoreError(sqlstruct.Scan(cr, rows))
}
return nil, nil
}
示例5: FetchBot
//Public Methods
func FetchBot(id string) (Bot, error) {
rows, err := config.DB.Query(fmt.Sprintf("SELECT %s FROM bots WHERE group_id = $1", sqlstruct.Columns(Bot{})), id)
if err != nil {
return Bot{}, err
}
defer rows.Close()
rows.Next()
var bot Bot
err = sqlstruct.Scan(&bot, rows)
return bot, err
}
示例6: GetOCSP
// GetOCSP retrieves a OCSPRecord from db by serial.
func GetOCSP(db *sql.DB, serial string) (rr *OCSPRecord, err error) {
rr = new(OCSPRecord)
rows, err := db.Query(fmt.Sprintf(selectOCSPSQL, sqlstruct.Columns(*rr)), serial)
if err != nil {
return nil, wrapCertStoreError(err)
}
defer rows.Close()
if rows.Next() {
return rr, sqlstruct.Scan(rr, rows)
}
return nil, nil
}
示例7: Query
func (r ModelMysqlRepo) Query(query string) (models []Model, err error) {
rows, err := r.Db.Query(query)
if err != nil {
log.Println(err)
return
}
model := Model{}
for rows.Next() {
err = sqlstruct.Scan(&model, rows)
models = append(models, model)
}
rows.Close()
return
}
示例8: Query
func (r TagMysqlRepo) Query(query string) (tags []Tag, err error) {
rows, err := r.Db.Query(query)
if err != nil {
log.Println(err)
return
}
tag := Tag{}
for rows.Next() {
err = sqlstruct.Scan(&tag, rows)
tags = append(tags, tag)
}
rows.Close()
return
}
示例9: unmarshalBalls
func unmarshalBalls(rows *sql.Rows) (balls []Ball, err error) {
for rows.Next() {
var ball Ball
err := sqlstruct.Scan(&ball, rows)
if err != nil {
log.Fatal(err)
}
ball.Date, err = timeFromSQLTimestamp(ball.Timestamp)
if err != nil {
log.Fatal(err)
}
balls = append(balls, ball)
}
return
}
示例10: Query
func (r MakeMysqlRepo) Query(query string) (makes []Make, err error) {
rows, err := r.Db.Query(query)
if err != nil {
log.Println(err)
return
}
make := Make{}
for rows.Next() {
err = sqlstruct.Scan(&make, rows)
makes = append(makes, make)
}
rows.Close()
return
}
示例11: GetUnexpiredOCSPs
// GetUnexpiredOCSPs retrieves all unexpired OCSPRecord from db.
func GetUnexpiredOCSPs(db *sql.DB) (rrs []*OCSPRecord, err error) {
rr := new(OCSPRecord)
rows, err := db.Query(fmt.Sprintf(selectAllUnexpiredOCSPSQL, sqlstruct.Columns(*rr)))
if err != nil {
return nil, wrapCertStoreError(err)
}
defer rows.Close()
for rows.Next() {
err = sqlstruct.Scan(rr, rows)
if err != nil {
return nil, wrapCertStoreError(err)
}
rrs = append(rrs, rr)
}
return rrs, nil
}
示例12: GetUnexpiredCertificates
// GetUnexpiredCertificates gets all unexpired certificate from db.
func GetUnexpiredCertificates(db *sql.DB) (crs []*CertificateRecord, err error) {
cr := new(CertificateRecord)
rows, err := db.Query(fmt.Sprintf(selectAllUnexpiredSQL, sqlstruct.Columns(*cr)))
if err != nil {
return nil, wrapCertStoreError(err)
}
defer rows.Close()
for rows.Next() {
err = sqlstruct.Scan(cr, rows)
if err != nil {
return nil, wrapCertStoreError(err)
}
crs = append(crs, cr)
}
return crs, nil
}
示例13: GetCertificate
// GetCertificate gets a certdb.CertificateRecord indexed by serial.
func (d *Accessor) GetCertificate(serial string) (*certdb.CertificateRecord, error) {
err := d.checkDB()
if err != nil {
return nil, err
}
cr := new(certdb.CertificateRecord)
rows, err := d.db.Query(fmt.Sprintf(selectSQL, sqlstruct.Columns(*cr)), serial)
if err != nil {
return nil, wrapSQLError(err)
}
defer rows.Close()
if rows.Next() {
return cr, wrapSQLError(sqlstruct.Scan(cr, rows))
}
return nil, nil
}
示例14: GetOCSP
// GetOCSP retrieves a certdb.OCSPRecord from db by serial.
func (d *Accessor) GetOCSP(serial string) (rr *certdb.OCSPRecord, err error) {
err = d.checkDB()
if err != nil {
return nil, err
}
rr = new(certdb.OCSPRecord)
rows, err := d.db.Query(fmt.Sprintf(selectOCSPSQL, sqlstruct.Columns(*rr)), serial)
if err != nil {
return nil, wrapSQLError(err)
}
defer rows.Close()
if rows.Next() {
return rr, sqlstruct.Scan(rr, rows)
}
return nil, nil
}
示例15: Get
func (r ModelMysqlRepo) Get(id int, joins []string) (model Model, err error) {
query := fmt.Sprintf("select * from model where id=%d", id)
rows, err := r.Db.Query(query)
if err != nil {
return
}
if !rows.Next() {
err = ErrNoResults
return
}
sqlstruct.Scan(&model, rows)
err = rows.Err()
rows.Close()
return
}