clover

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

clover

Table of Contents

  1. Description
  2. Structure and Organisation
  3. Class Diagram
  4. Functionality
  5. Data Types
  6. Testing
  7. Proposed Functionality/Requirements
  8. References

Specification

Description

This sub package contains CloverDB implementation of the database interfaces.

Structure and Organisation

Here is quick overview of the contents of this pacakge:

  • README: Current file which is aimed towards developers who wish to use and modify the database functionality.

  • generic_repository: This file implements the methods of GenericRepository interface.

  • generic_entity_repository: This file implements the methods of GenericEntityRepository interface.

  • deployment: This file contains implementation of DeploymentRequestFlat interface.

  • elk_stats: This file contains implementation of RequestTracker interface.

  • firecracker: This file contains implementation of VirtualMachine interface.

  • machine: This file contains implementation of interfaces defined in machine.go.

  • utils: This file contains utility functions with respect to clover implementation.

All files with *_test.go naming convention contain unit tests with respect to the specific implementation.

Class Diagram

The class diagram for the clover package is shown below.

Source file

clover Class diagram

Rendered from source file
!$rootUrlGitlab = "https://gitlab.com/nunet/device-management-service/-/raw/main"
!$packageRelativePath = "/db/repositories/clover"
!$packageUrlGitlab = $rootUrlGitlab + $packageRelativePath
 
!include $packageUrlGitlab/specs/class_diagram.puml
Functionality
GenericRepository
NewGenericRepository
  • signature: NewGenericRepository[T repositories.ModelType](db *clover.DB) -> repositories.GenericRepository[T]

  • input: clover Database object

  • output: Repository of type db.clover.GenericRepositoryclover

NewGenericRepository function creates a new instance of GenericRepositoryclover struct. It initializes and returns a repository with the provided clover database.

Interface Methods

See db package readme for methods of GenericRepository interface

query
  • signature: query(includeDeleted bool) -> *clover_q.Query

  • input: boolean value to choose whether to include deleted records

  • output: CloverDB query object

query function creates and returns a new CloverDB Query object. Input value of False will add a condition to exclude the deleted records.

queryWithID
  • signature: queryWithID(id interface{}, includeDeleted bool) -> *clover_q.Query

  • input #1: identifier

  • input #2: boolean value to choose whether to include deleted records

  • output: CloverDB query object

queryWithID function creates and returns a new CloverDB Query object. The provided inputs are added to query conditions. The identifier will be compared to primary key field value of the repository.

Providing includeDeleted as False will add a condition to exclude the deleted records.

GenericEntityRepository
NewGenericEntityRepository
  • signature: NewGenericEntityRepository[T repositories.ModelType](db *clover.DB) repositories.GenericEntityRepository[T]

  • input: clover Database object

  • output: Repository of type db.clover.GenericEntityRepositoryclover

NewGenericEntityRepository creates a new instance of GenericEntityRepositoryclover struct. It initializes and returns a repository with the provided clover database instance and name of the collection in the database.

Interface Methods

See db package readme for methods of GenericEntityRepository interface.

query

query function creates and returns a new CloverDB Query object.

Data Types
  • db.clover.GenericRepositoryClover: This is a generic repository implementation using clover as an ORM
type GenericRepositoryClover[T repositories.ModelType] struct {
	db         *clover.DB // db is the Clover database instance.
	collection string     // collection is the name of the collection in the database.
}
  • db.clover.GenericEntityRepositoryClover: This is a generic single entity repository implementation using clover as an ORM
type GenericEntityRepositoryClover[T repositories.ModelType] struct {
	db         *clover.DB // db is the Clover database instance.
	collection string     // collection is the name of the collection in the database.
}

For other data types refer to db package readme.

Testing

Refer to *_test.go files for unit tests of different functionalities.

Proposed Functionality / Requirements
List of issues

