func (a *Article) GetAll(w io.Writer, q *service.Query) error { stmt, err := db.Prepare("SELECT * FROM lunar.post LIMIT ?, ?") if err != nil { return err } defer stmt.Close() var r bytes.Buffer var ar []*Article rows, err := stmt.Query(q.Offset(), q.Size()) for rows.Next() { t := &Article{} rows.Scan(&t.Id, &t.CategoryId, &t.UserId, &t.ImageId, &t.Title, &t.Slug, &t.Text, &t.Created, &t.Updated, &t.Deleted) ar = append(ar, t) } util.ToJson(&r, &ar) _, err = r.WriteTo(w) return err }
func (a *Article) ToJson(w io.Writer) error { return util.ToJson(w, &a) }