diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-21 22:34:54 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-21 22:34:54 -0600 |
commit | 0e4d77d424b2f18c76da7643de88b462b86310f2 (patch) | |
tree | 3b2e834d1563bc2ce856f224973cc5d262a2a708 /tx.go | |
parent | Add 'bolt keys'. (diff) | |
download | dedo-0e4d77d424b2f18c76da7643de88b462b86310f2.tar.gz dedo-0e4d77d424b2f18c76da7643de88b462b86310f2.tar.xz |
Add 'bolt pages'.
Diffstat (limited to 'tx.go')
-rw-r--r-- | tx.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -420,3 +420,30 @@ func (t *Tx) forEachPage(pgid pgid, depth int, fn func(*page, int)) { } } } + +// Page returns page information for a given page number. +// This is only available from writable transactions. +func (t *Tx) Page(id int) (*PageInfo, error) { + if !t.writable { + return nil, ErrTxNotWritable + } else if pgid(id) >= t.meta.pgid { + return nil, nil + } + + // Build the page info. + p := t.page(pgid(id)) + info := &PageInfo{ + ID: id, + Count: int(p.count), + OverflowCount: int(p.overflow), + } + + // Determine the type (or if it's free). + if t.db.freelist.isFree(pgid(id)) { + info.Type = "free" + } else { + info.Type = p.typ() + } + + return info, nil +} |