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
}
Exemple #2
0
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
}
Exemple #3
0
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
	})
}
Exemple #4
0
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)
}
Exemple #5
0
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
}
Exemple #6
0
func (this *User) Put(user *models.User) {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	q.Save(user)
}
Exemple #7
0
func (this *Project) Put(project *models.Project) {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	q.Save(project)
}
Exemple #8
0
//开始连接
func (c *Qbs) Begin() revel.Result {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	c.q = q
	return nil
}
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
}
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
}
Exemple #11
0
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()
}
Exemple #12
0
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)
}
Exemple #13
0
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
}
Exemple #14
0
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)
}
Exemple #15
0
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
}
Exemple #16
0
func (c *Admin) ListUser() revel.Result {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	var users []*models.User
	err = q.FindAll(&users)

	return c.Render(users)
}
Exemple #17
0
func (c App) QbsFortune() 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})
	c.RenderArgs["fortunes"] = fortunes
	return c.RenderTemplate("App/Fortune.html")
}
Exemple #18
0
Fichier : k.go Projet : rose312/mzr
func do(w http.ResponseWriter, r *http.Request) {
	q, _ := qbs.GetQbs()
	if q == nil {
		return
	}
	defer q.Close()
	proc := new(Process)
	proc.Id = 100
	proc.Name = "Process"
	q.Save(proc)
	w.Write([]byte("Process"))
}
Exemple #19
0
// 列出用户所有项目
func (this *Project) FindByOwner(ownerId int64) (obj []*models.Project) {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	err = q.WhereEqual("owner_id", ownerId).OrderByDesc("updated").FindAll(&obj)
	if err != nil {
		return nil
	}
	return
}
Exemple #20
0
func (c *Admin) ListCategory() revel.Result {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	var categories []*models.Category
	err = q.FindAll(&categories)

	return c.Render(categories)
}
Exemple #21
0
// 因为Project没有聚集索引 所以直接使用这个
func (this *Project) GetById(id int64) *models.Project {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	obj := &models.Project{Id: id}
	q.Find(obj)
	if obj.Name == "" {
		return nil
	}
	return obj
}
Exemple #22
0
func (this *UserCode) GetByCode(code string) *models.UserCode {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	obj := &models.UserCode{}
	q.WhereEqual("code", code).Find(obj)
	if obj.Id == 0 {
		return nil
	}
	return obj
}
Exemple #23
0
func (this *User) GetBy(key string, value interface{}) *models.User {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	obj := &models.User{}
	q.WhereEqual(key, value).Find(obj)
	if obj.Username != "" {
		return obj
	}
	return nil
}
func ShraniSporocilo(nick string, title string, msg string) (error, *Sporocilo) {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
		return err, nil
	}
	sp := new(Sporocilo)
	sp.Nick = nick
	sp.Title = title
	sp.Msg = msg
	_, err2 := q.Save(sp)
	return err2, sp
}
Exemple #25
0
func (this *UserCode) GetById(id int64) *models.UserCode {
	//////////////////
	q, err := qbs.GetQbs()
	assetsError(err)
	defer q.Close()
	//////////////////
	obj := &models.UserCode{Id: id}
	q.Find(obj)
	if obj.Code == "" {
		return nil
	}
	return obj
}
Exemple #26
0
func CheckSignin(name, password string) *User {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	user := new(User)
	condition := qbs.NewCondition("name = ?", name).And(
		"hashed_password = ?", EncryptPassword(password))
	q.Condition(condition).Find(user)

	return user
}
Exemple #27
0
func (u *User) HasEmail() bool {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	user := new(User)
	q.WhereEqual("email", u.Email).Find(user)

	if user.Id > 0 {
		return true
	}
	return false
}
Exemple #28
0
func GetCategories() []*Category {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	var categories []*Category
	err = q.FindAll(&categories)
	if err != nil {
		fmt.Println(err)
	}

	return categories
}
Exemple #29
0
func (self *qbsWrappedUdid) applyPolicy(pb PBundle, fn func(*qbs.Qbs) (interface{}, error)) (result_obj interface{}, result_error error) {
	q, err := qbs.GetQbs()
	if err != nil {
		return nil, err
	}
	defer q.Close()
	tx := self.store.Policy.StartTransaction(q)
	defer func() {
		if x := recover(); x != nil {
			result_obj, result_error = self.store.Policy.HandlePanic(tx, x)
		}
	}()
	value, err := fn(tx)
	return self.store.Policy.HandleResult(tx, value, err)
}
Exemple #30
0
func (c *Category) Save() bool {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer q.Close()

	_, err = q.Save(c)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}