Documentation
¶
Overview ¶
The mock database package allows for testing that are decoupled from a particular database implementation.
Index ¶
- type Database
- func (DB *Database) AddNode(ctx context.Context, pubkey string) (uint32, error)
- func (DB *Database) AllNodes(ctx context.Context) ([]uint32, error)
- func (DB *Database) ContainsNode(ctx context.Context, nodeID uint32) bool
- func (DB *Database) FollowCounts(ctx context.Context, nodeIDs ...uint32) ([]int, error)
- func (DB *Database) FollowerCounts(ctx context.Context, nodeIDs ...uint32) ([]int, error)
- func (DB *Database) Followers(ctx context.Context, nodeIDs ...uint32) ([][]uint32, error)
- func (DB *Database) Follows(ctx context.Context, nodeIDs ...uint32) ([][]uint32, error)
- func (DB *Database) NodeByID(ctx context.Context, nodeID uint32) (*models.Node, error)
- func (DB *Database) NodeByKey(ctx context.Context, pubkey string) (*models.Node, error)
- func (DB *Database) NodeIDs(ctx context.Context, pubkeys ...string) ([]*uint32, error)
- func (DB *Database) Pubkeys(ctx context.Context, nodeIDs ...uint32) ([]*string, error)
- func (DB *Database) ScanNodes(ctx context.Context, cursor uint64, limit int) ([]uint32, uint64, error)
- func (DB *Database) Size(ctx context.Context) int
- func (DB *Database) Update(ctx context.Context, delta *models.Delta) error
- func (DB *Database) Validate() error
- type NodeSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// a map that associates each public key with a unique nodeID
KeyIndex map[string]uint32
// a map that associates each nodeID with its node data
NodeIndex map[uint32]*models.Node
// maps that associate each nodeID with the slice of its follows
Follow map[uint32]NodeSet
Follower map[uint32]NodeSet
// the next nodeID to be used. When a new node is added, this fiels is incremented by one
LastNodeID int
}
simulates a simple graph database for testing.
func GenerateDB ¶
generates a random mock database of a specified number of nodes and successors per node the successor of a node won't include itself, and won't have repetitions
func NewDatabase ¶
func NewDatabase() *Database
NewDatabase() creates and returns a new Database instance.
func (*Database) AddNode ¶
AddNode() adds a node to the database and returns its assigned nodeID. In case of errors, it returns MaxUint32 as the nodeID.
func (*Database) ContainsNode ¶
ContainsNode() returns whether nodeID is found in the DB
func (*Database) FollowCounts ¶
func (*Database) FollowerCounts ¶
func (*Database) NodeIDs ¶
NodeIDs() returns a slice of nodeIDs that correspond with the given slice of pubkeys. If a pubkey is not found, nil is returned
func (*Database) Pubkeys ¶
Pubkeys() returns a slice of pubkeys that correspond with the given slice of nodeIDs. If a pubkey is not found, nil is returned.
func (*Database) ScanNodes ¶
func (DB *Database) ScanNodes(ctx context.Context, cursor uint64, limit int) ([]uint32, uint64, error)
ScanNodes() scans over the nodes and returns all of the nodeIDs, ignoring the limit.