world.go 609 B

123456789101112131415161718192021222324252627
  1. package mysql
  2. import (
  3. "context"
  4. "fmt"
  5. "pji_desktop_http/biz/dal/query"
  6. "pji_desktop_http/biz/model"
  7. )
  8. func AddWorld(ctx context.Context, world model.World) {
  9. w := query.World
  10. err := w.WithContext(ctx).Create(&world)
  11. if err != nil {
  12. panic(err)
  13. }
  14. }
  15. func QueryWorld(ctx context.Context, sceneId string) (*model.World, error) {
  16. w := query.World
  17. world, err := w.WithContext(ctx).Where(w.SceneID.Eq(sceneId)).Order(w.CreatedAt.Desc()).First()
  18. if err != nil {
  19. fmt.Println("query world failed:", err.Error())
  20. return nil, err
  21. }
  22. fmt.Print("query world successfully:", world)
  23. return world, err
  24. }