本文整理汇总了Golang中database/sql.DB类的典型用法代码### 示例。如果您正苦于以下问题:Golang DB类的具体用法?Golang DB怎么用?Golang DB使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。
在下文中一共展示了DB类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: ObservationsAutour
func (store *MysqlStore) ObservationsAutour(db *sql.DB, x int, y int, z int, dist int, trollId int, amis []int, withTresors bool) ([]*Observation, error) {
sql := "select auteur, num, date, type, nom, x, y, z from observation where"
sql += " x>" + strconv.Itoa(x-dist-1) + " and x<" + strconv.Itoa(x+dist+1)
sql += " and y>" + strconv.Itoa(y-dist-1) + " and y<" + strconv.Itoa(y+dist+1)
sql += " and z>" + strconv.Itoa(z-dist/2-1) + " and z<" + strconv.Itoa(z+dist/2+1)
if !withTresors {
sql += " and type<>'tresor'"
}
sql += " and auteur in (" + strconv.Itoa(trollId)
for _, id := range amis {
sql += "," + strconv.Itoa(id)
}
sql += ") order by type, num, date desc"
rows, err := db.Query(sql)
observations := make([]*Observation, 0, 20)
for rows.Next() {
r := new(Observation)
err = rows.Scan(&r.Auteur, &r.Num, &r.Date, &r.Type, &r.Nom, &r.X, &r.Y, &r.Z)
if err != nil {
return nil, err
}
if len(observations) > 0 && r.Num == observations[len(observations)-1].Num { // dédoublonnage
continue
}
observations = append(observations, r)
}
rows.Close()
return observations, nil
}
开发者ID:toopip,项目名称:Chrall,代码行数:30,代码来源:observationstore.go
示例2: getApplicationDeployments
func getApplicationDeployments(db *sql.DB, a *models.Application, limit int) ([]*models.Deployment, error) {
deployments := []*models.Deployment{}
rows, err := db.Query(applicationDeploymentsStmt, a.Name, limit)
if err != nil {
return deployments, err
}
defer rows.Close()
for rows.Next() {
var state string
d := &models.Deployment{}
err = rows.Scan(&d.Id, &d.UserId, &d.TargetName, &d.CommitSha, &d.Branch, &d.Comment, &state, &d.CreatedAt)
if err != nil {
return deployments, err
}
d.State = models.DeploymentState(state)
deployments = append(deployments, d)
}
if err := rows.Err(); err != nil {
return deployments, err
}
return deployments, nil
}
开发者ID:MahaKoala,项目名称:applikatoni,代码行数:29,代码来源:database.go
示例3: dbUpdateFromV8
func dbUpdateFromV8(db *sql.DB) error {
stmt := `
UPDATE certificates SET fingerprint = replace(fingerprint, " ", "");
INSERT INTO schema (version, updated_at) VALUES (?, strftime("%s"));`
_, err := db.Exec(stmt, 9)
return err
}
开发者ID:rcj4747,项目名称:lxd,代码行数:7,代码来源:db_update.go
示例4: GetHistoryPlayers
func GetHistoryPlayers(db *sql.DB, days int) ([]HistoryPlayers, error) {
var data []HistoryPlayers
var query string
switch days {
case 1:
query = "SELECT history_slots_used, history_date FROM history WHERE history_date > NOW() - INTERVAL 1 DAY"
case 7:
query = "SELECT a.history_slots_used, a.history_date FROM (SELECT history_slots_used, history_date, DATE_FORMAT(history_date, '%p%d%m%y') AS g FROM history WHERE history_date > NOW() - INTERVAL 1 WEEK GROUP BY g) AS a"
case 30:
query = "SELECT a.history_slots_used, a.history_date FROM (SELECT history_slots_used, history_date, DATE_FORMAT(history_date, '%d%m%y') AS g FROM history WHERE history_date > NOW() - INTERVAL 1 MONTH GROUP BY g) AS a"
case 365:
query = "SELECT a.history_slots_used, a.history_date FROM (SELECT history_slots_used, history_date, DATE_FORMAT(history_date, '%u%y') AS g FROM history WHERE history_date > NOW() - INTERVAL 1 YEAR GROUP BY g) AS a"
}
rows, err := db.Query(query)
if err != nil {
return data, err
}
defer rows.Close()
for rows.Next() {
var tmp HistoryPlayers
if err := rows.Scan(&tmp.Total, &tmp.Date); err != nil {
return data, err
}
data = append(data, tmp)
}
return data, nil
}
开发者ID:quickdevel,项目名称:statsamp,代码行数:27,代码来源:server.go
示例5: runExec
func runExec(ctx context.Context, db *sql.DB, query string) error {
done := make(chan struct{})
var (
errMsg error
)
go func() {
for {
if _, err := db.Exec(query); err != nil {
errMsg = err
time.Sleep(time.Second)
continue
} else {
errMsg = nil
done <- struct{}{}
break
}
}
}()
select {
case <-done:
return errMsg
case <-ctx.Done():
return fmt.Errorf("runExec %s timed out with %v / %v", query, ctx.Err(), errMsg)
}
}
开发者ID:xqbumu,项目名称:learn,代码行数:25,代码来源:database.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng