本文整理匯總了Golang中github.com/cayleygraph/cayley/graph/proto.LogDelta類的典型用法代碼示例。如果您正苦於以下問題:Golang LogDelta類的具體用法?Golang LogDelta怎麽用?Golang LogDelta使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了LogDelta類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Quad
func (qs *QuadStore) Quad(k graph.Value) quad.Quad {
var d proto.LogDelta
tok := k.(*Token)
err := qs.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(tok.bucket)
data := b.Get(tok.key)
if data == nil {
return nil
}
var in proto.HistoryEntry
err := in.Unmarshal(data)
if err != nil {
return err
}
if len(in.History) == 0 {
return nil
}
b = tx.Bucket(logBucket)
data = b.Get(qs.createDeltaKeyFor(int64(in.History[len(in.History)-1])))
if data == nil {
// No harm, no foul.
return nil
}
return d.Unmarshal(data)
})
if err != nil {
clog.Errorf("Error getting quad: %v", err)
return quad.Quad{}
}
return d.Quad.ToNative()
}
示例2: deltaToProto
func deltaToProto(delta graph.Delta) proto.LogDelta {
var newd proto.LogDelta
newd.ID = uint64(delta.ID.Int())
newd.Action = int32(delta.Action)
newd.Timestamp = delta.Timestamp.UnixNano()
newd.Quad = proto.MakeQuad(delta.Quad)
return newd
}
示例3: upgrade2To3
func upgrade2To3(db *bolt.DB) error {
fmt.Println("Upgrading v2 to v3...")
tx, err := db.Begin(true)
if err != nil {
return err
}
defer tx.Rollback()
fmt.Println("Upgrading bucket", string(logBucket))
lb := tx.Bucket(logBucket)
c := lb.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var delta proto.LogDelta
err := delta.Unmarshal(v)
if err != nil {
return err
}
delta.Quad.Upgrade()
data, err := delta.Marshal()
if err != nil {
return err
}
lb.Put(k, data)
}
if err := tx.Commit(); err != nil {
return err
}
tx, err = db.Begin(true)
if err != nil {
return err
}
defer tx.Rollback()
fmt.Println("Upgrading bucket", string(nodeBucket))
nb := tx.Bucket(nodeBucket)
c = nb.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var vd proto.NodeData
err := vd.Unmarshal(v)
if err != nil {
return err
}
vd.Upgrade()
data, err := vd.Marshal()
if err != nil {
return err
}
nb.Put(k, data)
}
if err := tx.Commit(); err != nil {
return err
}
return nil
}
示例4: deltaToProto
func deltaToProto(delta graph.Delta) proto.LogDelta {
var newd proto.LogDelta
newd.ID = uint64(delta.ID.Int())
newd.Action = int32(delta.Action)
newd.Timestamp = delta.Timestamp.UnixNano()
newd.Quad = &proto.Quad{
Subject: delta.Quad.Subject,
Predicate: delta.Quad.Predicate,
Object: delta.Quad.Object,
Label: delta.Quad.Label,
}
return newd
}