clover

Last updated: 2024-09-27 10:47:20.570024 File source: link on GitLab

clover

Table of Contents

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

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

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

Last updated