All issues that are related to the implementation of db package can be found below. These include any proposals for modifications to the package or new functionality needed to cover the requirements of other packages.

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContractRepo

func NewContractRepo(db *clover.DB) repositories.Contract

NewContractRepo creates a contract repo

func NewDB

func NewDB(path string, collections []string) (*clover.DB, error)

NewDB initializes and sets up the clover database using bbolt under the hood. Additionally, it automatically creates collections for the necessary types.

func NewFreeResources

func NewFreeResources(db *clover.DB) repositories.FreeResources

NewFreeResources creates a new instance of FreeResourcesClover. It initializes and returns a Clover-based repository for FreeResources entity.

func NewGenericEntityRepository

func NewGenericEntityRepository[T repositories.ModelType](
	db *clover.DB,
) repositories.GenericEntityRepository[T]

NewGenericEntityRepository creates a new instance of GenericEntityRepositoryClover. It initializes and returns a repository with the provided Clover database, primary key field, and value.

func NewGenericRepository

func NewGenericRepository[T repositories.ModelType](
	db *clover.DB,
) repositories.GenericRepository[T]

NewGenericRepository creates a new instance of GenericRepositoryClover. It initializes and returns a repository with the provided Clover database.

func NewMachineResourcesRepository

func NewMachineResourcesRepository(db *clover.DB) repositories.MachineResources

NewMachineResourcesRepository creates a new instance of MachineResourcesRepositoryClover. It initializes and returns a Clover-based repository for MachineResources entity.

func NewOnboardedResources

func NewOnboardedResources(db *clover.DB) repositories.OnboardedResources

NewOnboardedResources creates a new instance of OnboardedResourcesClover. It initializes and returns a Clover-based repository for OnboardedResources entity.

func NewOnboardingConfig

func NewOnboardingConfig(db *clover.DB) repositories.OnboardingConfig

NewOnboardingConfigRepository creates a new instance of OnboardingConfigRepository. It initializes and returns a Clover-based repository for OnboardingConfig entity.

func NewOrchestratorView

func NewOrchestratorView(db *clover.DB) repositories.OrchestratorView

NewOrchestratorView creates a new instance of OrchestratorViewClover. It initializes and returns a Clover-based repository for StorageVolume entities.

func NewRequestTracker

func NewRequestTracker(db *clover.DB) repositories.RequestTracker

NewRequestTracker creates a new instance of RequestTrackerClover. It initializes and returns a Clover-based repository for RequestTracker entities.

func NewResourceAllocation

func NewResourceAllocation(db *clover.DB) repositories.ResourceAllocation

NewResourceAllocation creates a new instance of ResourceAllocationClover. It initializes and returns a Clover-based repository for ResourceAllocation entity.

func NewStorageVolume

func NewStorageVolume(db *clover.DB) repositories.StorageVolume

NewStorageVolume creates a new instance of StorageVolumeClover. It initializes and returns a Clover-based repository for StorageVolume entities.

Types

type ContractRepoClover

type ContractRepoClover struct {
	repositories.GenericRepository[contract.Contract]
}

ContractRepoClover

type FreeResourcesClover

type FreeResourcesClover struct {
	repositories.GenericEntityRepository[types.FreeResources]
}

FreeResourcesClover is a Clover implementation of the FreeResources interface.

type GenericEntityRepositoryClover

type GenericEntityRepositoryClover[T repositories.ModelType] struct {
	// contains filtered or unexported fields
}

GenericEntityRepositoryClover is a generic single entity repository implementation using Clover. It is intended to be embedded in single entity model repositories to provide basic database operations.

func (*GenericEntityRepositoryClover[T]) Clear

Clear removes the record with its history from the repository.

func (*GenericEntityRepositoryClover[T]) Get

func (repo *GenericEntityRepositoryClover[T]) Get(_ context.Context) (T, error)

Get retrieves the record from the repository.

func (*GenericEntityRepositoryClover[T]) GetQuery

