gorm

Last updated: 2024-11-21 22:06:01.931280 File source: link on GitLab

gorm

Table of Contents

Specification

Description

This sub package contains Gorm 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 Gorm implementation.

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

Class Diagram

The class diagram for the gorm package is shown below.

Source file

gorm Class diagram

Rendered from source file

!$rootUrlGitlab = "https://gitlab.com/nunet/device-management-service/-/raw/main"
!$packageRelativePath = "/db/repositories/gorm"
!$packageUrlGitlab = $rootUrlGitlab + $packageRelativePath
 
!include $packageUrlGitlab/specs/class_diagram.puml

Functionality

GenericRepository

NewGenericRepository

  • signature: NewGenericRepository[T repositories.ModelType](db *gorm.DB) -> repositories.GenericRepository[T]

  • input: Gorm Database object

  • output: Repository of type db.gorm.GenericRepositoryGORM

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

Interface Methods

See db package readme for methods of GenericRepository interface.

GenericEntityRepository

NewGenericEntityRepository

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

  • input #1: Gorm Database object

  • output: Repository of type db.gorm.GenericEntityRepositoryGORM

NewGenericEntityRepository creates a new instance of GenericEntityRepositoryGORM struct. It initializes and returns a repository with the provided GORM database.

Interface Methods

See db package readme for methods of GenericEntityRepository interface.

Data Types

  • db.gorm.GenericRepositoryGORM: This is a generic repository implementation using GORM as an ORM.

type GenericRepositoryGORM[T repositories.ModelType] struct {
	db *gorm.DB
}
  • db.gorm.GenericEntityRepositoryGORM: This is a generic single entity repository implementation using GORM as an ORM

type GenericEntityRepositoryGORM[T repositories.ModelType] struct {
	db *gorm.DB // db is the GORM database instance.
}

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