db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

README

db

GoDoc GoReport Travis License Chat Mentioned in Awesome Go

Package db provides embed key/value database for pdu.

The default database used in this project is bolt, more information could be found https://github.com/boltdb/bolt

Overview

This package ...

Documentation

Index

Constants

View Source
const (
	// BucketUser is used to save all users
	BucketUser = "user"

	// BucketMsg is used to save the msg (msg.ID/ msg)
	BucketMsg = "msg"

	// BucketMID is used to save msg.ID by order (order/msg.ID)
	BucketMID = "mid"

	// BucketMOD is used to save msg received sequence (msg.ID/order)
	BucketMOD = "mod"

	// BucketLastMID is used to save last msg.ID by user.ID
	BucketLastMID = "lmid"

	// BucketConfig is used to save config info when universe be created
	BucketConfig = "config"

	// BucketPeer is used to save the peer information
	BucketPeer = "peer"

	// ConfigRoot0 root user which gender is 0
	ConfigRoot0 = "root0"

	// ConfigRoot1 root user which gender is 1
	ConfigRoot1 = "root1"

	// ConfigMsgCount is the current message count in the universe
	ConfigMsgCount = "msg_count"

	// ConfigCurrentStep is the current step of initialize the universe
	// step 0 - create bucket
	// step 1 - roots saved
	ConfigCurrentStep = "current_step"

	// ConfigLocalNodeKey is the local node key
	ConfigLocalNodeKey = "local_node_key"

	// ConfigUniverseDimension is universe dimension, depends on how your view the universe,
	// just related to calculate the distance between two common.Hash in this universe.
	ConfigUniverseDimension = "universe_dimension"

	// ConfigUniversePerimeter is local universe perimeter, same as dimension.
	ConfigUniversePerimeter = "universe_perimeter"

	// ConfigUniverseRedshiftConstant is local constant for dynamice universe model.
	ConfigUniverseRedshiftConstant = "universe_red_shift"
)
View Source
const (
	// StepInitDB is the step which all bucket in db have been created
	StepInitDB = iota

	// StepRootsSaved is the step which two roots have been saved into db
	StepRootsSaved
)

Variables

View Source
var (
	// ErrMessageNotFound returns when the message not be found
	ErrMessageNotFound = errors.New("message can not be found")
)

Functions

func GetLastMsg

func GetLastMsg(udb UDB) (*core.Message, error)

GetLastMsg get the last message by order from db

func GetLastMsgByUser

func GetLastMsgByUser(udb UDB, userID common.Hash) (*core.Message, error)

GetLastMsgByUser return the last message by userID

func GetMsgByOrder

func GetMsgByOrder(udb UDB, start *big.Int, size int) (msgs []*core.Message)

GetMsgByOrder get the message by order, for sync message between peers

func GetMsgCount

func GetMsgCount(udb UDB) (count *big.Int, err error)

GetMsgCount return the message count in local db

func GetOrderCntByMsg

func GetOrderCntByMsg(udb UDB, mid common.Hash) (order *big.Int, count *big.Int, err error)

GetOrderCntByMsg get the message order by msgID

func GetRootUsers

func GetRootUsers(udb UDB) (*core.User, *core.User, error)

GetRootUsers get two root users from db

func SaveMsg

func SaveMsg(udb UDB, msg *core.Message) error

SaveMsg save new msg to db

func SaveRootUsers

func SaveRootUsers(udb UDB, users []*core.User) (err error)

SaveRootUsers is save two root users to db

Types

type Row

type Row struct {
	K string
	V []byte
}

Row is the key/value pair from db

type UDB

type UDB interface {
	Close() error
	CreateBucket(string) error
	DeleteBucket(string) error
	Set(string, string, []byte) error
	Get(string, string) ([]byte, error)
	Del(string, string) error
	Find(string, string, ...int) ([]*Row, error)
}

UDB is a database interface for embed database, default db is bolt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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