本文整理匯總了Golang中github.com/chop-dbhi/origins/storage.Tx類的典型用法代碼示例。如果您正苦於以下問題:Golang Tx類的具體用法?Golang Tx怎麽用?Golang Tx使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Tx類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetSegment
// GetSegment returns a segment from storage.
func GetSegment(e storage.Tx, domain string, id *uuid.UUID) (*Segment, error) {
var (
bytes []byte
err error
key string
)
key = fmt.Sprintf(segmentKey, id)
if bytes, err = e.Get(domain, key); err != nil {
return nil, err
}
if bytes == nil {
return nil, nil
}
seg := Segment{
UUID: id,
Domain: domain,
}
if err = unmarshalSegment(bytes, &seg); err != nil {
return nil, err
}
return &seg, nil
}
示例2: SetBlock
func SetBlock(e storage.Tx, domain string, id *uuid.UUID, idx int, bytes []byte) (int, error) {
var key string
key = fmt.Sprintf(blockKey, id, idx)
return len(bytes), e.Set(domain, key, bytes)
}
示例3: GetLog
func GetLog(e storage.Tx, domain, name string) (*Log, error) {
var (
bytes []byte
err error
key string
)
key = fmt.Sprintf(logKey, name)
if bytes, err = e.Get(domain, key); err != nil {
return nil, err
}
if bytes == nil {
return nil, nil
}
log := Log{
Domain: domain,
Name: name,
}
if err = unmarshalLog(bytes, &log); err != nil {
return nil, err
}
return &log, nil
}
示例4: GetBlock
// GetBlock returns a block from storage. The lookup requires the domain, ID of the segment
// the block is contained in, the index of the block in the segment, and the transaction
// that processed the segment.
func GetBlock(e storage.Tx, domain string, id *uuid.UUID, idx int) ([]byte, error) {
var key string
key = fmt.Sprintf(blockKey, id, idx)
return e.Get(domain, key)
}
示例5: SetLog
func SetLog(e storage.Tx, domain string, log *Log) (int, error) {
var (
bytes []byte
err error
key string
)
if bytes, err = marshalLog(log); err != nil {
return 0, err
}
key = fmt.Sprintf(logKey, log.Name)
return len(bytes), e.Set(domain, key, bytes)
}
示例6: SetSegment
func SetSegment(e storage.Tx, domain string, segment *Segment) (int, error) {
var (
bytes []byte
err error
key string
)
if bytes, err = marshalSegment(segment); err != nil {
return 0, err
}
key = fmt.Sprintf(segmentKey, segment.UUID)
return len(bytes), e.Set(domain, key, bytes)
}
示例7: DeleteLog
func DeleteLog(e storage.Tx, domain string, name string) error {
key := fmt.Sprintf(logKey, name)
return e.Delete(domain, key)
}
示例8: DeleteBlock
func DeleteBlock(e storage.Tx, domain string, id *uuid.UUID, idx int) error {
key := fmt.Sprintf(blockKey, id, idx)
return e.Delete(domain, key)
}
示例9: DeleteSegment
func DeleteSegment(e storage.Tx, domain string, id *uuid.UUID) error {
key := fmt.Sprintf(segmentKey, id)
return e.Delete(domain, key)
}
示例10: txid
// txid increments a global transaction ID.
func txid(tx storage.Tx) (uint64, error) {
return tx.Incr("origins", "tx")
}