Documentation ¶
Overview ¶
Package gouchstore implements native Go access to couchstore files. See https://github.com/couchbase/couchstore for more information about couchstore.
Usage:
db, err := gouchstore.Open("database.couch")
To fetch a document by ID:
doc, err := db.DocumentById("docid")
To list all keys, create a callback:
func callback(g *gouchstore.Gouchstore, docInfo *gouchstore.DocumentInfo, userContext interface{}) { fmt.Printf("ID: %s", docInfo.ID) }
Then:
err = db.AllDocuments("", "", callback, nil)
Index ¶
- Constants
- type BaseGouchOps
- func (g *BaseGouchOps) Close(f *os.File) error
- func (g *BaseGouchOps) CompactionTreeWriter(keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, ...) (TreeWriter, error)
- func (g *BaseGouchOps) GotoEOF(f *os.File) (ret int64, err error)
- func (g *BaseGouchOps) OpenFile(name string, flag int, perm os.FileMode) (file *os.File, err error)
- func (g *BaseGouchOps) ReadAt(f *os.File, b []byte, off int64) (n int, err error)
- func (g *BaseGouchOps) SnappyDecode(dst, src []byte) ([]byte, error)
- func (g *BaseGouchOps) SnappyEncode(dst, src []byte) []byte
- func (g *BaseGouchOps) Sync(f *os.File) error
- func (g *BaseGouchOps) WriteAt(f *os.File, b []byte, off int64) (n int, err error)
- type BulkWriter
- type DatabaseInfo
- type Document
- type DocumentInfo
- type DocumentInfoCallback
- type DocumentWalkFun
- type GouchOps
- type Gouchstore
- func (g *Gouchstore) AllDocuments(startId, endId string, cb DocumentInfoCallback, userContext interface{}) error
- func (db *Gouchstore) Bulk() BulkWriter
- func (g *Gouchstore) ChangesSince(since uint64, till uint64, cb DocumentInfoCallback, userContext interface{}) error
- func (g *Gouchstore) Close() error
- func (g *Gouchstore) Commit() error
- func (g *Gouchstore) Compact(targetFilename string) error
- func (g *Gouchstore) DatabaseInfo() (*DatabaseInfo, error)
- func (g *Gouchstore) DebugAddress(w io.Writer, offsetAddress int64, printRawBytes, readLargeChunk bool, ...) error
- func (g *Gouchstore) DocumentBodyById(id string) ([]byte, error)
- func (g *Gouchstore) DocumentByDocumentInfo(docInfo *DocumentInfo) (*Document, error)
- func (g *Gouchstore) DocumentByDocumentInfoNoAlloc(docInfo *DocumentInfo, doc *Document) error
- func (g *Gouchstore) DocumentById(id string) (*Document, error)
- func (g *Gouchstore) DocumentByIdNoAlloc(id string, doc *Document) error
- func (g *Gouchstore) DocumentInfoById(id string) (*DocumentInfo, error)
- func (g *Gouchstore) DocumentInfoByIdNoAlloc(id string, docInfo *DocumentInfo) error
- func (g *Gouchstore) DocumentInfoBySeq(seq uint64) (*DocumentInfo, error)
- func (g *Gouchstore) DocumentInfosByIds(identifiers []string) ([]*DocumentInfo, error)
- func (g *Gouchstore) DocumentInfosBySeqs(sequences []uint64) ([]*DocumentInfo, error)
- func (g *Gouchstore) LocalDocumentById(id string) (*LocalDocument, error)
- func (g *Gouchstore) SaveDocument(doc *Document, docInfo *DocumentInfo) error
- func (g *Gouchstore) SaveDocuments(docs []*Document, docInfos []*DocumentInfo) error
- func (g *Gouchstore) SaveLocalDocument(localDoc *LocalDocument) error
- func (db *Gouchstore) WalkDocs(startkey, endkey string, callback DocumentWalkFun) error
- func (g *Gouchstore) WalkIdTree(startId, endId string, wtcb WalkTreeCallback, userContext interface{}) error
- func (g *Gouchstore) WalkLocalDocsTree(startId, endId string, wtcb WalkTreeCallback, userContext interface{}) error
- func (g *Gouchstore) WalkSeqTree(since uint64, till uint64, wtcb WalkTreeCallback, userContext interface{}) error
- type InMemoryTreeWriter
- type LocalDocument
- type LogGouchOps
- func (g *LogGouchOps) Close(f *os.File) error
- func (g *LogGouchOps) GotoEOF(f *os.File) (ret int64, err error)
- func (g *LogGouchOps) OpenFile(name string, flag int, perm os.FileMode) (file *os.File, err error)
- func (g *LogGouchOps) ReadAt(f *os.File, b []byte, off int64) (n int, err error)
- func (g *LogGouchOps) Sync(f *os.File) error
- func (g *LogGouchOps) WriteAt(f *os.File, b []byte, off int64) (n int, err error)
- type MemCompactGouchOps
- type OnDiskTreeWriter
- type TreeWriter
- type WalkTreeCallback
Constants ¶
const ( COMPACT_KEEP_ITEM int = 0 COMPACT_DROP_ITEM int = 1 )
const ( OPEN_CREATE int = 1 OPEN_RDONLY int = 2 )
const (
DOC_IS_COMPRESSED byte = 128
)
const ID_SORT_CHUNK_SIZE = (10 * 1024 * 1024) // 10MB. Make tuneable?
FIXME this isn't really MB right? its a count of items, not their size
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseGouchOps ¶
type BaseGouchOps struct{}
func NewBaseGouchOps ¶
func NewBaseGouchOps() *BaseGouchOps
func (*BaseGouchOps) CompactionTreeWriter ¶
func (g *BaseGouchOps) CompactionTreeWriter(keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, reduceContext interface{}) (TreeWriter, error)
func (*BaseGouchOps) SnappyDecode ¶
func (g *BaseGouchOps) SnappyDecode(dst, src []byte) ([]byte, error)
func (*BaseGouchOps) SnappyEncode ¶
func (g *BaseGouchOps) SnappyEncode(dst, src []byte) []byte
type BulkWriter ¶
type BulkWriter interface { // Set a document. Set(*DocumentInfo, *Document) // Delete a document. Delete(*DocumentInfo) // Commit the current batch. Commit() error // Shut down this bulk interface. Close() error }
type DatabaseInfo ¶
type DatabaseInfo struct { FileName string `json:"fileName"` // filesystem path LastSeq uint64 `json:"lastSeq"` // last sequence number allocated DocumentCount uint64 `json:"documentCount"` // total number of (non-deleted) documents DeletedCount uint64 `json:"deletedCount"` // total number of deleted documents SpaceUsed uint64 `json:"spaceUsed"` // disk space actively used by docs FileSize uint64 `json:"fileSize"` // total disk space used by database HeaderPosition uint64 `json:"headerPosition"` // file offset of current header }
DatabaseInfo describes the database as a whole.
type DocumentInfo ¶
type DocumentInfo struct { ID string `json:"id"` // document identifier Seq uint64 `json:"seq"` // sequence number in database Rev uint64 `json:"rev"` // revision number of document RevMeta []byte `json:"revMeta"` // additional revision meta-data (uninterpreted by Gouchstore) ContentMeta uint8 `json:"contentMeta"` // content meta-data flags Deleted bool `json:"deleted"` // is the revision deleted? Size uint64 `json:"size"` // size of document data in bytes // contains filtered or unexported fields }
DocumentInfo is document meta-data.
func NewDocumentInfo ¶
func NewDocumentInfo(id string) *DocumentInfo
func (*DocumentInfo) String ¶
func (di *DocumentInfo) String() string
type DocumentInfoCallback ¶
type DocumentInfoCallback func(gouchstore *Gouchstore, documentInfo *DocumentInfo, userContext interface{}) error
DocumentInfoCallback is a function definition which is used for document iteration. For example, when iterating all documents with the AllDocuments() method, the provided callback will be invoked for each document in the database.
type DocumentWalkFun ¶
type DocumentWalkFun func(db *Gouchstore, di *DocumentInfo, doc *Document) error
type GouchOps ¶
type GouchOps interface { OpenFile(name string, flag int, perm os.FileMode) (file *os.File, err error) ReadAt(f *os.File, b []byte, off int64) (n int, err error) WriteAt(f *os.File, b []byte, off int64) (n int, err error) GotoEOF(f *os.File) (ret int64, err error) Sync(f *os.File) error CompactionTreeWriter(keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, reduceContext interface{}) (TreeWriter, error) SnappyEncode(dst, src []byte) []byte SnappyDecode(dst, src []byte) ([]byte, error) Close(f *os.File) error }
GouchOps an interface for plugging in differentl implementations of some common low-level operations
type Gouchstore ¶
type Gouchstore struct {
// contains filtered or unexported fields
}
Gouchstore gives access to a couchstore database file.
func Open ¶
func Open(filename string, options int) (*Gouchstore, error)
Open attemps to open an existing couchstore file.
All Gouchstore files successfully opened should be closed with the Close() method.
func (*Gouchstore) AllDocuments ¶
func (g *Gouchstore) AllDocuments(startId, endId string, cb DocumentInfoCallback, userContext interface{}) error
AllDocuments will iterate through all documents in the database in ascending ID order, from startId (inclusive) through endId (inclusive). For each document, the provided DocumentInfoCallback will be invoked. A user specified context can be included, and this will be passed to each invocation of the callback.
If startId is the empty string, the iteration will start with the first document.
If endId is the empty string, the iteration will continue to the last document.
func (*Gouchstore) Bulk ¶
func (db *Gouchstore) Bulk() BulkWriter
Get a bulk writer.
You must call Close() on the bulk writer when you're done bulk writing.
func (*Gouchstore) ChangesSince ¶
func (g *Gouchstore) ChangesSince(since uint64, till uint64, cb DocumentInfoCallback, userContext interface{}) error
ChangesSince will iterate through all documents in the database in ascending sequence number order, from since (inclusive) through till (inclusive). For each document, the provided DocumentInfoCallback will be invoked. A user specified context can be included, and this will be passed to each invocation of the callback.
If since is 0, the iteration will start with the first document.
If endId is 0, the iteration will continue to the last document.
func (*Gouchstore) Close ¶
func (g *Gouchstore) Close() error
Close will close the underlying file handle and release any resources associated with the Gouchstore object.
func (*Gouchstore) Commit ¶
func (g *Gouchstore) Commit() error
func (*Gouchstore) Compact ¶
func (g *Gouchstore) Compact(targetFilename string) error
func (*Gouchstore) DatabaseInfo ¶
func (g *Gouchstore) DatabaseInfo() (*DatabaseInfo, error)
DatabaseInfo returns information describing the database itself.
func (*Gouchstore) DebugAddress ¶
func (*Gouchstore) DocumentBodyById ¶
func (g *Gouchstore) DocumentBodyById(id string) ([]byte, error)
func (*Gouchstore) DocumentByDocumentInfo ¶
func (g *Gouchstore) DocumentByDocumentInfo(docInfo *DocumentInfo) (*Document, error)
DocumentByDocumentInfo returns the Document using the provided DocumentInfo. The provided DocumentInfo should be valid, such as one received by one of the DocumentInfo*() methods, on the current couchstore file.
func (*Gouchstore) DocumentByDocumentInfoNoAlloc ¶
func (g *Gouchstore) DocumentByDocumentInfoNoAlloc(docInfo *DocumentInfo, doc *Document) error
func (*Gouchstore) DocumentById ¶
func (g *Gouchstore) DocumentById(id string) (*Document, error)
DocumentById returns the Document with the specified identifier.
func (*Gouchstore) DocumentByIdNoAlloc ¶
func (g *Gouchstore) DocumentByIdNoAlloc(id string, doc *Document) error
func (*Gouchstore) DocumentInfoById ¶
func (g *Gouchstore) DocumentInfoById(id string) (*DocumentInfo, error)
DocumentInfoById returns DocumentInfo for a single document with the specified ID.
func (*Gouchstore) DocumentInfoByIdNoAlloc ¶
func (g *Gouchstore) DocumentInfoByIdNoAlloc(id string, docInfo *DocumentInfo) error
func (*Gouchstore) DocumentInfoBySeq ¶
func (g *Gouchstore) DocumentInfoBySeq(seq uint64) (*DocumentInfo, error)
DocumentInfoBySeq returns DocumentInfo for a single document with the specified sequence number.
func (*Gouchstore) DocumentInfosByIds ¶
func (g *Gouchstore) DocumentInfosByIds(identifiers []string) ([]*DocumentInfo, error)
DocumentInfosByIds returns DocumentInfo objects for the specified document IDs. This will be more efficient than making consecutive calls to DocumentInfoById().
NOTE: contents of the result slice will be in ascending ID order, not the order they appeared in the argument list.
func (*Gouchstore) DocumentInfosBySeqs ¶
func (g *Gouchstore) DocumentInfosBySeqs(sequences []uint64) ([]*DocumentInfo, error)
DocumentInfosBySeqs returns DocumentInfo objects for the specified document sequence numbers. This will be more efficient than making consecutive calls to DocumentInfoBySeq().
NOTE: contents of the result slice will be in ascending sequence order, not the order they appeared in the argument list.
func (*Gouchstore) LocalDocumentById ¶
func (g *Gouchstore) LocalDocumentById(id string) (*LocalDocument, error)
LocalDocumentById returns the LocalDocument with the specified identifier.
func (*Gouchstore) SaveDocument ¶
func (g *Gouchstore) SaveDocument(doc *Document, docInfo *DocumentInfo) error
SaveDocument stores the document, if doc is nil, the document will be deleted
func (*Gouchstore) SaveDocuments ¶
func (g *Gouchstore) SaveDocuments(docs []*Document, docInfos []*DocumentInfo) error
SaveDocuments stores multiple documents at a time
func (*Gouchstore) SaveLocalDocument ¶
func (g *Gouchstore) SaveLocalDocument(localDoc *LocalDocument) error
SaveLocalDocument stores local documents in the database
func (*Gouchstore) WalkDocs ¶
func (db *Gouchstore) WalkDocs(startkey, endkey string, callback DocumentWalkFun) error
Walk the DB from a specific location including the complete docs.
func (*Gouchstore) WalkIdTree ¶
func (g *Gouchstore) WalkIdTree(startId, endId string, wtcb WalkTreeCallback, userContext interface{}) error
func (*Gouchstore) WalkLocalDocsTree ¶
func (g *Gouchstore) WalkLocalDocsTree(startId, endId string, wtcb WalkTreeCallback, userContext interface{}) error
func (*Gouchstore) WalkSeqTree ¶
func (g *Gouchstore) WalkSeqTree(since uint64, till uint64, wtcb WalkTreeCallback, userContext interface{}) error
type InMemoryTreeWriter ¶
type InMemoryTreeWriter struct {
// contains filtered or unexported fields
}
func NewInMemoryTreeWriter ¶
func NewInMemoryTreeWriter(keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, reduceContext interface{}) (*InMemoryTreeWriter, error)
func (*InMemoryTreeWriter) AddItem ¶
func (imt *InMemoryTreeWriter) AddItem(key, value []byte) error
func (*InMemoryTreeWriter) Close ¶
func (imt *InMemoryTreeWriter) Close() error
func (*InMemoryTreeWriter) Sort ¶
func (imt *InMemoryTreeWriter) Sort() error
func (*InMemoryTreeWriter) Write ¶
func (imt *InMemoryTreeWriter) Write(db *Gouchstore) (*nodePointer, error)
type LocalDocument ¶
LocalDocument represents a local (non-replicated) document.
type LogGouchOps ¶
type LogGouchOps struct {
*BaseGouchOps
}
func NewLogGouchOps ¶
func NewLogGouchOps() *LogGouchOps
type MemCompactGouchOps ¶
type MemCompactGouchOps struct {
*BaseGouchOps
}
func NewMemCompactGouchOps ¶
func NewMemCompactGouchOps() *MemCompactGouchOps
func (*MemCompactGouchOps) CompactionTreeWriter ¶
func (g *MemCompactGouchOps) CompactionTreeWriter(keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, reduceContext interface{}) (TreeWriter, error)
type OnDiskTreeWriter ¶
type OnDiskTreeWriter struct {
// contains filtered or unexported fields
}
func NewOnDiskTreeWriter ¶
func NewOnDiskTreeWriter(unsortedFilePath string, keyCompare btreeKeyComparator, reduce, rereduce reduceFunc, reduceContext interface{}) (*OnDiskTreeWriter, error)
func (*OnDiskTreeWriter) AddItem ¶
func (imt *OnDiskTreeWriter) AddItem(key, value []byte) error
func (*OnDiskTreeWriter) Close ¶
func (imt *OnDiskTreeWriter) Close() error
func (*OnDiskTreeWriter) Sort ¶
func (imt *OnDiskTreeWriter) Sort() error
func (*OnDiskTreeWriter) Write ¶
func (imt *OnDiskTreeWriter) Write(db *Gouchstore) (*nodePointer, error)
type TreeWriter ¶
type WalkTreeCallback ¶
type WalkTreeCallback func(gouchstore *Gouchstore, depth int, documentInfo *DocumentInfo, key []byte, subTreeSize uint64, reducedValue []byte, userContext interface{}) error
WalkTreeCallback is a function definition which is used for tree walks.