ankadb

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: Apache-2.0 Imports: 17 Imported by: 11

README

AnkaDB

Build Status

AnkaDB is a scalable embedded database with golang.
AnkaDB supports multiple database engines, now LevelDB, and will soon support RocksDB.
AnkaDB is now single-node and will soon support multiple nodes, using the raft protocol.
AnkaDB queries and modifies data with GraphQL.
AnkaDB used GRPC & ProtoBuf v3.

TradingDB is an implementation of AnkaDB.


Update
v0.2
  • Refactor the error module and delete the CODE in the protobuf.
  • Support graphiql
  • Replace chan with context
v0.1
  • Complete basic single node.
  • Support graphql query.
  • Support leveldb.
  • Support http service.
  • Support grpc service.
  • Support local queries.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGRPCListen - grpc service listen err
	ErrGRPCListen = errors.New("grpc service listen err")
	// ErrHTTPListen - http service listen err
	ErrHTTPListen = errors.New("http service listen err")
	// ErrLoadFileReadSize - loadfile invalid file read size
	ErrLoadFileReadSize = errors.New("loadfile invalid file read size")
	// ErrHTTPNoQuery - HTTP no query
	ErrHTTPNoQuery = errors.New("HTTP no query")
	// ErrCtxAnkaDB - context has not ankadb
	ErrCtxAnkaDB = errors.New("context has not ankadb")
	// ErrCtxCurDB - context has not currentdb
	ErrCtxCurDB = errors.New("context has not currentdb")
	// ErrQuertParams - query params err
	ErrQuertParams = errors.New("query params err")
	// ErrQuertResultDecode - query result decode err
	ErrQuertResultDecode = errors.New("query result decode err")
	// ErrCtxSnapshotMgr - query get snapshotMgr from err
	ErrCtxSnapshotMgr = errors.New("query get snapshotMgr from err")
)

Functions

func GetContextValueDatabase

func GetContextValueDatabase(ctx context.Context, key interface{}) database.Database

GetContextValueDatabase -

func GetMsgFromDB

func GetMsgFromDB(db database.Database, key []byte, msg proto.Message) error

GetMsgFromDB - get protobuf message from database

func GetMsgFromParam

func GetMsgFromParam(params graphql.ResolveParams, paramName string, msg proto.Message) error

GetMsgFromParam - get protobuf message from param

func MakeGraphQLErrorResult

func MakeGraphQLErrorResult(err error) *graphql.Result

MakeGraphQLErrorResult -

func MakeMsgFromResult

func MakeMsgFromResult(result *graphql.Result, msg proto.Message) error

MakeMsgFromResult - make protobuf object from graphql.Result

func MakeObjFromResult

func MakeObjFromResult(result *graphql.Result, obj interface{}) error

MakeObjFromResult - make object from graphql.Result

func MakeParamsFromMsg

func MakeParamsFromMsg(params map[string]interface{}, paramName string, msg proto.Message) error

MakeParamsFromMsg - change protobuf message to param

func PutMsg2DB

func PutMsg2DB(db database.Database, key []byte, msg proto.Message) error

PutMsg2DB - put protobuf message to database

Types

type AnkaDB

type AnkaDB struct {
	MgrDB DBMgr
	// contains filtered or unexported fields
}

AnkaDB -

func GetContextValueAnkaDB

func GetContextValueAnkaDB(ctx context.Context, key interface{}) *AnkaDB

GetContextValueAnkaDB -

func NewAnkaDB

func NewAnkaDB(cfg Config, logic DBLogic) (*AnkaDB, error)

NewAnkaDB -

func (*AnkaDB) LocalQuery

func (anka *AnkaDB) LocalQuery(ctx context.Context, request string, values map[string]interface{}) (*graphql.Result, error)

LocalQuery - local query

func (*AnkaDB) Start

func (anka *AnkaDB) Start(ctx context.Context) error

Start -

func (*AnkaDB) Stop

func (anka *AnkaDB) Stop()

Stop -

type Config

type Config struct {
	AddrGRPC   string     `yaml:"addrgrpc"`
	PathDBRoot string     `yaml:"pathdbroot"`
	AddrHTTP   string     `yaml:"addrhttp"`
	ListDB     []DBConfig `yaml:"listdb"`
}

Config -

func LoadConfig

func LoadConfig(cfgfilename string) (*Config, error)

LoadConfig -

func NewConfig

func NewConfig() Config

NewConfig -

type DBConfig

type DBConfig struct {
	Name   string `yaml:"name"`
	Engine string `yaml:"engine"`
	PathDB string `yaml:"pathdb"`
}

DBConfig -

type DBLogic

type DBLogic interface {
	OnQuery(ctx context.Context, request string, values map[string]interface{}) (*graphql.Result, error)
	OnQueryStream(ctx context.Context, request string, values map[string]interface{}, funcOnQueryStream FuncOnQueryStream) error
}

DBLogic -

type DBMgr

type DBMgr interface {
	AddDB(cfg DBConfig) error
	GetDB(name string) database.Database
	GetMgrSnapshot(name string) *SnapshotMgr
}

DBMgr -

func NewDBMgr

func NewDBMgr(lstDB []DBConfig) (DBMgr, error)

NewDBMgr - new DBMgr

type FuncOnQueryStream

type FuncOnQueryStream func(*pb.ReplyQuery)

FuncOnQueryStream - use in DBLogic.OnQueryStream

type SnapshotMgr

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

SnapshotMgr - key list snapshot

func (*SnapshotMgr) Add

func (mgr *SnapshotMgr) Add(pSnapshot *pb.Snapshot) (int64, error)

Add - add snapshot

func (*SnapshotMgr) Get

func (mgr *SnapshotMgr) Get(snapshotid int64) *pb.Snapshot

Get - get snapshot

func (*SnapshotMgr) NewSnapshot

func (mgr *SnapshotMgr) NewSnapshot(prefix []byte) (*pb.Snapshot, error)

NewSnapshot - new snapshot

Directories

Path Synopsis
samples
trading command

Jump to

Keyboard shortcuts

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