oc-lib/entrypoint.go

44 lines
1.1 KiB
Go
Raw Normal View History

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