dagwriter

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2021 License: Apache-2.0, MIT Imports: 2 Imported by: 0

README

go-dagwriter

DagWriter is the glue for mutating (adding, removing) ipld nodes in a block service.

Usage

import (
    "context"

    "github.com/ipfs/go-dagwriter"
    "github.com/ipld/go-ipld-prime"
    cidlink "github.com/ipld/go-ipld-prime/linking/cid"
    "github.com/ipfs/go-cid"
)

...
linkPrototype := cidlink.LinkPrototype{cid.Prefix{
    Version: 1, Codec: 0x71, MhType: 0x17, MhLength: 20,
}}

writer := dagwriter.NewDagWriter(blockService)

// Store ipldNode in the block service
link, err := writer.Store(ipld.LinkContext{}, linkPrototype, ipldNode)
if err != nil {
    panic(err)
}
...

// Remove the node from the block service.
if err := writer.Delete(context.Background(), link); err != nil {
    panic(err)
}

Contribute

PRs are welcome!

License

The go-dagwriter project is dual-licensed under Apache 2.0 and MIT terms:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DagBatchWriter

type DagBatchWriter interface {
	DagWriter
	// Commit executes the queued operations to the underlying data store
	Commit() error
}

DagBatchWriter is a DagWriter that allows queing up several write and delete commands to an underlying store, then executing them in a single commit

type DagWriter

type DagWriter interface {
	// Store stores the given ipld.Node in the underlying store, constructing a link/CID
	// from the data in the node and the provided LinkPrototype
	Store(lnkCtx ipld.LinkContext, lp ipld.LinkPrototype, n ipld.Node) (ipld.Link, error)
	// Delete deletes the node matching the given link from the underlying store
	Delete(ctx context.Context, lnk ipld.Link) error
}

DagWriter provides access for writing and deleting ipld.Nodes in an underlying store Note: on its own, the dag writer provides no methods for loading/reading nodes

type DagWritingService

type DagWritingService interface {
	DagWriter
	// NewBatchWriter instantiates a new multi-operation write/delete
	NewBatchWriter() DagBatchWriter
}

DagWritingService provides both methods for writing and deleting ipld.Nodes atomically, and for instantiating batch operations

Directories

Path Synopsis
impl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL