本文整理汇总了Golang中github.com/jinzhu/gorm.DB.Raw方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Raw方法的具体用法?Golang DB.Raw怎么用?Golang DB.Raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jinzhu/gorm.DB
的用法示例。
在下文中一共展示了DB.Raw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: releasesLastVersion
// ReleasesLastVersion returns the last ReleaseVersion for the given App. This
// function also ensures that the last release is locked until the transaction
// is commited, so the release version can be incremented atomically.
func releasesLastVersion(db *gorm.DB, appID string) (int, error) {
var version int
rows, err := db.Raw(`select version from releases where app_id = ? order by version desc for update`, appID).Rows()
if err != nil {
return version, err
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&version)
return version, err
}
return version, nil
}
示例2: getColumnNames
func getColumnNames(db gorm.DB, table string) [][]string {
query := `select column_name, data_type from information_schema.columns
where table_name = '` + table + `'`
rows, err := db.Raw(query).Rows()
if err != nil {
panic(err)
}
defer rows.Close()
var rowData [][]string
for rows.Next() {
var columnName string
var dataType string
rows.Scan(&columnName, &dataType)
rowData = append(rowData, []string{columnName, dataType})
}
return rowData
}
示例3: getUniqueMapsCount
func getUniqueMapsCount(db *gorm.DB) uint {
var result = struct {
Maps uint
}{}
db.Raw("select count(map) as maps from (select distinct map from matches)").
Scan(&result)
log.Printf("unique maps: %u", result.Maps)
return result.Maps
}
示例4: RefreshStats
func RefreshStats(cache *Cache, db *gorm.DB) (err error) {
m := &runtime.MemStats{}
runtime.ReadMemStats(m)
acq := m.Sys / 1024 / 1024
used := m.Alloc / 1024 / 1024
m = nil
stats.GoRoutines = runtime.NumGoroutine()
stats.MemoryAcq = int(acq)
stats.MemoryUsed = int(used)
stats.CacheMB = cache.GetSizeInMb()
stats.CacheCount = cache.GetSize()
stats.Rel = nil
stats.Ta = nil
err = db.Order("weight desc").Limit(10).Find(&stats.Ta).Error
if err != nil {
return
}
err = db.Order("hits desc").Limit(10).Find(&stats.Rel).Error
if err != nil {
return
}
row := db.Raw(HITCOUNT).Row()
row.Scan(&stats.HitCount)
row = db.Raw(TAGCOUNT).Row()
row.Scan(&stats.TagCount)
row = db.Raw(RELEASECOUNT).Row()
row.Scan(&stats.ReleaseCount)
return
}