db

package
v0.0.2-0...-1a2f110 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DocAlreadyExisted = "document already existed"

DocAlreadyExisted means document already existed in the database when a new creation is requested

View Source
var DocNotFound = "no document found"

DocNotFound means no document found in the database

Functions

This section is empty.

Types

type Crud

type Crud interface {
	GetByTopic(topicFullName, pulsarURL string) (*model.TopicConfig, error)
	GetByKey(hashedTopicKey string) (*model.TopicConfig, error)
	Update(topicCfg *model.TopicConfig) (string, error)
	Create(topicCfg *model.TopicConfig) (string, error)
	Delete(topicFullName, pulsarURL string) (string, error)
	DeleteByKey(hashedTopicKey string) (string, error)

	// Load is invoked by the webhook.go to start new wekbooks and stop deleted ones
	Load() ([]*model.TopicConfig, error)
}

Crud interface specifies typical CRUD opertaions for database

type Db

type Db interface {
	Crud
	Ops
}

Db interface embeds two other database interfaces

func NewDb

func NewDb(reqDbType string) (Db, error)

NewDb is a database factory pattern to create a new database

func NewDbWithPanic

func NewDbWithPanic(reqDbType string) Db

NewDbWithPanic ensures a database is returned panic otherwise

type InMemoryHandler

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

InMemoryHandler is the in memory cache driver

func NewInMemoryHandler

func NewInMemoryHandler() (*InMemoryHandler, error)

NewInMemoryHandler initialize a Mongo Db

func (*InMemoryHandler) Close

func (s *InMemoryHandler) Close() error

Close closes database

func (*InMemoryHandler) Create

func (s *InMemoryHandler) Create(topicCfg *model.TopicConfig) (string, error)

Create creates a new document

func (*InMemoryHandler) Delete

func (s *InMemoryHandler) Delete(topicFullName, pulsarURL string) (string, error)

Delete deletes a document

func (*InMemoryHandler) DeleteByKey

func (s *InMemoryHandler) DeleteByKey(hashedTopicKey string) (string, error)

DeleteByKey deletes a document based on key

func (*InMemoryHandler) GetByKey

func (s *InMemoryHandler) GetByKey(hashedTopicKey string) (*model.TopicConfig, error)

GetByKey gets a document by the key

func (*InMemoryHandler) GetByTopic

func (s *InMemoryHandler) GetByTopic(topicFullName, pulsarURL string) (*model.TopicConfig, error)

GetByTopic gets a document by the topic name and pulsar URL

func (*InMemoryHandler) Health

func (s *InMemoryHandler) Health() bool

Health is a Db interface method

func (*InMemoryHandler) Init

func (s *InMemoryHandler) Init() error

Init is a Db interface method.

func (*InMemoryHandler) Load

func (s *InMemoryHandler) Load() ([]*model.TopicConfig, error)

Load loads the entire database as a list

func (*InMemoryHandler) Sync

func (s *InMemoryHandler) Sync() error

Sync is a Db interface method.

func (*InMemoryHandler) Update

func (s *InMemoryHandler) Update(topicCfg *model.TopicConfig) (string, error)

Update updates or creates a topic config document

type MongoDb

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

MongoDb is the mongo database driver

func NewMongoDb

func NewMongoDb() (*MongoDb, error)

NewMongoDb initialize a Mongo Db

func (*MongoDb) Close

func (s *MongoDb) Close() error

Close closes database

func (*MongoDb) Create

func (s *MongoDb) Create(topicCfg *model.TopicConfig) (string, error)

Create creates a new document

func (*MongoDb) Delete

func (s *MongoDb) Delete(topicFullName, pulsarURL string) (string, error)

Delete deletes a document

func (*MongoDb) DeleteByKey

func (s *MongoDb) DeleteByKey(hashedTopicKey string) (string, error)

DeleteByKey deletes a document based on key

func (*MongoDb) GetByKey

func (s *MongoDb) GetByKey(hashedTopicKey string) (*model.TopicConfig, error)

GetByKey gets a document by the key

func (*MongoDb) GetByTopic

func (s *MongoDb) GetByTopic(topicFullName, pulsarURL string) (*model.TopicConfig, error)

GetByTopic gets a document by the topic name and pulsar URL

func (*MongoDb) Health

func (s *MongoDb) Health() bool

Health is a Db interface method

func (*MongoDb) Init

func (s *MongoDb) Init() error

Init is a Db interface method.

func (*MongoDb) Load

func (s *MongoDb) Load() ([]*model.TopicConfig, error)

Load loads the entire database into memory

func (*MongoDb) Sync

func (s *MongoDb) Sync() error

Sync is a Db interface method.

func (*MongoDb) Update

func (s *MongoDb) Update(topicCfg *model.TopicConfig) (string, error)

Update updates or creates a topic config document

type Ops

type Ops interface {
	Init() error
	Sync() error
	Close() error
	Health() bool
}

Ops interface specifies required database access operations

type PulsarHandler

type PulsarHandler struct {
	PulsarURL   string
	PulsarToken string
	TopicName   string
	// contains filtered or unexported fields
}

PulsarHandler is the Pulsar database driver

func NewPulsarHandler

func NewPulsarHandler() (*PulsarHandler, error)

NewPulsarHandler initialize a Pulsar Db

func (*PulsarHandler) Close

func (s *PulsarHandler) Close() error

Close closes database

func (*PulsarHandler) Create

func (s *PulsarHandler) Create(topicCfg *model.TopicConfig) (string, error)

Create creates a new document

func (*PulsarHandler) Delete

func (s *PulsarHandler) Delete(topicFullName, pulsarURL string) (string, error)

Delete deletes a document

func (*PulsarHandler) DeleteByKey

func (s *PulsarHandler) DeleteByKey(hashedTopicKey string) (string, error)

DeleteByKey deletes a document based on key

func (*PulsarHandler) GetByKey

func (s *PulsarHandler) GetByKey(hashedTopicKey string) (*model.TopicConfig, error)

GetByKey gets a document by the key

func (*PulsarHandler) GetByTopic

func (s *PulsarHandler) GetByTopic(topicFullName, pulsarURL string) (*model.TopicConfig, error)

GetByTopic gets a document by the topic name and pulsar URL

func (*PulsarHandler) Health

func (s *PulsarHandler) Health() bool

Health is a Db interface method

func (*PulsarHandler) Init

func (s *PulsarHandler) Init() error

Init is a Db interface method.

func (*PulsarHandler) Load

func (s *PulsarHandler) Load() ([]*model.TopicConfig, error)

Load loads the entire database into memory

func (*PulsarHandler) Sync

func (s *PulsarHandler) Sync() error

Sync is a Db interface method.

func (*PulsarHandler) Update

func (s *PulsarHandler) Update(topicCfg *model.TopicConfig) (string, error)

Update updates or creates a topic config document

Jump to

Keyboard shortcuts

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