func (repo *GenericEntityRepositoryClover[T]) GetQuery() repositories.Query[T]

GetQuery returns a clean Query instance for building queries.

func (*GenericEntityRepositoryClover[T]) History

func (repo *GenericEntityRepositoryClover[T]) History(_ context.Context, query repositories.Query[T]) ([]T, error)

History retrieves previous versions of the record from the repository.

func (*GenericEntityRepositoryClover[T]) Save

func (repo *GenericEntityRepositoryClover[T]) Save(_ context.Context, data T) (T, error)

Save creates or updates the record to the repository and returns the new/updated data.

type GenericRepositoryClover

type GenericRepositoryClover[T repositories.ModelType] struct {
	// contains filtered or unexported fields
}

GenericRepositoryClover is a generic repository implementation using Clover. It is intended to be embedded in model repositories to provide basic database operations.

func (*GenericRepositoryClover[T]) Create

func (repo *GenericRepositoryClover[T]) Create(ctx context.Context, data T) (T, error)

Create adds a new record to the repository and returns the created data.

func (*GenericRepositoryClover[T]) Delete

func (repo *GenericRepositoryClover[T]) Delete(ctx context.Context, id interface{}) error

Delete removes a record by its identifier.

func (*GenericRepositoryClover[T]) Find

func (repo *GenericRepositoryClover[T]) Find(
	ctx context.Context,
	query repositories.Query[T],
) (T, error)

Find retrieves a single record based on a query.

func (*GenericRepositoryClover[T]) FindAll

func (repo *GenericRepositoryClover[T]) FindAll(
	ctx context.Context,
	query repositories.Query[T],
) ([]T, error)

FindAll retrieves multiple records based on a query.

func (*GenericRepositoryClover[T]) Get

func (repo *GenericRepositoryClover[T]) Get(ctx context.Context, id interface{}) (T, error)

Get retrieves a record by its identifier.

func (*GenericRepositoryClover[T]) GetQuery

func (repo *GenericRepositoryClover[T]) GetQuery() repositories.Query[T]

GetQuery returns a clean Query instance for building queries.

func (*GenericRepositoryClover[T]) Update

func (repo *GenericRepositoryClover[T]) Update(
	ctx context.Context,
	id interface{},
	data T,
) (T, error)

Update modifies a record by its identifier.

type MachineResourcesRepositoryClover

type MachineResourcesRepositoryClover struct {
	repositories.GenericEntityRepository[types.MachineResources]
}

MachineResourcesRepositoryClover is a Clover implementation of the MachineResourcesRepository interface.

type OnboardedResourcesClover

type OnboardedResourcesClover struct {
	repositories.GenericEntityRepository[types.OnboardedResources]
}

OnboardedResourcesClover is a Clover implementation of the OnboardedResources interface.

type OnboardingConfigRepository

type OnboardingConfigRepository struct {
	repositories.GenericEntityRepository[types.OnboardingConfig]
}

OnboardingConfigRepository is a Clover implementation of the OnboardingConfigRepository interface.

type OrchestratorViewClover

type OrchestratorViewClover struct {
	repositories.GenericRepository[job_types.OrchestratorView]
}

OrchestratorViewClover is a Clover implementation of the StorageVolume interface.

type RequestTrackerClover

type RequestTrackerClover struct {
	repositories.GenericRepository[types.RequestTracker]
}

RequestTrackerClover is a Clover implementation of the RequestTracker interface.

type ResourceAllocationClover

type ResourceAllocationClover struct {
	repositories.GenericRepository[types.ResourceAllocation]
}

ResourceAllocationClover is a Clover implementation of the ResourceAllocation interface.

type StorageVolumeClover

type StorageVolumeClover struct {
	repositories.GenericRepository[types.StorageVolume]
}

StorageVolumeClover is a Clover implementation of the StorageVolume interface.

Jump to

Keyboard shortcuts

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