ankadb

package module
v0.3.35 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 25 Imported by: 9

README

AnkaDB

Build Status

AnkaDB is a scalable embedded database with golang.
AnkaDB supports multiple database engines, LevelDB and 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.

Key-Value sample is here.
GraphQL sample is here.


Update
v0.6
  • Support raft protocol.
v0.5
  • Support RocksDB.
v0.3
  • Refactor AnkaDB & DBLogic.
  • Add Key-Value interface.
  • Add GraphQL sample.
  • Add test.
  • Add Development Log.
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.

AnkaDB Development Log

Come Here


How To Upgrade v2 To v3
  • change *AnkaDB to AnkaDB.
  • change Config to *Config.
  • change MgrDB to GetDBMgr().
  • remove your dblogic, and use ankadb.NewBaseDBLogic new a DBLogic.
  • Config.ListDB.PathDB doesn't require join Config.PathDBRoot.
  • you can remove all the query result definitions, and use MakeMsgFromResultEx to resolve the query result.

Documentation

Index

Constants

View Source
const AnkaDBCoreVersion = "v0.3.35"

AnkaDBCoreVersion - ankadb core version

View Source
const RequestIDKey = requestID("ankadb")

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")
	// ErrNotFoundDB - not found db
	ErrNotFoundDB = errors.New("not found db")
	// ErrNotFoundKey - not found key
	ErrNotFoundKey = errors.New("not found key")
	// ErrInvalidEvent - invalid event
	ErrInvalidEvent = errors.New("invalid event")
	// ErrNotFoundTemplate - not found template
	ErrNotFoundTemplate = errors.New("not found template")
	// ErrNotInit - not initialization
	ErrNotInit = errors.New("not initialization")
	// ErrParamIsNotMap - param is not a map
	ErrParamIsNotMap = errors.New("param is not a map")
	// ErrResultIsNotMap - result is not a map
	ErrResultIsNotMap = errors.New("result is not a map")
	// ErrDuplicateDB - duplicate name for database
	ErrDuplicateDB = errors.New("duplicate name for database")
)
View Source
var (
	// EventOnStarted - onStarted
	EventOnStarted = "onstarted"
)

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 GetMsgFromIterator added in v0.3.29

func GetMsgFromIterator(it iterator.Iterator, msg proto.Message) error

GetMsgFromIterator - get protobuf message from iterator.Iterator

func GetMsgFromParam

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

GetMsgFromParam - get protobuf message from param

func GetResultError added in v0.2.8

func GetResultError(result *graphql.Result) error

GetResultError - get result error

func GraphQLFormattedErrorArr2Error added in v0.3.26

func GraphQLFormattedErrorArr2Error(errs []gqlerrors.FormattedError) error

GraphQLFormattedErrorArr2Error - []gqlerrors.FormattedError to error

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 MakeMsgFromResultEx added in v0.3.26

func MakeMsgFromResultEx(result *graphql.Result, name string, msg proto.Message) error

MakeMsgFromResultEx - 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 Msg2Map added in v0.3.26

func Msg2Map(msg proto.Message) map[string]interface{}

Msg2Map - protobuf message to map

func ParseQuery added in v0.3.26

func ParseQuery(schema *graphql.Schema, query string, name string) (*ast.Document, []gqlerrors.FormattedError)

ParseQuery - parse graphql query

func PutMsg2DB

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

PutMsg2DB - put protobuf message to database

Types

type AnkaDB

type AnkaDB interface {
	// Start - start service
	Start(ctx context.Context) error

	// Query - query
	Query(ctx context.Context, request string, values map[string]interface{}) (*graphql.Result, error)

	// SetQueryTemplate - set query template
	SetQueryTemplate(templateName string, request string) error

	// Get - get value
	Get(ctx context.Context, dbname string, key string) ([]byte, error)
	// Set - set value
	Set(ctx context.Context, dbname string, key string, value []byte) error
	// Delete - deletes the key from database
	Delete(ctx context.Context, dbname string, key string) error

	// GetEx - get value
	GetEx(ctx context.Context, dbname string, key []byte) ([]byte, error)
	// SetEx - set value
	SetEx(ctx context.Context, dbname string, key []byte, value []byte) error
	// Delete - deletes the key from database
	DeleteEx(ctx context.Context, dbname string, key []byte) error

	// ForEachWithPrefix - for each with prefix
	ForEachWithPrefix(ctx context.Context, dbname string, prefix string, foreach FuncAnkaDBForEach) error

	// RegEventFunc - register a function for event
	RegEventFunc(event string, eventfunc FuncAnkaDBEvent) error

	// GetConfig - get config
	GetConfig() *Config
	// GetLogic - get DBLogic
	GetLogic() DBLogic
	// GetDBMgr - get DBMgr
	GetDBMgr() DBMgr

	// GetDatabase - get databse with dbname
	GetDatabase(dbname string) database.Database
	// AddDatabase - add database
	AddDatabase(dbcfg DBConfig) error
}

AnkaDB - AnkaDB interface

func GetContextValueAnkaDB

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

GetContextValueAnkaDB -

func NewAnkaDB

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

NewAnkaDB -

type BaseDBLogic added in v0.3.26

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

BaseDBLogic - base DBLogic

func NewBaseDBLogic added in v0.3.26

func NewBaseDBLogic(cfg graphql.SchemaConfig) (*BaseDBLogic, error)

NewBaseDBLogic - new BaseDBLogic

func (*BaseDBLogic) GetScheme added in v0.3.26

func (logic *BaseDBLogic) GetScheme() *graphql.Schema

GetScheme - get GraphQL scheme

func (*BaseDBLogic) Query added in v0.3.26

func (logic *BaseDBLogic) Query(ctx context.Context, request string, values map[string]interface{}) (*graphql.Result, error)

Query - query graphql request string

func (*BaseDBLogic) QueryTemplate added in v0.3.26

func (logic *BaseDBLogic) QueryTemplate(ctx context.Context, templateName string, values map[string]interface{}) (*graphql.Result, error)

QueryTemplate - query graphql with template

func (*BaseDBLogic) SetQueryTemplate added in v0.3.26

func (logic *BaseDBLogic) SetQueryTemplate(templateName string, request string) error

SetQueryTemplate - set query template

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 {
	// GetScheme - get GraphQL scheme
	GetScheme() *graphql.Schema

	// Query - query graphql request string
	Query(ctx context.Context, request string, values map[string]interface{}) (*graphql.Result, error)
	// QueryTemplate - query graphql with template
	QueryTemplate(ctx context.Context, templateName string, values map[string]interface{}) (*graphql.Result, error)

	// SetQueryTemplate - set query template
	SetQueryTemplate(templateName string, request string) 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(rootpath string, lstDB []DBConfig) (DBMgr, error)

NewDBMgr - new DBMgr

type FuncAnkaDBEvent added in v0.3.13

type FuncAnkaDBEvent func(ctx context.Context, anka AnkaDB) error

FuncAnkaDBEvent - func event

type FuncAnkaDBForEach added in v0.3.30

type FuncAnkaDBForEach func(key string, value []byte) error

FuncAnkaDBForEach - func event

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

Jump to

Keyboard shortcuts

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