Skip to content

Commit

Permalink
feat: added system collections
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Oct 14, 2024
1 parent 045fc42 commit e65b846
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion core/models/models/v2/base_v2.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package models

import (
"go.mongodb.org/mongo-driver/bson/primitive"
"reflect"
"time"

"go.mongodb.org/mongo-driver/bson/primitive"
)

type BaseModelV2[T any] struct {
Expand Down Expand Up @@ -62,3 +64,66 @@ func (m *BaseModelV2[T]) SetUpdated(id primitive.ObjectID) {
m.SetUpdatedAt(time.Now())
m.SetUpdatedBy(id)
}

func GetModelInstances() []any {
return []any{
*new(TestModelV2),
*new(DataCollectionV2),
*new(DatabaseV2),
*new(DatabaseMetricV2),
*new(DependencyV2),
*new(DependencyLogV2),
*new(DependencySettingV2),
*new(DependencyTaskV2),
*new(EnvironmentV2),
*new(GitV2),
*new(MetricV2),
*new(NodeV2),
*new(NotificationChannelV2),
*new(NotificationRequestV2),
*new(NotificationSettingV2),
*new(PermissionV2),
*new(ProjectV2),
*new(RolePermissionV2),
*new(RoleV2),
*new(ScheduleV2),
*new(SettingV2),
*new(SpiderV2),
*new(SpiderStatV2),
*new(TaskQueueItemV2),
*new(TaskStatV2),
*new(TaskV2),
*new(TokenV2),
*new(UserRoleV2),
*new(UserV2),
}
}

func GetSystemModelColNames() []string {
colNames := make([]string, 0)
for _, instance := range GetModelInstances() {
colName := GetCollectionNameByInstance(instance)
if colName != "" {
colNames = append(colNames, colName)
}
}
return colNames
}

func GetCollectionNameByInstance(v any) string {
t := reflect.TypeOf(v)
field := t.Field(0)
return field.Tag.Get("collection")
}

// Add this new function
func GetSystemModelColNamesMap() map[string]bool {
colNamesMap := make(map[string]bool)
for _, instance := range GetModelInstances() {
colName := GetCollectionNameByInstance(instance)
if colName != "" {
colNamesMap[colName] = true
}
}
return colNamesMap
}

0 comments on commit e65b846

Please sign in to comment.