mongo

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	// TODO: by using the mongo.ObjectID wrapper
	// the ID in the database is not being set properly.
	// It assigns a BYNARY
	// How can this be solved if we want to use the wrapper?
	ID           primitive.ObjectID `bson:"_id,omitempty"`
	Name         string             `bson:"name"`
	SingularName string             `bson:"singular_name"`
	PluralName   string             `bson:"plural_name"`
	Fields       []Field            `bson:"fields"`
	Collection   string             `bson:"collection"`
}

Entity is a specific definition of an object/entity/thing inside a domain in Mongo

type EntityMarshaler

type EntityMarshaler interface {
	// MarshalEntity encodes a domain entity model to a mongo entity model
	MarshalEntity(entity *domain.Entity) (*Entity, error)
	// UnmarshalEntity decodes a mongo entity model to a domain entity model
	UnmarshalEntity(ent *Entity) (*domain.Entity, error)
}

EntityMarshaler decodes/encodes domain entity model from/to mongo entity model

func NewEntityMarshaler

func NewEntityMarshaler() EntityMarshaler

NewEntityMarshaler returns a new instance of EntityMarshaler

type Field

type Field struct {
	Type        string `bson:"type"`
	Name        string `bson:"name"`
	Label       string `bson:"label"`
	Help        string `bson:"help"`
	Placeholder string `bson:"placeholder"`
	Rules       []Rule `bson:"rules"`
}

Field defines a representation for every field of an entity in Mongo

type MongoEntityRepository

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

MongoEntityRepository is the repository to manage entities in Mongo

func NewMongoEntityRepository

func NewMongoEntityRepository(
	entityMarshaler EntityMarshaler,
	dbClient database.DatabaseClient,
) (*MongoEntityRepository, error)

NewMongoEntityRepository creates an instace of MongoEntityRepository

func (*MongoEntityRepository) CreateEntity

func (repo *MongoEntityRepository) CreateEntity(
	ctx context.Context,
	entity *domain.Entity,
) (*domain.Entity, error)

CreateEntity creates an entity with fields and rules in Mongo

func (*MongoEntityRepository) GetEntityByName

func (repo *MongoEntityRepository) GetEntityByName(
	ctx context.Context,
	entityName string,
) (*domain.Entity, error)

GetEntityByName returns one single entity defined by its name

type MongoRecordRepository added in v1.3.0

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

RecordRepository defines the repository that stores, modifies and deletes record in Mongo

func NewMongoRecordRepository added in v1.3.0

func NewMongoRecordRepository(
	dbClient database.DatabaseClient,
) (*MongoRecordRepository, error)

NewMongoRecordRepository creates an instace of MongoRecordRepository

func (*MongoRecordRepository) CreateRecord added in v1.3.0

func (repo *MongoRecordRepository) CreateRecord(
	ctx context.Context,
	entity *domain.Entity,
	record *pubdomain.Record,
) (*pubdomain.Record, error)

CreateRecord creates a new record in the data store related to an entity

func (*MongoRecordRepository) DeleteRecord added in v1.7.0

func (repo *MongoRecordRepository) DeleteRecord(
	ctx context.Context,
	entity *domain.Entity,
	recordId string,
) error

DeleteRecord deletes a record in the data store related to an entity

func (*MongoRecordRepository) GetRecord added in v1.5.0

func (repo *MongoRecordRepository) GetRecord(
	ctx context.Context,
	entity *domain.Entity,
	recordId string,
) (*pubdomain.Record, error)

GetRecord gets a record from the data store related to an entity

func (*MongoRecordRepository) UpdateRecord added in v1.6.0

func (repo *MongoRecordRepository) UpdateRecord(
	ctx context.Context,
	entity *domain.Entity,
	recordId string,
	partialRecord *pubdomain.Record,
) (*pubdomain.Record, error)

UpdateRecord updates a record in the data store related to an entity

type Rule

type Rule struct {
	Type   string                 `bson:"type"`
	Config map[string]interface{} `bson:"config"`
}

Rule defines a validation to check if a value is valid or not in Mongo

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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