Accessor for each ressource to access DB

This commit is contained in:
pb 2024-07-17 17:18:27 +02:00
parent 3732187678
commit 562720089f
5 changed files with 156 additions and 0 deletions

33
data_mongo_accessor.go Normal file
View File

@ -0,0 +1,33 @@
package oclib
type DataMongoAccessor struct{
}
func (dma *DataMongoAccessor) StoreOne(data Data) string {
id, err := StoreOne(data,"data")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not store " + data.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (dma *DataMongoAccessor) LoadOne(id string) Data {
var data Data
res_mongo, err := LoadOne(id,"data")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Data{}
}
res_mongo.Decode(&data)
return data
}

View File

@ -0,0 +1,28 @@
package oclib
type DatacenterMongoAccessor struct{}
func (dca *DatacenterMongoAccessor) StoreOne(datacenter Datacenter) string {
id, err := StoreOne(datacenter, "datacenter")
if err != nil {
l := CreateLogger("oclib", "")
l.Error().Msg("Could not store " + datacenter.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (dca *DatacenterMongoAccessor) LoadOne(id string) Datacenter {
var datacenter Datacenter
res_mongo, err := LoadOne(id, "datacenter")
if err != nil {
l := CreateLogger("oclib", "")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Datacenter{}
}
res_mongo.Decode(&datacenter)
return datacenter
}

View File

@ -0,0 +1,33 @@
package oclib
type ProcessingMongoAccessor struct{
}
func (pma *ProcessingMongoAccessor) StoreOne(processing Processing) string {
id, err := StoreOne(processing,"processing")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not store " + processing.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (pma *ProcessingMongoAccessor) LoadOne(id string) Processing {
var processing Processing
res_mongo, err := LoadOne(id,"processing")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Processing{}
}
res_mongo.Decode(&processing)
return processing
}

33
storage_mongo_accessor.go Normal file
View File

@ -0,0 +1,33 @@
package oclib
type StorageMongoAccessor struct{
}
func (schedulema *StorageMongoAccessor) StoreOne(storage Storage) string {
id, err := StoreOne(storage,"storage")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not store " + storage.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (schedulema *StorageMongoAccessor) LoadOne(id string) Storage {
var storage Storage
res_mongo, err := LoadOne(id,"storage")
if err != nil{
l := CreateLogger("oclib","")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Storage{}
}
res_mongo.Decode(&storage)
return storage
}

View File

@ -0,0 +1,29 @@
package oclib
type WorkflowMongoAccessor struct{}
func (wfa *WorkflowMongoAccessor) StoreOne(workflow Workflow) string {
id, err := StoreOne(workflow, "workflow")
if err != nil {
l := CreateLogger("oclib", "")
l.Error().Msg("Could not store " + workflow.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (wfa *WorkflowMongoAccessor) LoadOne(id string) Workflow {
var workflow Workflow
res_mongo, err := LoadOne(id, "workflow")
if err != nil {
l := CreateLogger("oclib", "")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Workflow{}
}
res_mongo.Decode(&workflow)
return workflow
}