db

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeNotFound node not found
	ErrNodeNotFound = errors.New("node not found")
	// ErrFarmNotFound farm not found
	ErrFarmNotFound = errors.New("farm not found")
	//ErrViewNotFound
	ErrNodeResourcesViewNotFound = errors.New("ERROR: relation \"nodes_resources_view\" does not exist (SQLSTATE 42P01)")
)

Functions

This section is empty.

Types

type DBContract

type DBContract struct {
	ContractID        uint
	TwinID            uint
	State             string
	CreatedAt         uint
	Name              string
	NodeID            uint
	DeploymentData    string
	DeploymentHash    string
	NumberOfPublicIps uint
	Type              string
	ContractBillings  string
}

DBContract is contract info

type Database

type Database interface {
	GetCounters(filter types.StatsFilter) (types.Counters, error)
	GetNode(nodeID uint32) (Node, error)
	GetFarm(farmID uint32) (Farm, error)
	GetNodes(filter types.NodeFilter, limit types.Limit) ([]Node, uint, error)
	GetFarms(filter types.FarmFilter, limit types.Limit) ([]Farm, uint, error)
	GetTwins(filter types.TwinFilter, limit types.Limit) ([]types.Twin, uint, error)
	GetContracts(filter types.ContractFilter, limit types.Limit) ([]DBContract, uint, error)
	UpsertNodesGPU(nodesGPU []types.NodeGPU) error
}

Database interface for storing and fetching grid info

func NewPostgresDatabase

func NewPostgresDatabase(host string, port int, user, password, dbname string) (Database, error)

NewPostgresDatabase returns a new postgres db client

type Farm

type Farm struct {
	Name            string
	FarmID          int
	TwinID          int
	PricingPolicyID int
	Certification   string
	StellarAddress  string
	Dedicated       bool
	PublicIps       string
}

Farm data about a farm which is calculated from the chain

type Node

type Node struct {
	ID              string
	NodeID          int64
	FarmID          int64
	TwinID          int64
	Country         string
	GridVersion     int64
	City            string
	Uptime          int64
	Created         int64
	FarmingPolicyID int64
	UpdatedAt       int64
	TotalCru        int64
	TotalMru        int64
	TotalSru        int64
	TotalHru        int64
	UsedCru         int64
	UsedMru         int64
	UsedSru         int64
	UsedHru         int64
	Domain          string
	Gw4             string
	Gw6             string
	Ipv4            string
	Ipv6            string
	Certification   string
	Dedicated       bool
	RentContractID  int64
	RentedByTwinID  int64
	SerialNumber    string
	Longitude       *float64
	Latitude        *float64
	Power           NodePower `gorm:"type:jsonb"`
	NumGPU          int       `gorm:"num_gpu"`
	ExtraFee        uint64
}

Node data about a node which is calculated from the chain

type NodeGPU

type NodeGPU struct {
	NodeTwinID int    `gorm:"primaryKey;autoIncrement:false"`
	ID         string `gorm:"primaryKey"`
	Vendor     string
	Device     string
	Contract   int
}

func (NodeGPU) TableName

func (NodeGPU) TableName() string

type NodePower

type NodePower struct {
	State  string `json:"state"`
	Target string `json:"target"`
}

NodePower struct is the farmerbot report for node status

func (*NodePower) Scan

func (np *NodePower) Scan(value interface{}) error

Scan is a custom decoder for jsonb filed. executed while scanning the node.

type NodesDistribution

type NodesDistribution struct {
	Country string `json:"country"`
	Nodes   int64  `json:"nodes"`
}

NodesDistribution is the number of nodes per each country

type PostgresDatabase

type PostgresDatabase struct {
	// contains filtered or unexported fields
}

PostgresDatabase postgres db client

func (*PostgresDatabase) Close

func (d *PostgresDatabase) Close() error

Close the db connection

func (*PostgresDatabase) GetContracts

func (d *PostgresDatabase) GetContracts(filter types.ContractFilter, limit types.Limit) ([]DBContract, uint, error)

GetContracts returns contracts filtered and paginated

func (*PostgresDatabase) GetCounters

func (d *PostgresDatabase) GetCounters(filter types.StatsFilter) (types.Counters, error)

GetCounters returns aggregate info about the grid

func (*PostgresDatabase) GetFarm

func (d *PostgresDatabase) GetFarm(farmID uint32) (Farm, error)

GetFarm return farm info

func (*PostgresDatabase) GetFarms

func (d *PostgresDatabase) GetFarms(filter types.FarmFilter, limit types.Limit) ([]Farm, uint, error)

GetFarms return farms filtered and paginated

func (*PostgresDatabase) GetNode

func (d *PostgresDatabase) GetNode(nodeID uint32) (Node, error)

GetNode returns node info

func (*PostgresDatabase) GetNodes

func (d *PostgresDatabase) GetNodes(filter types.NodeFilter, limit types.Limit) ([]Node, uint, error)

GetNodes returns nodes filtered and paginated

func (*PostgresDatabase) GetTwins

func (d *PostgresDatabase) GetTwins(filter types.TwinFilter, limit types.Limit) ([]types.Twin, uint, error)

GetTwins returns twins filtered and paginated

func (*PostgresDatabase) UpsertNodesGPU

func (p *PostgresDatabase) UpsertNodesGPU(nodesGPU []types.NodeGPU) error

Jump to

Keyboard shortcuts

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