database.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package repo
  2. import "mats/db/model"
  3. func GetDatabaseCollection(ctx *RepoSession, dbId string, assetId string) (db *model.Database, assetConf *model.DbAsset) {
  4. database := &model.Database{}
  5. ok, _ := RepoSeachDoc(ctx, &DocSearchOptions{CollectName: CollectionDatabase, Query: Map{"_id": dbId}, Project: []string{"assets", "name", "categories"}}, database)
  6. if !ok {
  7. return
  8. }
  9. db = database
  10. for _, v := range database.Assets {
  11. if v.Id == assetId {
  12. assetConf = v
  13. break
  14. }
  15. }
  16. return
  17. }
  18. func GetDatabaseCollectionSimple(ctx *RepoSession, dbId string, assetId string) *model.AssetDbConf {
  19. out := &model.AssetDbConf{}
  20. database := &model.Database{}
  21. ok, _ := RepoSeachDoc(ctx, &DocSearchOptions{CollectName: CollectionDatabase, Query: Map{"_id": dbId}, Project: []string{"assets", "name"}}, database)
  22. if !ok {
  23. return nil
  24. }
  25. out.Db = database
  26. find := false
  27. for _, v := range database.Assets {
  28. if v.Id == assetId {
  29. out.AssetConf = v
  30. find = true
  31. break
  32. }
  33. }
  34. if find {
  35. return out
  36. }
  37. return nil
  38. }
  39. func RepoCreateDefaultAssetValue(asset *model.DbAsset) interface{} {
  40. switch asset.Type {
  41. case model.AssetTypeMesh:
  42. return &model.AssetStaticMesh{}
  43. }
  44. return nil
  45. }