db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// Operation string for mongo add/insert operation
	MongoAddOp = "insert"

	// Operation string for mongo update operation
	MongoUpdateOp = "update"

	// Operation string for mongo delete operation
	MongoDeleteOp = "delete"
)

Variables

This section is empty.

Functions

func GetSourceIdentifier

func GetSourceIdentifier() string

for internal use only, it will also make source identifier in use

func SetSourceIdentifier

func SetSourceIdentifier(identifier string) bool

Sets Source identifier to specified value, returns the status true if successfull, this will fail under only one scenario if the identifier is already in use by any of the connection

Types

type DocumentKey

type DocumentKey[K any] struct {
	Key *K `bson:"_id,omitempty"`
}

type Event

type Event[K any, E any] struct {
	Doc     DocumentKey[K]        `bson:"documentKey,omitempty"`
	Op      string                `bson:"operationType,omitempty"`
	Time    bson.Timestamp        `bson:"clusterTime,omitempty"`
	Ns      *Namespace            `bson:"ns,omitempty"`
	Entry   *E                    `bson:"fullDocument,omitempty"`
	Updates *UpdateDescription[E] `bson:"updateDescription,omitempty"`
}

func (*Event[K, E]) LogEvent

func (e *Event[K, E]) LogEvent()

type EventLogger

type EventLogger[K any, E any] struct {
	// contains filtered or unexported fields
}

func NewEventLogger

func NewEventLogger[K any, E any](col StoreCollection, timestamp *bson.Timestamp) *EventLogger[K, E]

func (*EventLogger[K, E]) Start

func (l *EventLogger[K, E]) Start(ctx context.Context) error

type MongoConfig

type MongoConfig struct {
	Host     string
	Port     string
	Uri      string
	Username string
	Password string
}

type Namespace

type Namespace struct {
	Database   string `bson:"db,omitempty"`
	Collection string `bson:"coll,omitempty"`
}

type Store

type Store interface {
	// Gets collection corresponding to the collection name
	GetCollection(col string) StoreCollection

	// Gets Name of the database corresponding to the store
	Name() string
}

interface definition for a store, responsible for holding group of collections

type StoreClient

type StoreClient interface {
	// Get the Data Store interface given the client interface
	GetDataStore(dbName string) Store

	// Gets collection corresponding to the collection name inside
	// the requested database name
	GetCollection(dbName, col string) StoreCollection

	// Health Check, if the Store is connectable and healthy
	// returns the status of health of the server by means of
	// error if error is nil the health of the DB store can be
	// considered healthy
	HealthCheck(ctx context.Context) error
}

interface definition for Client corresponding to a store and

func NewMongoClient

func NewMongoClient(conf *MongoConfig) (StoreClient, error)

type StoreCollection

type StoreCollection interface {
	// Set KeyType for the collection, this is not mandatory
	// while the key type will be used by the interface implementer
	// mainly for Watch Callback for providing decoded key, if not
	// set watch will be working with the default decoders of
	// interface implementer
	// only pointer key type is supported as of now
	// returns error if the key type is not a pointer
	SetKeyType(keyType reflect.Type) error

	// insert one entry to the collection for the given key and data
	InsertOne(ctx context.Context, key any, data any) error

	// update one entry in the collection for the given key and data
	// if upsert flag is set, it would insert an entry if it doesn't
	// exist while updating
	UpdateOne(ctx context.Context, key any, data any, upsert bool) error

	// Find one entry from the store collection for the given key, where the data
	// value is returned based on the object type passed to it
	FindOne(ctx context.Context, key any, data any) error

	// Find multiple entries from the store collection for the given filter, where the data
	// value is returned as a list based on the object type passed to it
	FindMany(ctx context.Context, filter any, data any, opts ...any) error

	// Return count of entries matching the provided filter
	Count(ctx context.Context, filter any) (int64, error)

	// remove one entry from the collection matching the given key
	DeleteOne(ctx context.Context, key any) error

	// Delete Many entries matching the delete criteria
	// returns number of entries deleted and if there is any error processing the request
	DeleteMany(ctx context.Context, filter any) (int64, error)

	// watch allows getting notified whenever a change happens to a document
	// in the collection
	// allow provisiong for a filter to be passed on, where the callback
	// function to receive only conditional notifications of the events
	// listener is interested about
	Watch(ctx context.Context, filter any, cb WatchCallbackfn) error
	// contains filtered or unexported methods
}

interface definition for a collection in store

type UpdateDescription

type UpdateDescription[E any] struct {
	UpdatedFields *E       `bson:"updatedFields,omitempty"`
	RemovedFields []string `bson:"removedFields,omitempty"`
}

type WatchCallbackfn

type WatchCallbackfn func(op string, key any)

WatchCallbackfn responsible for

Jump to

Keyboard shortcuts

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