Add schema rename support
Using SchemaFrom("schemaName") it is possible to set SQL builder table to point to a different schema.
This commit is contained in:
parent
753d3bac9a
commit
b375733dfa
17 changed files with 206 additions and 153 deletions
|
|
@ -135,7 +135,7 @@ import (
|
|||
"github.com/go-jet/jet/v2/mysql"
|
||||
)
|
||||
|
||||
var Actor = newActorTable()
|
||||
var Actor = newActorTable("dvds", "actor", "")
|
||||
|
||||
type ActorTable struct {
|
||||
mysql.Table
|
||||
|
|
@ -151,13 +151,16 @@ type ActorTable struct {
|
|||
}
|
||||
|
||||
// AS creates new ActorTable with assigned alias
|
||||
func (a *ActorTable) AS(alias string) ActorTable {
|
||||
aliasTable := newActorTable()
|
||||
aliasTable.Table.AS(alias)
|
||||
return aliasTable
|
||||
func (a ActorTable) AS(alias string) ActorTable {
|
||||
return newActorTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
func newActorTable() ActorTable {
|
||||
// Schema creates new ActorTable with assigned schema name
|
||||
func (a ActorTable) FromSchema(schemaName string) ActorTable {
|
||||
return newActorTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
func newActorTable(schemaName, tableName, alias string) ActorTable {
|
||||
var (
|
||||
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
||||
FirstNameColumn = mysql.StringColumn("first_name")
|
||||
|
|
@ -168,7 +171,7 @@ func newActorTable() ActorTable {
|
|||
)
|
||||
|
||||
return ActorTable{
|
||||
Table: mysql.NewTable("dvds", "actor", allColumns...),
|
||||
Table: mysql.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ActorID: ActorIDColumn,
|
||||
|
|
@ -218,7 +221,7 @@ import (
|
|||
"github.com/go-jet/jet/v2/mysql"
|
||||
)
|
||||
|
||||
var ActorInfo = newActorInfoTable()
|
||||
var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||
|
||||
type ActorInfoTable struct {
|
||||
mysql.Table
|
||||
|
|
@ -234,13 +237,16 @@ type ActorInfoTable struct {
|
|||
}
|
||||
|
||||
// AS creates new ActorInfoTable with assigned alias
|
||||
func (a *ActorInfoTable) AS(alias string) ActorInfoTable {
|
||||
aliasTable := newActorInfoTable()
|
||||
aliasTable.Table.AS(alias)
|
||||
return aliasTable
|
||||
func (a ActorInfoTable) AS(alias string) ActorInfoTable {
|
||||
return newActorInfoTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
func newActorInfoTable() ActorInfoTable {
|
||||
// Schema creates new ActorInfoTable with assigned schema name
|
||||
func (a ActorInfoTable) FromSchema(schemaName string) ActorInfoTable {
|
||||
return newActorInfoTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
func newActorInfoTable(schemaName, tableName, alias string) ActorInfoTable {
|
||||
var (
|
||||
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
||||
FirstNameColumn = mysql.StringColumn("first_name")
|
||||
|
|
@ -251,7 +257,7 @@ func newActorInfoTable() ActorInfoTable {
|
|||
)
|
||||
|
||||
return ActorInfoTable{
|
||||
Table: mysql.NewTable("dvds", "actor_info", allColumns...),
|
||||
Table: mysql.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ActorID: ActorIDColumn,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue