Last updated: 2024-11-07 21:05:00.194303 File source: link on GitLab
This sub package contains CloverDB implementation of the database interfaces.
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.
The class diagram for the clover
package is shown below.
Source file
Rendered from source file
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
signature: query() -> *clover_q.Query
input: None
output: CloverDB query object
query
function creates and returns a new CloverDB Query object.
db.clover.GenericRepositoryClover
: This is a generic repository implementation using clover as an ORM
db.clover.GenericEntityRepositoryClover
: This is a generic single entity repository implementation using clover as an ORM
For other data types refer to db
package readme.
Refer to *_test.go
files for unit tests of different functionalities.
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.
Last updated: 2024-11-07 21:05:00.491765 File source: link on GitLab
This sub package contains Gorm implementation of the database interfaces.
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.
The class diagram for the gorm
package is shown below.
Source file
Rendered from source file
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.
db.gorm.GenericRepositoryGORM
: This is a generic repository implementation using GORM as an ORM.
db.gorm.GenericEntityRepositoryGORM
: This is a generic single entity repository implementation using GORM as an ORM
For other data types refer to db
package readme.
Refer to *_test.go
files for unit tests of different functionalities.
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.
Last updated: 2024-11-07 21:04:59.905240 File source: link on GitLab
The db
package contains the configuration and functionality of database used by the DMS
Here is quick overview of the contents of this pacakge:
Files
README: Current file which is aimed towards developers who wish to use and modify the database functionality.
generic_repository: This file defines the interface defining the main methods for db pacakge. It is designed using generic types and can be adapted to specific data type as needed.
generic_entity_repository: This file contains the interface for those databases which will hold only a single record.
deployment: This file specifies a database interface having types.DeploymentRequestFlat
data type.
elk_stats: This file specifies a database interface having types.RequestTracker
data type.
errors: This file specifies the different types of errors.
firecracker: This file specifies a database interface having types.VirtualMachine
data type.
machine: This file defines database interfaces of various data types.
utils: This file contains some utility functions with respect to database operations.
utils_test: This file contains unit tests for functions defined in utils.go file.
Subpackages
gorm: This folder contains SQlite database implementation using gorm.
clover: This folder contains CloverDB database implementation.
The class diagram for the db
package is shown below.
Source file
Rendered from source file
There are two types of interfaces defined to cover database operations:
GenericRepository
GenericEntityRepository
These interfaces are described below.
GenericRepository Interface
GenericRepository
interface defines basic CRUD operations and standard querying methods. It is defined with generic data types. This allows it to be used for any data type.
interface definition: type GenericRepository[T ModelType] interface
The methods of GenericRepository
are as follows:
Create
signature: Create(ctx context.Context, data T) -> (T, error)
input #1: Go context
input #2: Data to be added to the database. It should be of type used to initialize the repository
output (success): Data type used to initialize the repository
output (error): error message
Create
function adds a new record to the database.
Get
signature: Get(ctx context.Context, id interface{}) -> (T, error)
input #1: Go context
input #2: Identifier of the record. Can be any data type
output (success): Data with the identifier provided. It is of type used to initialize the repository
output (error): error message
Get
function retrieves a record from the database by its identifier.
Update
signature: Update(ctx context.Context, id interface{}, data T) -> (T, error)
input #1: Go context
input #2: Identifier of the record. Can be any data type
input #3: New data of type used to initialize the repository
output (success): Updated record of type used to initialize the repository
output (error): error message
Update
function modifies an existing record in the database using its identifier.
Delete
signature: Delete(ctx context.Context, id interface{}) -> error
input #1: Go context
input #2: Identifier of the record. Can be any data type
output (success): None
output (error): error message
Delete
function deletes an existing record in the database using its identifier.
Find
signature: Find(ctx context.Context, query Query[T]) -> (T, error)
input #1: Go context
input #2: Query of type db.query
output (success): Result of query having the data type used to initialize the repository
output (error): error message
Find
function retrieves a single record from the database based on a query.
FindAll
signature: FindAll(ctx context.Context, query Query[T]) -> ([]T, error)
input #1: Go context
input #2: Query of type db.query
output (success): Lists of records based on query result. The data type of each record will be what was used to initialize the repository
output (error): error message
FindAll
function retrieves multiple records from the database based on a query.
GetQuery
signature: GetQuery() -> Query[T]
input: None
output: Query of type db.query
GetQuery
function returns an empty query instance for the repository's type.
GenericEntityRepository Interface
GenericEntityRepository
defines basic CRUD operations for repositories handling a single record. It is defined with generic data types. This allows it to be used for any data type.
interface definition: type GenericEntityRepository[T ModelType] interface
The methods of GenericEntityRepository
are as follows:
Save
signature: Save(ctx context.Context, data T) -> (T, error)
input #1: Go context
input #2: Data to be saved of type used to initialize the database
output (success): Updated record of type used to initialize the repository
output (error): error message
Save
function adds or updates a single record in the repository
Get
signature: Get(ctx context.Context) -> (T, error)
input: Go context
output (success): Record of type used to initialize the repository
output (error): error message
Get
function retrieves the single record from the database.
Clear
signature: Clear(ctx context.Context) -> error
input: Go context
output (success): None
output (error): error
Clear
function removes the record and its history from the repository.
History
signature: History(ctx context.Context, qiery Query[T]) -> ([]T, error)
input #1: Go context
input #2: query of type db.query
output (success):List of records of repository's type
output (error): error
History
function retrieves previous records from the repository which satisfy the query conditions.
GetQuery
signature: GetQuery() -> Query[T]
input: None
output: New query of type db.query
GetQuery
function returns an empty query instance for the repository's type.
db.Query
: This contains parameters related to a query that is passed to the database.
db.QueryCondition
: This contains parameters defining a query condition.
GenericRepository
has been initialised for the following data types:
types.DeploymentRequestFlat
types.VirtualMachine
types.PeerInfo
types.Machine
types.Services
types.ServiceResourceRequirements
types.Connection
types.ElasticToken
GenericEntityRepository
has been initialised for the following data types:
types.FreeResources
types.AvailableResources
types.Libp2pInfo
types.MachineUUID
The unit tests for utility functions are defined in utils_test.go
. Refer to *_test.go
files for unit tests of various implementations covered in subpackages.
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.