Files
gf/database/gdb/gdb_schema.go

31 lines
793 B
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2020-01-10 23:48:19 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gdb
// Schema is a schema object from which it can then create a Model.
type Schema struct {
2022-02-16 00:26:06 +08:00
DB
2020-01-10 23:48:19 +08:00
}
// Schema creates and returns a schema.
2020-03-08 00:17:42 +08:00
func (c *Core) Schema(schema string) *Schema {
// Do not change the schema of the original db,
// it here creates a new db and changes its schema.
2022-02-16 00:26:06 +08:00
db, err := NewByGroup(c.GetGroup())
if err != nil {
panic(err)
}
2022-02-16 00:26:06 +08:00
core := db.GetCore()
// Different schema share some same objects.
core.logger = c.logger
core.cache = c.cache
core.schema = schema
return &Schema{
DB: db,
}
2020-01-10 23:48:19 +08:00
}