Example #1
0
func (a *ArticleApi) GetByCid(cid string) (db.DataRow, error) {
	q := db.NewQueryBuilder("articles").Select("cid,user_id,title,html,status,created_at,updated_at")
	row, err := q.Where("cid=?", cid).QueryOne()
	if err != nil {
		return nil, err
	}
	if row.Empty() {
		return nil, gos.DoError("没有找到相应的记录")
	}
	row = row.Bytes2String()
	user, err := user.NewUserModel().GetById(row.GetInt64("user_id"))
	if err != nil {
		return nil, err
	}
	user = user.Bytes2String()

	row["user"] = user
	return row, err
}
Example #2
0
func (a *ArticleApi) List(args util.MapData) (db.DataSet, error) {
	nick := args.GetString("nick")
	page := args.GetInt("page")

	q := db.NewQueryBuilder("articles").
		Page(page, 20).
		Order("id desc").
		Select("cid,title,description,status,created_at")

	if nick != "" {
		u, err := user.NewUserModel().GetByNickAllField(nick)
		if err != nil {
			return nil, err
		}
		if u.Empty() {
			return nil, gos.DoError("没有找到相应的记录", nick)
		}
		q.Where("user_id=?", u.GetInt64("id"))
	}

	ds, err := q.Query()
	return ds.Bytes2String(), err
}