oc-lib/entrypoint.go
2024-07-18 15:15:01 +02:00

44 lines
1.1 KiB
Go

package oclib
import (
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/models"
"cloud.o-forge.io/core/oc-lib/models/resources"
)
type LibData int
const (
INVALID LibData = iota
DATA = resources.DATA
PROCESSING = resources.PROCESSING
STORAGE = resources.STORAGE
DATACENTER = resources.DATACENTER
WORKFLOW = resources.WORKFLOW
)
func (d LibData) EnumIndex() int {
return int(d)
}
func Init() {
mongo.MONGOService.Init(models.GetModelsNames(), GetConfig())
}
func LoadOne(col LibData, id string) interface{} {
return models.Model(col.EnumIndex()).GetAccessor().LoadOne(id)
}
func UpdateOne(col LibData, set map[string]interface{}, id string) interface{} {
return models.Model(col.EnumIndex()).GetAccessor().UpdateOne(set, id)
}
func DeleteOne(col LibData, id string) interface{} {
return models.Model(col.EnumIndex()).GetAccessor().DeleteOne(id)
}
func StoreOne(col LibData, object map[string]interface{}) interface{} {
model := models.Model(col.EnumIndex())
return model.GetAccessor().StoreOne(model.Deserialize(object))
}