本文整理汇总了Golang中github.com/coocood/qbs.GetQbs函数的典型用法代码示例。如果您正苦于以下问题:Golang GetQbs函数的具体用法?Golang GetQbs怎么用?Golang GetQbs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetQbs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetupDb
func SetupDb() (q *qbs.Qbs) {
var (
err error
migration *qbs.Migration
)
q, err = qbs.GetQbs()
if q, err = qbs.GetQbs(); err != nil {
panic(err)
}
if migration, err = qbs.GetMigration(); err != nil {
panic(err)
}
defer migration.Close()
if err = migration.CreateTableIfNotExists(new(User)); err != nil {
panic(err)
}
if err = migration.CreateTableIfNotExists(new(Profile)); err != nil {
panic(err)
}
return q
}
示例2: Save
func (r *Reply) Save() bool {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
return false
}
defer q.Close()
_, err = q.Save(r)
if err != nil {
fmt.Println(err)
return false
}
topic := new(Topic)
topic.Id = r.TopicId
q.Find(topic)
if err != nil {
fmt.Println(err)
return false
}
if topic.Id > 0 {
topic.Replies += 1
topic.Save()
}
return true
}
示例3: main2
func main2() {
qbs.Register("sqlite3", "gowalker.db", "", qbs.NewSqlite3())
q, _ := qbs.GetQbs()
defer q.Close()
pinfo := new(PkgInfo)
q.Iterate(pinfo, func() error {
if pinfo.Id > 198 {
c := &http.Client{}
req, err := http.NewRequest("GET",
"http://gowalker.org/add?path="+pinfo.Path+"&views="+fmt.Sprintf("%d", pinfo.Views), nil)
if err != nil {
return err
}
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0")
resp, err := c.Do(req)
defer resp.Body.Close()
fmt.Println(pinfo.Id, pinfo.Path)
if pinfo.Id >= 10000 {
return errors.New("FINISH")
}
}
return nil
})
}
示例4: QbsUpdate
func (c App) QbsUpdate(queries int) revel.Result {
qbs, _ := qbs.GetQbs()
defer qbs.Close()
if queries <= 1 {
var w World
w.Id = uint16(rand.Intn(WorldRowCount) + 1)
if err := qbs.Find(&w); err != nil {
revel.ERROR.Fatalf("Error scanning world row: %v", err)
}
w.RandomNumber = uint16(rand.Intn(WorldRowCount) + 1)
if _, err := qbs.Save(&w); err != nil {
revel.ERROR.Fatalf("Error updating world row: %v", err)
}
return c.RenderJson(&w)
}
ww := make([]World, queries)
for i := 0; i < queries; i++ {
ww[i].Id = uint16(rand.Intn(WorldRowCount) + 1)
if err := qbs.Find(&ww[i]); err != nil {
revel.ERROR.Fatalf("Error scanning world row: %v", err)
}
ww[i].RandomNumber = uint16(rand.Intn(WorldRowCount) + 1)
if _, err := qbs.Save(&ww[i]); err != nil {
revel.ERROR.Fatalf("Error scanning world row: %v", err)
}
}
return c.RenderJson(ww)
}
示例5: GetTopics
func GetTopics(page int, where string, value interface{}, order string, url string) ([]*Topic, *Pagination) {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
}
defer q.Close()
page -= 1
if page < 0 {
page = 0
}
var topics []*Topic
var total int64
if where == "" {
total = q.Count("topic")
err = q.OmitFields("Content").OrderByDesc(order).
Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&topics)
} else {
total = q.WhereEqual(where, value).Count("topic")
err = q.WhereEqual(where, value).
OmitFields("Content").OrderByDesc(order).
Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&topics)
}
if err != nil {
fmt.Println(err)
}
url = url[:strings.Index(url, "=")+1]
pagination := NewPagination(page, int(total), url)
return topics, pagination
}
示例6: Put
func (this *User) Put(user *models.User) {
//////////////////
q, err := qbs.GetQbs()
assetsError(err)
defer q.Close()
//////////////////
q.Save(user)
}
示例7: Put
func (this *Project) Put(project *models.Project) {
//////////////////
q, err := qbs.GetQbs()
assetsError(err)
defer q.Close()
//////////////////
q.Save(project)
}
示例8: Begin
//开始连接
func (c *Qbs) Begin() revel.Result {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
}
c.q = q
return nil
}
示例9: getModels
func getModels(items interface{}) (interface{}, error) {
q, err := qbs.GetQbs()
if err != nil {
return nil, err
}
defer q.Close()
err = q.FindAll(items)
return items, err
}
示例10: NajdiSporocila
func NajdiSporocila(offset int) (error, []*Sporocilo) {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
return err, nil
}
var sporocila []*Sporocilo
err2 := q.Limit(25).Offset(offset).FindAll(&sporocila)
return err2, sporocila
}
示例11: Init
func Init() {
//qbs.RegisterSqlite3("e:/mygo/src/cms/data/orange.db")
qbs.RegisterSqlite3(utils.Sqlite3Path(beego.AppConfig.String("DatabasePath")))
db, _ = qbs.GetQbs()
// //cache期限
// var err error
// if expired, err = beego.AppConfig.Int64("CacheExpired"); err != nil {
// expired = 60
// }
// bm = cache.NewMemoryCache()
}
示例12: Fortune
func (c App) Fortune() revel.Result {
qbs, _ := qbs.GetQbs()
defer qbs.Close()
var fortunes []*Fortune
qbs.FindAll(&fortunes)
fortunes = append(fortunes,
&Fortune{Message: "Additional fortune added at request time."})
sort.Sort(ByMessage{fortunes})
return c.Render(fortunes)
}
示例13: FindUserByCode
func FindUserByCode(code string) *User {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
}
defer q.Close()
user := new(User)
err = q.WhereEqual("validate_code", code).Find(user)
return user
}
示例14: GetUser
func GetUser(w http.ResponseWriter, r *http.Request) {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
w.WriteHeader(500)
return
}
defer q.Close()
u, err := FindUserById(q, 6)
data, _ := json.Marshal(u)
w.Write(data)
}
示例15: FindUserById
func FindUserById(id int64) *User {
q, err := qbs.GetQbs()
if err != nil {
fmt.Println(err)
}
defer q.Close()
user := new(User)
err = q.WhereEqual("id", id).Find(user)
return user
}