本文整理汇总了Golang中github.com/kisielk/sqlstruct.Scan函数的典型用法代码示例。如果您正苦于以下问题:Golang Scan函数的具体用法?Golang Scan怎么用?Golang Scan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scan函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:OpenCoreData,项目名称:ocdJanus,代码行数:58,代码来源:JanusTestJSONData.go
示例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
}
开发者ID:rosshamish,项目名称:scheduler,代码行数:57,代码来源:scheduler.go
示例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()
}
开发者ID:NelsonLeDuc,项目名称:CalmanBot,代码行数:52,代码来源:gmcachemanager.go
示例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
}
开发者ID:jamesbjackson,项目名称:cfssl,代码行数:14,代码来源:certdb.go
示例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
}
开发者ID:NelsonLeDuc,项目名称:CalmanBot,代码行数:14,代码来源:repo.go
示例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
}
开发者ID:jamesbjackson,项目名称:cfssl,代码行数:14,代码来源:certdb.go
示例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
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:15,代码来源:model-mysql-repo.go
示例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
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:15,代码来源:tag-mysql-repo.go
示例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
}
开发者ID:kybernetyk,项目名称:golandball,代码行数:15,代码来源:ballsite.go
示例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
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:16,代码来源:make-mysql-repo.go
示例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
}
开发者ID:jamesbjackson,项目名称:cfssl,代码行数:19,代码来源:certdb.go
示例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
}
开发者ID:jamesbjackson,项目名称:cfssl,代码行数:19,代码来源:certdb.go
示例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
}
开发者ID:mclem,项目名称:cfssl,代码行数:19,代码来源:database_accessor.go
示例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
}
开发者ID:mclem,项目名称:cfssl,代码行数:19,代码来源:database_accessor.go
示例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
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:19,代码来源:model-mysql-repo.go
示例16: Get
func (r MakeMysqlRepo) Get(id int, joins []string) (make Make, err error) {
entities := "make"
query := fmt.Sprintf("select * from %s where id=%d", entities, id)
rows, err := r.Db.Query(query)
if err != nil {
return
}
if !rows.Next() {
err = ErrNoResults
return
}
sqlstruct.Scan(&make, rows)
rows.Close()
return
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:19,代码来源:make-mysql-repo.go
示例17: cacheFetch
func cacheFetch(whereStr string, values []interface{}) ([]Cached, error) {
queryStr := fmt.Sprintf("SELECT %s FROM cached", sqlstruct.Columns(Cached{}))
rows, err := config.DB.Query(queryStr+" "+whereStr, values...)
if err != nil {
return []Cached{}, err
}
defer rows.Close()
actions := []Cached{}
for rows.Next() {
var act Cached
err := sqlstruct.Scan(&act, rows)
if err == nil {
actions = append(actions, act)
}
}
return actions, nil
}
开发者ID:NelsonLeDuc,项目名称:CalmanBot,代码行数:20,代码来源:smartcache.go
示例18: GetAll
func (r TagMysqlRepo) GetAll(limit int, joins []string) (result []Tag, err error) {
if limit == 0 {
limit = MAX_MYSQL_RESULTS
}
query := fmt.Sprintf("select * from tag limit %d", limit)
rows, err := r.Db.Query(query)
if err != nil {
log.Println(err)
return
}
tag := Tag{}
for rows.Next() {
err = sqlstruct.Scan(&tag, rows)
result = append(result, tag)
}
rows.Close()
return
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:20,代码来源:tag-mysql-repo.go
示例19: populateDataForPhonenumbers
func populateDataForPhonenumbers(rows *sql.Rows, languageCode string) (*model.Response, error) {
countries := []*model.Country{}
for rows.Next() {
var data model.Phonenumber
err := sqlstruct.Scan(&data, rows)
if err != nil {
panic(err)
}
countryPosition := -1
for i := 0; i < len(countries); i++ {
if countries[i].Code == data.Country {
countryPosition = i
}
}
if countryPosition != -1 {
countries[countryPosition].Phonenumbers = append(countries[countryPosition].Phonenumbers, &data)
} else {
newCountry := &model.Country{
Code: data.Country,
Phonenumbers: []*model.Phonenumber{},
}
newCountry.Phonenumbers = append(newCountry.Phonenumbers, &data)
countries = append(countries, newCountry)
}
}
err := rows.Err()
if err != nil {
log.Errorf("Error during the loop of rows, err: %s", err)
}
data := &model.Response{
Countries: countries,
Language: languageCode,
}
return data, err
}
开发者ID:helphone,项目名称:api,代码行数:41,代码来源:helper.go
示例20: GetAll
func (r ModelMysqlRepo) GetAll(limit int, joins []string) (result []Model, err error) {
if limit == 0 {
limit = MAX_MYSQL_RESULTS
}
query := fmt.Sprintf("select * from model limit %d", limit)
rows, err := r.Db.Query(query)
if err != nil {
log.Println(err)
return
}
model := Model{}
for rows.Next() {
err = sqlstruct.Scan(&model, rows)
result = append(result, model)
}
rows.Close()
return
}
开发者ID:tonto,项目名称:claire-go-backend,代码行数:21,代码来源:model-mysql-repo.go
注:本文中的github.com/kisielk/sqlstruct.Scan函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论