gdb_schema.go 793 B

123456789101112131415161718192021222324252627282930
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gdb
  7. // Schema is a schema object from which it can then create a Model.
  8. type Schema struct {
  9. DB
  10. }
  11. // Schema creates and returns a schema.
  12. func (c *Core) Schema(schema string) *Schema {
  13. // Do not change the schema of the original db,
  14. // it here creates a new db and changes its schema.
  15. db, err := NewByGroup(c.GetGroup())
  16. if err != nil {
  17. panic(err)
  18. }
  19. core := db.GetCore()
  20. // Different schema share some same objects.
  21. core.logger = c.logger
  22. core.cache = c.cache
  23. core.schema = schema
  24. return &Schema{
  25. DB: db,
  26. }
  27. }