Shallow Get All

This commit is contained in:
mr
2024-07-23 11:22:50 +02:00
parent a687206a1b
commit 94cd62acfe
10 changed files with 119 additions and 14 deletions

View File

@@ -24,6 +24,12 @@ func (d LibDataEnum) EnumIndex() int {
return int(d)
}
type LibDataShallow struct {
Data []utils.ShallowDBObject `bson:"data" json:"data"`
Code int `bson:"code" json:"code"`
Err string `bson:"error" json:"error"`
}
type LibData struct {
Data utils.DBObject `bson:"data" json:"data"`
Code int `bson:"code" json:"code"`
@@ -40,6 +46,14 @@ func GetLogger() zerolog.Logger {
return logs.GetLogger()
}
func LoadAll(collection LibDataEnum) LibDataShallow {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadAll()
if err != nil {
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
}
return LibDataShallow{Data: d, Code: code}
}
func LoadOne(collection LibDataEnum, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
if err != nil {