Esempio n. 1
0
func (ls *LevelDBStore) GetSlice(limit int64, offset int64) (posts []*postmi.Post, e error) {
	iter := ls.db.NewIterator(util.BytesPrefix([]byte("p")), nil)
	iter.Last()
	var p *postmi.Post
	p, e = postmi.NewPostFromJSON(iter.Value())
	if e != nil {
		return
	}
	posts = append(posts, p)
	for iter.Prev() {
		offset--
		if offset > 0 {
			continue
		}
		p, e = postmi.NewPostFromJSON(iter.Value())
		if e != nil {
			break
		}
		posts = append(posts, p)
		if int64(len(posts)) == limit {
			break
		}
	}
	iter.Release()
	if e != nil {
		return
	}
	e = iter.Error()
	return
}
Esempio n. 2
0
func (ls *LevelDBStore) Get(id int64) (*postmi.Post, error) {
	bts, e := ls.db.Get(idKey(id), nil)
	if e != nil {
		return nil, e
	}
	return postmi.NewPostFromJSON(bts)
}