Exemplo n.º 1
0
func GetCommentsForType(db *gorp.Transaction, itemtype string) ([]Comment,
	error) {
	var cs []Comment
	_, err := db.Select(&cs, "select * from Comment where"+
		" ItemType = ? and Deleted = 0 order by Id desc",
		itemtype)
	return cs, err
}
Exemplo n.º 2
0
func FindAccountByEmail(txn *gorp.Transaction, email string) *Account {
	accounts, err := txn.Select(Account{}, `select * from accounts where lower(email) = lower($1) limit 1`, email)
	if err != nil {
		panic(err)
	}
	if len(accounts) == 0 {
		return nil
	}
	return accounts[0].(*Account)
}
Exemplo n.º 3
0
func getVotes(db *gorp.Transaction, gid, fid int64) (rate.Rate, error) {
	r := []rate.Rate{}
	_, err := db.Select(&r, "select * from Rate where ItemId = ? and ItemType = ?", gid, fid)
	if err != nil {
		return rate.Rate{}, err
	}
	if len(r) == 1 {
		r[0].Votes, err = getVotesforRate(db, r[0].Id)
		if err != nil {
			return rate.Rate{}, err
		}
		return r[0], nil
	}
	return rate.Rate{}, errors.New(fmt.Sprint("Unexpected error", len(r)))
}
Exemplo n.º 4
0
func createRate(db *gorp.Transaction, guruid int64) error {
	humor := rate.Rate{
		ItemType: 0,
		ItemId:   guruid,
	}
	goodwill := rate.Rate{
		ItemType: 1,
		ItemId:   guruid,
	}
	understandability := rate.Rate{
		ItemType: 2,
		ItemId:   guruid,
	}
	err := db.Insert(&humor, &goodwill, &understandability)
	return err
}
Exemplo n.º 5
0
func createFeatures(db *gorp.Transaction, guruid int64) error {
	humor := GuruFeatures{
		Feature: "humor",
		GuruId:  guruid,
	}
	goodwill := GuruFeatures{
		Feature: "goodwill",
		GuruId:  guruid,
	}
	understandability := GuruFeatures{
		Feature: "understandability",
		GuruId:  guruid,
	}
	err := db.Insert(&humor, &goodwill, &understandability)
	return err
}
Exemplo n.º 6
0
func getVotesforRate(db *gorp.Transaction, rateid int64) ([]rate.Vote, error) {
	r := []rate.Vote{}
	_, err := db.Select(&r, "select * from Vote where RateId = ?", rateid)
	return r, err
}
Exemplo n.º 7
0
func upd(db *gorp.Transaction, r RateLimit) error {
	r.Updated = time.Now().UnixNano()
	_, err := db.Update(&r)
	return err
}
Exemplo n.º 8
0
func setTry(db *gorp.Transaction, r RateLimit) error {
	r.Updated = time.Now().UnixNano()
	r.Count++
	_, err := db.Update(&r)
	return err
}