Merge remote-tracking branch 'remotes/origin/schema-rename-support2' into develop
This commit is contained in:
commit
9773657c3d
29 changed files with 348 additions and 240 deletions
|
|
@ -77,6 +77,7 @@ jobs:
|
||||||
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
|
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
|
||||||
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
|
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
|
||||||
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
|
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
|
||||||
|
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
|
||||||
|
|
||||||
- run:
|
- run:
|
||||||
name: Init Postgres database
|
name: Init Postgres database
|
||||||
|
|
@ -145,6 +146,7 @@ jobs:
|
||||||
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
|
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
|
||||||
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
|
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
|
||||||
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
|
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
|
||||||
|
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
|
||||||
|
|
||||||
- run:
|
- run:
|
||||||
name: Init MariaDB database
|
name: Init MariaDB database
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Actor = newActorTable()
|
var Actor = newActorTable("dvds", "actor", "")
|
||||||
|
|
||||||
type actorTable struct {
|
type actorTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -33,20 +33,23 @@ type ActorTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorTable with assigned alias
|
// AS creates new ActorTable with assigned alias
|
||||||
func (a *ActorTable) AS(alias string) *ActorTable {
|
func (a ActorTable) AS(alias string) *ActorTable {
|
||||||
aliasTable := newActorTable()
|
return newActorTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return &ActorTable{
|
return &ActorTable{
|
||||||
actorTable: newActorTableImpl("dvds", "actor"),
|
actorTable: newActorTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newActorTableImpl("", "excluded"),
|
EXCLUDED: newActorTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newActorTableImpl(schemaName, tableName string) actorTable {
|
func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
var (
|
var (
|
||||||
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = postgres.StringColumn("first_name")
|
FirstNameColumn = postgres.StringColumn("first_name")
|
||||||
|
|
@ -57,7 +60,7 @@ func newActorTableImpl(schemaName, tableName string) actorTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return actorTable{
|
return actorTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Category = newCategoryTable()
|
var Category = newCategoryTable("dvds", "category", "")
|
||||||
|
|
||||||
type categoryTable struct {
|
type categoryTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -32,20 +32,23 @@ type CategoryTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new CategoryTable with assigned alias
|
// AS creates new CategoryTable with assigned alias
|
||||||
func (a *CategoryTable) AS(alias string) *CategoryTable {
|
func (a CategoryTable) AS(alias string) *CategoryTable {
|
||||||
aliasTable := newCategoryTable()
|
return newCategoryTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCategoryTable() *CategoryTable {
|
// Schema creates new CategoryTable with assigned schema name
|
||||||
|
func (a CategoryTable) FromSchema(schemaName string) *CategoryTable {
|
||||||
|
return newCategoryTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCategoryTable(schemaName, tableName, alias string) *CategoryTable {
|
||||||
return &CategoryTable{
|
return &CategoryTable{
|
||||||
categoryTable: newCategoryTableImpl("dvds", "category"),
|
categoryTable: newCategoryTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newCategoryTableImpl("", "excluded"),
|
EXCLUDED: newCategoryTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCategoryTableImpl(schemaName, tableName string) categoryTable {
|
func newCategoryTableImpl(schemaName, tableName, alias string) categoryTable {
|
||||||
var (
|
var (
|
||||||
CategoryIDColumn = postgres.IntegerColumn("category_id")
|
CategoryIDColumn = postgres.IntegerColumn("category_id")
|
||||||
NameColumn = postgres.StringColumn("name")
|
NameColumn = postgres.StringColumn("name")
|
||||||
|
|
@ -55,7 +58,7 @@ func newCategoryTableImpl(schemaName, tableName string) categoryTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return categoryTable{
|
return categoryTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
CategoryID: CategoryIDColumn,
|
CategoryID: CategoryIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Film = newFilmTable()
|
var Film = newFilmTable("dvds", "film", "")
|
||||||
|
|
||||||
type filmTable struct {
|
type filmTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -42,20 +42,23 @@ type FilmTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new FilmTable with assigned alias
|
// AS creates new FilmTable with assigned alias
|
||||||
func (a *FilmTable) AS(alias string) *FilmTable {
|
func (a FilmTable) AS(alias string) *FilmTable {
|
||||||
aliasTable := newFilmTable()
|
return newFilmTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmTable() *FilmTable {
|
// Schema creates new FilmTable with assigned schema name
|
||||||
|
func (a FilmTable) FromSchema(schemaName string) *FilmTable {
|
||||||
|
return newFilmTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFilmTable(schemaName, tableName, alias string) *FilmTable {
|
||||||
return &FilmTable{
|
return &FilmTable{
|
||||||
filmTable: newFilmTableImpl("dvds", "film"),
|
filmTable: newFilmTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newFilmTableImpl("", "excluded"),
|
EXCLUDED: newFilmTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmTableImpl(schemaName, tableName string) filmTable {
|
func newFilmTableImpl(schemaName, tableName, alias string) filmTable {
|
||||||
var (
|
var (
|
||||||
FilmIDColumn = postgres.IntegerColumn("film_id")
|
FilmIDColumn = postgres.IntegerColumn("film_id")
|
||||||
TitleColumn = postgres.StringColumn("title")
|
TitleColumn = postgres.StringColumn("title")
|
||||||
|
|
@ -75,7 +78,7 @@ func newFilmTableImpl(schemaName, tableName string) filmTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return filmTable{
|
return filmTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
FilmID: FilmIDColumn,
|
FilmID: FilmIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var FilmActor = newFilmActorTable()
|
var FilmActor = newFilmActorTable("dvds", "film_actor", "")
|
||||||
|
|
||||||
type filmActorTable struct {
|
type filmActorTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -32,20 +32,23 @@ type FilmActorTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new FilmActorTable with assigned alias
|
// AS creates new FilmActorTable with assigned alias
|
||||||
func (a *FilmActorTable) AS(alias string) *FilmActorTable {
|
func (a FilmActorTable) AS(alias string) *FilmActorTable {
|
||||||
aliasTable := newFilmActorTable()
|
return newFilmActorTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmActorTable() *FilmActorTable {
|
// Schema creates new FilmActorTable with assigned schema name
|
||||||
|
func (a FilmActorTable) FromSchema(schemaName string) *FilmActorTable {
|
||||||
|
return newFilmActorTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFilmActorTable(schemaName, tableName, alias string) *FilmActorTable {
|
||||||
return &FilmActorTable{
|
return &FilmActorTable{
|
||||||
filmActorTable: newFilmActorTableImpl("dvds", "film_actor"),
|
filmActorTable: newFilmActorTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newFilmActorTableImpl("", "excluded"),
|
EXCLUDED: newFilmActorTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmActorTableImpl(schemaName, tableName string) filmActorTable {
|
func newFilmActorTableImpl(schemaName, tableName, alias string) filmActorTable {
|
||||||
var (
|
var (
|
||||||
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
||||||
FilmIDColumn = postgres.IntegerColumn("film_id")
|
FilmIDColumn = postgres.IntegerColumn("film_id")
|
||||||
|
|
@ -55,7 +58,7 @@ func newFilmActorTableImpl(schemaName, tableName string) filmActorTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return filmActorTable{
|
return filmActorTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var FilmCategory = newFilmCategoryTable()
|
var FilmCategory = newFilmCategoryTable("dvds", "film_category", "")
|
||||||
|
|
||||||
type filmCategoryTable struct {
|
type filmCategoryTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -32,20 +32,23 @@ type FilmCategoryTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new FilmCategoryTable with assigned alias
|
// AS creates new FilmCategoryTable with assigned alias
|
||||||
func (a *FilmCategoryTable) AS(alias string) *FilmCategoryTable {
|
func (a FilmCategoryTable) AS(alias string) *FilmCategoryTable {
|
||||||
aliasTable := newFilmCategoryTable()
|
return newFilmCategoryTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmCategoryTable() *FilmCategoryTable {
|
// Schema creates new FilmCategoryTable with assigned schema name
|
||||||
|
func (a FilmCategoryTable) FromSchema(schemaName string) *FilmCategoryTable {
|
||||||
|
return newFilmCategoryTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFilmCategoryTable(schemaName, tableName, alias string) *FilmCategoryTable {
|
||||||
return &FilmCategoryTable{
|
return &FilmCategoryTable{
|
||||||
filmCategoryTable: newFilmCategoryTableImpl("dvds", "film_category"),
|
filmCategoryTable: newFilmCategoryTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newFilmCategoryTableImpl("", "excluded"),
|
EXCLUDED: newFilmCategoryTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFilmCategoryTableImpl(schemaName, tableName string) filmCategoryTable {
|
func newFilmCategoryTableImpl(schemaName, tableName, alias string) filmCategoryTable {
|
||||||
var (
|
var (
|
||||||
FilmIDColumn = postgres.IntegerColumn("film_id")
|
FilmIDColumn = postgres.IntegerColumn("film_id")
|
||||||
CategoryIDColumn = postgres.IntegerColumn("category_id")
|
CategoryIDColumn = postgres.IntegerColumn("category_id")
|
||||||
|
|
@ -55,7 +58,7 @@ func newFilmCategoryTableImpl(schemaName, tableName string) filmCategoryTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return filmCategoryTable{
|
return filmCategoryTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
FilmID: FilmIDColumn,
|
FilmID: FilmIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Language = newLanguageTable()
|
var Language = newLanguageTable("dvds", "language", "")
|
||||||
|
|
||||||
type languageTable struct {
|
type languageTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -32,20 +32,23 @@ type LanguageTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new LanguageTable with assigned alias
|
// AS creates new LanguageTable with assigned alias
|
||||||
func (a *LanguageTable) AS(alias string) *LanguageTable {
|
func (a LanguageTable) AS(alias string) *LanguageTable {
|
||||||
aliasTable := newLanguageTable()
|
return newLanguageTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLanguageTable() *LanguageTable {
|
// Schema creates new LanguageTable with assigned schema name
|
||||||
|
func (a LanguageTable) FromSchema(schemaName string) *LanguageTable {
|
||||||
|
return newLanguageTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLanguageTable(schemaName, tableName, alias string) *LanguageTable {
|
||||||
return &LanguageTable{
|
return &LanguageTable{
|
||||||
languageTable: newLanguageTableImpl("dvds", "language"),
|
languageTable: newLanguageTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newLanguageTableImpl("", "excluded"),
|
EXCLUDED: newLanguageTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLanguageTableImpl(schemaName, tableName string) languageTable {
|
func newLanguageTableImpl(schemaName, tableName, alias string) languageTable {
|
||||||
var (
|
var (
|
||||||
LanguageIDColumn = postgres.IntegerColumn("language_id")
|
LanguageIDColumn = postgres.IntegerColumn("language_id")
|
||||||
NameColumn = postgres.StringColumn("name")
|
NameColumn = postgres.StringColumn("name")
|
||||||
|
|
@ -55,7 +58,7 @@ func newLanguageTableImpl(schemaName, tableName string) languageTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return languageTable{
|
return languageTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
LanguageID: LanguageIDColumn,
|
LanguageID: LanguageIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ActorInfo = newActorInfoTable()
|
var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||||
|
|
||||||
type actorInfoTable struct {
|
type actorInfoTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -33,20 +33,23 @@ type ActorInfoTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorInfoTable with assigned alias
|
// AS creates new ActorInfoTable with assigned alias
|
||||||
func (a *ActorInfoTable) AS(alias string) *ActorInfoTable {
|
func (a ActorInfoTable) AS(alias string) *ActorInfoTable {
|
||||||
aliasTable := newActorInfoTable()
|
return newActorInfoTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return &ActorInfoTable{
|
return &ActorInfoTable{
|
||||||
actorInfoTable: newActorInfoTableImpl("dvds", "actor_info"),
|
actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newActorInfoTableImpl("", "excluded"),
|
EXCLUDED: newActorInfoTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newActorInfoTableImpl(schemaName, tableName string) actorInfoTable {
|
func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
|
||||||
var (
|
var (
|
||||||
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = postgres.StringColumn("first_name")
|
FirstNameColumn = postgres.StringColumn("first_name")
|
||||||
|
|
@ -57,7 +60,7 @@ func newActorInfoTableImpl(schemaName, tableName string) actorInfoTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return actorInfoTable{
|
return actorInfoTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CustomerList = newCustomerListTable()
|
var CustomerList = newCustomerListTable("dvds", "customer_list", "")
|
||||||
|
|
||||||
type customerListTable struct {
|
type customerListTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -38,20 +38,23 @@ type CustomerListTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new CustomerListTable with assigned alias
|
// AS creates new CustomerListTable with assigned alias
|
||||||
func (a *CustomerListTable) AS(alias string) *CustomerListTable {
|
func (a CustomerListTable) AS(alias string) *CustomerListTable {
|
||||||
aliasTable := newCustomerListTable()
|
return newCustomerListTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCustomerListTable() *CustomerListTable {
|
// Schema creates new CustomerListTable with assigned schema name
|
||||||
|
func (a CustomerListTable) FromSchema(schemaName string) *CustomerListTable {
|
||||||
|
return newCustomerListTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCustomerListTable(schemaName, tableName, alias string) *CustomerListTable {
|
||||||
return &CustomerListTable{
|
return &CustomerListTable{
|
||||||
customerListTable: newCustomerListTableImpl("dvds", "customer_list"),
|
customerListTable: newCustomerListTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newCustomerListTableImpl("", "excluded"),
|
EXCLUDED: newCustomerListTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCustomerListTableImpl(schemaName, tableName string) customerListTable {
|
func newCustomerListTableImpl(schemaName, tableName, alias string) customerListTable {
|
||||||
var (
|
var (
|
||||||
IDColumn = postgres.IntegerColumn("id")
|
IDColumn = postgres.IntegerColumn("id")
|
||||||
NameColumn = postgres.StringColumn("name")
|
NameColumn = postgres.StringColumn("name")
|
||||||
|
|
@ -67,7 +70,7 @@ func newCustomerListTableImpl(schemaName, tableName string) customerListTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return customerListTable{
|
return customerListTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ID: IDColumn,
|
ID: IDColumn,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/{{dialect.PackageName}}"
|
"github.com/go-jet/jet/v2/{{dialect.PackageName}}"
|
||||||
)
|
)
|
||||||
|
|
||||||
var {{ToGoIdentifier .Name}} = new{{.GoStructName}}()
|
var {{ToGoIdentifier .Name}} = new{{.GoStructName}}("{{.SchemaName}}", "{{.Name}}", "")
|
||||||
|
|
||||||
type {{.GoStructName}} struct {
|
type {{.GoStructName}} struct {
|
||||||
{{dialect.PackageName}}.Table
|
{{dialect.PackageName}}.Table
|
||||||
|
|
@ -38,13 +38,16 @@ type {{.GoStructName}} struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new {{.GoStructName}} with assigned alias
|
// AS creates new {{.GoStructName}} with assigned alias
|
||||||
func (a *{{.GoStructName}}) AS(alias string) {{.GoStructName}} {
|
func (a {{.GoStructName}}) AS(alias string) {{.GoStructName}} {
|
||||||
aliasTable := new{{.GoStructName}}()
|
return new{{.GoStructName}}(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func new{{.GoStructName}}() {{.GoStructName}} {
|
// Schema creates new {{.GoStructName}} with assigned schema name
|
||||||
|
func (a {{.GoStructName}}) FromSchema(schemaName string) {{.GoStructName}} {
|
||||||
|
return new{{.GoStructName}}(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func new{{.GoStructName}}(schemaName, tableName, alias string) {{.GoStructName}} {
|
||||||
var (
|
var (
|
||||||
{{- range .Columns}}
|
{{- range .Columns}}
|
||||||
{{ToGoIdentifier .Name}}Column = {{dialect.PackageName}}.{{.SqlBuilderColumnType}}Column("{{.Name}}")
|
{{ToGoIdentifier .Name}}Column = {{dialect.PackageName}}.{{.SqlBuilderColumnType}}Column("{{.Name}}")
|
||||||
|
|
@ -54,7 +57,7 @@ func new{{.GoStructName}}() {{.GoStructName}} {
|
||||||
)
|
)
|
||||||
|
|
||||||
return {{.GoStructName}}{
|
return {{.GoStructName}}{
|
||||||
Table: {{dialect.PackageName}}.NewTable("{{.SchemaName}}", "{{.Name}}", allColumns...),
|
Table: {{dialect.PackageName}}.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
{{- range .Columns}}
|
{{- range .Columns}}
|
||||||
|
|
@ -80,7 +83,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/{{dialect.PackageName}}"
|
"github.com/go-jet/jet/v2/{{dialect.PackageName}}"
|
||||||
)
|
)
|
||||||
|
|
||||||
var {{ToGoIdentifier .Name}} = new{{.GoStructName}}()
|
var {{ToGoIdentifier .Name}} = new{{.GoStructName}}("{{.SchemaName}}", "{{.Name}}", "")
|
||||||
|
|
||||||
type {{.GoStructImplName}} struct {
|
type {{.GoStructImplName}} struct {
|
||||||
{{dialect.PackageName}}.Table
|
{{dialect.PackageName}}.Table
|
||||||
|
|
@ -101,20 +104,23 @@ type {{.GoStructName}} struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new {{.GoStructName}} with assigned alias
|
// AS creates new {{.GoStructName}} with assigned alias
|
||||||
func (a *{{.GoStructName}}) AS(alias string) *{{.GoStructName}} {
|
func (a {{.GoStructName}}) AS(alias string) *{{.GoStructName}} {
|
||||||
aliasTable := new{{.GoStructName}}()
|
return new{{.GoStructName}}(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func new{{.GoStructName}}() *{{.GoStructName}} {
|
// Schema creates new {{.GoStructName}} with assigned schema name
|
||||||
|
func (a {{.GoStructName}}) FromSchema(schemaName string) *{{.GoStructName}} {
|
||||||
|
return new{{.GoStructName}}(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func new{{.GoStructName}}(schemaName, tableName, alias string) *{{.GoStructName}} {
|
||||||
return &{{.GoStructName}}{
|
return &{{.GoStructName}}{
|
||||||
{{.GoStructImplName}}: new{{.GoStructName}}Impl("{{.SchemaName}}", "{{.Name}}"),
|
{{.GoStructImplName}}: new{{.GoStructName}}Impl(schemaName, tableName, alias),
|
||||||
EXCLUDED: new{{.GoStructName}}Impl("", "excluded"),
|
EXCLUDED: new{{.GoStructName}}Impl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func new{{.GoStructName}}Impl(schemaName, tableName string) {{.GoStructImplName}} {
|
func new{{.GoStructName}}Impl(schemaName, tableName, alias string) {{.GoStructImplName}} {
|
||||||
var (
|
var (
|
||||||
{{- range .Columns}}
|
{{- range .Columns}}
|
||||||
{{ToGoIdentifier .Name}}Column = {{dialect.PackageName}}.{{.SqlBuilderColumnType}}Column("{{.Name}}")
|
{{ToGoIdentifier .Name}}Column = {{dialect.PackageName}}.{{.SqlBuilderColumnType}}Column("{{.Name}}")
|
||||||
|
|
@ -124,7 +130,7 @@ func new{{.GoStructName}}Impl(schemaName, tableName string) {{.GoStructImplName}
|
||||||
)
|
)
|
||||||
|
|
||||||
return {{.GoStructImplName}}{
|
return {{.GoStructImplName}}{
|
||||||
Table: {{dialect.PackageName}}.NewTable(schemaName, tableName, allColumns...),
|
Table: {{dialect.PackageName}}.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
{{- range .Columns}}
|
{{- range .Columns}}
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,27 @@ type Table interface {
|
||||||
columns() []Column
|
columns() []Column
|
||||||
SchemaName() string
|
SchemaName() string
|
||||||
TableName() string
|
TableName() string
|
||||||
AS(alias string)
|
Alias() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTable creates new table with schema Name, table Name and list of columns
|
// NewTable creates new table with schema Name, table Name and list of columns
|
||||||
func NewTable(schemaName, name string, columns ...ColumnExpression) SerializerTable {
|
func NewTable(schemaName, name, alias string, columns ...ColumnExpression) SerializerTable {
|
||||||
|
|
||||||
t := tableImpl{
|
t := tableImpl{
|
||||||
schemaName: schemaName,
|
schemaName: schemaName,
|
||||||
name: name,
|
name: name,
|
||||||
|
alias: alias,
|
||||||
columnList: columns,
|
columnList: columns,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
columnTableName := name
|
||||||
|
|
||||||
|
if alias != "" {
|
||||||
|
columnTableName = alias
|
||||||
|
}
|
||||||
|
|
||||||
for _, c := range columns {
|
for _, c := range columns {
|
||||||
c.setTableName(name)
|
c.setTableName(columnTableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &t
|
return &t
|
||||||
|
|
@ -41,14 +48,6 @@ type tableImpl struct {
|
||||||
columnList []ColumnExpression
|
columnList []ColumnExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tableImpl) AS(alias string) {
|
|
||||||
t.alias = alias
|
|
||||||
|
|
||||||
for _, c := range t.columnList {
|
|
||||||
c.setTableName(alias)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tableImpl) SchemaName() string {
|
func (t *tableImpl) SchemaName() string {
|
||||||
return t.schemaName
|
return t.schemaName
|
||||||
}
|
}
|
||||||
|
|
@ -67,13 +66,21 @@ func (t *tableImpl) columns() []Column {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *tableImpl) Alias() string {
|
||||||
|
return t.alias
|
||||||
|
}
|
||||||
|
|
||||||
func (t *tableImpl) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
func (t *tableImpl) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
panic("jet: tableImpl is nil")
|
panic("jet: tableImpl is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
out.WriteIdentifier(t.schemaName)
|
// Use default schema if the schema name is not set
|
||||||
out.WriteString(".")
|
if len(t.schemaName) > 0 {
|
||||||
|
out.WriteIdentifier(t.schemaName)
|
||||||
|
out.WriteString(".")
|
||||||
|
}
|
||||||
|
|
||||||
out.WriteIdentifier(t.name)
|
out.WriteIdentifier(t.name)
|
||||||
|
|
||||||
if len(t.alias) > 0 {
|
if len(t.alias) > 0 {
|
||||||
|
|
@ -145,6 +152,10 @@ func (t *joinTableImpl) columns() []Column {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *joinTableImpl) Alias() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (t *joinTableImpl) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
func (t *joinTableImpl) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
panic("jet: Join table is nil. ")
|
panic("jet: Join table is nil. ")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewTable(t *testing.T) {
|
func TestNewTable(t *testing.T) {
|
||||||
newTable := NewTable("schema", "table", IntegerColumn("intCol"))
|
newTable := NewTable("schema", "table", "", IntegerColumn("intCol"))
|
||||||
|
|
||||||
require.Equal(t, newTable.SchemaName(), "schema")
|
require.Equal(t, newTable.SchemaName(), "schema")
|
||||||
require.Equal(t, newTable.TableName(), "table")
|
require.Equal(t, newTable.TableName(), "table")
|
||||||
|
|
@ -16,8 +16,8 @@ func TestNewTable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewJoinTable(t *testing.T) {
|
func TestNewJoinTable(t *testing.T) {
|
||||||
newTable1 := NewTable("schema", "table", IntegerColumn("intCol1"))
|
newTable1 := NewTable("schema", "table", "", IntegerColumn("intCol1"))
|
||||||
newTable2 := NewTable("schema", "table2", IntegerColumn("intCol2"))
|
newTable2 := NewTable("schema", "table2", "", IntegerColumn("intCol2"))
|
||||||
|
|
||||||
joinTable := NewJoinTable(newTable1, newTable2, InnerJoin, IntegerColumn("intCol1").EQ(IntegerColumn("intCol2")))
|
joinTable := NewJoinTable(newTable1, newTable2, InnerJoin, IntegerColumn("intCol1").EQ(IntegerColumn("intCol2")))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ var (
|
||||||
table1ColBool = BoolColumn("col_bool")
|
table1ColBool = BoolColumn("col_bool")
|
||||||
table1ColDate = DateColumn("col_date")
|
table1ColDate = DateColumn("col_date")
|
||||||
)
|
)
|
||||||
var table1 = NewTable("db", "table1", table1Col1, table1ColInt, table1ColFloat, table1Col3, table1ColTime, table1ColTimez, table1ColBool, table1ColDate, table1ColTimestamp, table1ColTimestampz)
|
var table1 = NewTable("db", "table1", "", table1Col1, table1ColInt, table1ColFloat, table1Col3, table1ColTime, table1ColTimez, table1ColBool, table1ColDate, table1ColTimestamp, table1ColTimestampz)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
table2Col3 = IntegerColumn("col3")
|
table2Col3 = IntegerColumn("col3")
|
||||||
|
|
@ -41,14 +41,14 @@ var (
|
||||||
table2ColTimestampz = TimestampzColumn("col_timestampz")
|
table2ColTimestampz = TimestampzColumn("col_timestampz")
|
||||||
table2ColDate = DateColumn("col_date")
|
table2ColDate = DateColumn("col_date")
|
||||||
)
|
)
|
||||||
var table2 = NewTable("db", "table2", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColTime, table2ColTimez, table2ColDate, table2ColTimestamp, table2ColTimestampz)
|
var table2 = NewTable("db", "table2", "", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColTime, table2ColTimez, table2ColDate, table2ColTimestamp, table2ColTimestampz)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
table3Col1 = IntegerColumn("col1")
|
table3Col1 = IntegerColumn("col1")
|
||||||
table3ColInt = IntegerColumn("col_int")
|
table3ColInt = IntegerColumn("col_int")
|
||||||
table3StrCol = StringColumn("col2")
|
table3StrCol = StringColumn("col2")
|
||||||
)
|
)
|
||||||
var table3 = NewTable("db", "table3", table3Col1, table3ColInt, table3StrCol)
|
var table3 = NewTable("db", "table3", "", table3Col1, table3ColInt, table3StrCol)
|
||||||
|
|
||||||
func assertClauseSerialize(t *testing.T, clause Serializer, query string, args ...interface{}) {
|
func assertClauseSerialize(t *testing.T, clause Serializer, query string, args ...interface{}) {
|
||||||
out := SQLBuilder{Dialect: defaultDialect}
|
out := SQLBuilder{Dialect: defaultDialect}
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,9 @@ func (r readableTableInterfaceImpl) CROSS_JOIN(table ReadableTable) joinSelectUp
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTable creates new table with schema Name, table Name and list of columns
|
// NewTable creates new table with schema Name, table Name and list of columns
|
||||||
func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table {
|
func NewTable(schemaName, name, alias string, columns ...jet.ColumnExpression) Table {
|
||||||
t := &tableImpl{
|
t := &tableImpl{
|
||||||
SerializerTable: jet.NewTable(schemaName, name, columns...),
|
SerializerTable: jet.NewTable(schemaName, name, alias, columns...),
|
||||||
}
|
}
|
||||||
|
|
||||||
t.readableTableInterfaceImpl.parent = t
|
t.readableTableInterfaceImpl.parent = t
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,7 @@ var table1ColTimestamp = TimestampColumn("col_timestamp")
|
||||||
var table1ColDate = DateColumn("col_date")
|
var table1ColDate = DateColumn("col_date")
|
||||||
var table1ColTime = TimeColumn("col_time")
|
var table1ColTime = TimeColumn("col_time")
|
||||||
|
|
||||||
var table1 = NewTable(
|
var table1 = NewTable("db", "table1", "", table1Col1, table1ColInt, table1ColFloat, table1ColString, table1Col3, table1ColBool, table1ColDate, table1ColTimestamp, table1ColTime)
|
||||||
"db",
|
|
||||||
"table1",
|
|
||||||
table1Col1,
|
|
||||||
table1ColInt,
|
|
||||||
table1ColFloat,
|
|
||||||
table1ColString,
|
|
||||||
table1Col3,
|
|
||||||
table1ColBool,
|
|
||||||
table1ColDate,
|
|
||||||
table1ColTimestamp,
|
|
||||||
table1ColTime,
|
|
||||||
)
|
|
||||||
|
|
||||||
var table2Col3 = IntegerColumn("col3")
|
var table2Col3 = IntegerColumn("col3")
|
||||||
var table2Col4 = IntegerColumn("col4")
|
var table2Col4 = IntegerColumn("col4")
|
||||||
|
|
@ -39,28 +27,12 @@ var table2ColBool = BoolColumn("col_bool")
|
||||||
var table2ColTimestamp = TimestampColumn("col_timestamp")
|
var table2ColTimestamp = TimestampColumn("col_timestamp")
|
||||||
var table2ColDate = DateColumn("col_date")
|
var table2ColDate = DateColumn("col_date")
|
||||||
|
|
||||||
var table2 = NewTable(
|
var table2 = NewTable("db", "table2", "", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColDate, table2ColTimestamp)
|
||||||
"db",
|
|
||||||
"table2",
|
|
||||||
table2Col3,
|
|
||||||
table2Col4,
|
|
||||||
table2ColInt,
|
|
||||||
table2ColFloat,
|
|
||||||
table2ColStr,
|
|
||||||
table2ColBool,
|
|
||||||
table2ColDate,
|
|
||||||
table2ColTimestamp,
|
|
||||||
)
|
|
||||||
|
|
||||||
var table3Col1 = IntegerColumn("col1")
|
var table3Col1 = IntegerColumn("col1")
|
||||||
var table3ColInt = IntegerColumn("col_int")
|
var table3ColInt = IntegerColumn("col_int")
|
||||||
var table3StrCol = StringColumn("col2")
|
var table3StrCol = StringColumn("col2")
|
||||||
var table3 = NewTable(
|
var table3 = NewTable("db", "table3", "", table3Col1, table3ColInt, table3StrCol)
|
||||||
"db",
|
|
||||||
"table3",
|
|
||||||
table3Col1,
|
|
||||||
table3ColInt,
|
|
||||||
table3StrCol)
|
|
||||||
|
|
||||||
func assertSerialize(t *testing.T, clause jet.Serializer, query string, args ...interface{}) {
|
func assertSerialize(t *testing.T, clause jet.Serializer, query string, args ...interface{}) {
|
||||||
testutils.AssertSerialize(t, Dialect, clause, query, args...)
|
testutils.AssertSerialize(t, Dialect, clause, query, args...)
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,7 @@ func TestReservedWordEscaped(t *testing.T) {
|
||||||
var table1ColVariadic = IntervalColumn("VARIADIC")
|
var table1ColVariadic = IntervalColumn("VARIADIC")
|
||||||
var table1ColProcedure = IntervalColumn("procedure")
|
var table1ColProcedure = IntervalColumn("procedure")
|
||||||
|
|
||||||
_ = NewTable(
|
_ = NewTable("db", "table1", "", table1ColUser, table1ColVariadic, table1ColProcedure)
|
||||||
"db",
|
|
||||||
"table1",
|
|
||||||
table1ColUser,
|
|
||||||
table1ColVariadic,
|
|
||||||
table1ColProcedure,
|
|
||||||
)
|
|
||||||
|
|
||||||
assertSerialize(t, table1ColUser, `table1."user"`)
|
assertSerialize(t, table1ColUser, `table1."user"`)
|
||||||
assertSerialize(t, table1ColVariadic, `table1."VARIADIC"`)
|
assertSerialize(t, table1ColVariadic, `table1."VARIADIC"`)
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@ type tableImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTable creates new table with schema Name, table Name and list of columns
|
// NewTable creates new table with schema Name, table Name and list of columns
|
||||||
func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table {
|
func NewTable(schemaName, name, alias string, columns ...jet.ColumnExpression) Table {
|
||||||
|
|
||||||
t := &tableImpl{
|
t := &tableImpl{
|
||||||
SerializerTable: jet.NewTable(schemaName, name, columns...),
|
SerializerTable: jet.NewTable(schemaName, name, alias, columns...),
|
||||||
}
|
}
|
||||||
|
|
||||||
t.readableTableInterfaceImpl.parent = t
|
t.readableTableInterfaceImpl.parent = t
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ var table1ColInterval = IntervalColumn("col_interval")
|
||||||
var table1 = NewTable(
|
var table1 = NewTable(
|
||||||
"db",
|
"db",
|
||||||
"table1",
|
"table1",
|
||||||
|
"",
|
||||||
table1Col1,
|
table1Col1,
|
||||||
table1ColInt,
|
table1ColInt,
|
||||||
table1ColFloat,
|
table1ColFloat,
|
||||||
|
|
@ -46,32 +47,12 @@ var table2ColTimestampz = TimestampzColumn("col_timestampz")
|
||||||
var table2ColDate = DateColumn("col_date")
|
var table2ColDate = DateColumn("col_date")
|
||||||
var table2ColInterval = IntervalColumn("col_interval")
|
var table2ColInterval = IntervalColumn("col_interval")
|
||||||
|
|
||||||
var table2 = NewTable(
|
var table2 = NewTable("db", "table2", "", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColTime, table2ColTimez, table2ColDate, table2ColTimestamp, table2ColTimestampz, table2ColInterval)
|
||||||
"db",
|
|
||||||
"table2",
|
|
||||||
table2Col3,
|
|
||||||
table2Col4,
|
|
||||||
table2ColInt,
|
|
||||||
table2ColFloat,
|
|
||||||
table2ColStr,
|
|
||||||
table2ColBool,
|
|
||||||
table2ColTime,
|
|
||||||
table2ColTimez,
|
|
||||||
table2ColDate,
|
|
||||||
table2ColTimestamp,
|
|
||||||
table2ColTimestampz,
|
|
||||||
table2ColInterval,
|
|
||||||
)
|
|
||||||
|
|
||||||
var table3Col1 = IntegerColumn("col1")
|
var table3Col1 = IntegerColumn("col1")
|
||||||
var table3ColInt = IntegerColumn("col_int")
|
var table3ColInt = IntegerColumn("col_int")
|
||||||
var table3StrCol = StringColumn("col2")
|
var table3StrCol = StringColumn("col2")
|
||||||
var table3 = NewTable(
|
var table3 = NewTable("db", "table3", "", table3Col1, table3ColInt, table3StrCol)
|
||||||
"db",
|
|
||||||
"table3",
|
|
||||||
table3Col1,
|
|
||||||
table3ColInt,
|
|
||||||
table3StrCol)
|
|
||||||
|
|
||||||
func assertSerialize(t *testing.T, serializer jet.Serializer, query string, args ...interface{}) {
|
func assertSerialize(t *testing.T, serializer jet.Serializer, query string, args ...interface{}) {
|
||||||
testutils.AssertSerialize(t, Dialect, serializer, query, args...)
|
testutils.AssertSerialize(t, Dialect, serializer, query, args...)
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ func initMySQLDB() {
|
||||||
|
|
||||||
mySQLDBs := []string{
|
mySQLDBs := []string{
|
||||||
"dvds",
|
"dvds",
|
||||||
|
"dvds2",
|
||||||
"test_sample",
|
"test_sample",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,6 +90,7 @@ func initPostgresDB() {
|
||||||
"dvds",
|
"dvds",
|
||||||
"test_sample",
|
"test_sample",
|
||||||
"chinook",
|
"chinook",
|
||||||
|
"chinook2",
|
||||||
"northwind",
|
"northwind",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -974,7 +973,7 @@ func TestAllTypesInsert(t *testing.T) {
|
||||||
stmt := AllTypes.INSERT(AllTypes.AllColumns).
|
stmt := AllTypes.INSERT(AllTypes.AllColumns).
|
||||||
MODEL(toInsert)
|
MODEL(toInsert)
|
||||||
|
|
||||||
fmt.Println(stmt.DebugSql())
|
//fmt.Println(stmt.DebugSql())
|
||||||
|
|
||||||
testutils.AssertExec(t, stmt, tx, 1)
|
testutils.AssertExec(t, stmt, tx, 1)
|
||||||
|
|
||||||
|
|
@ -1028,7 +1027,7 @@ func TestAllTypesInsertOnDuplicateKeyUpdate(t *testing.T) {
|
||||||
AllTypes.Date.SET(DateT(time.Now())),
|
AllTypes.Date.SET(DateT(time.Now())),
|
||||||
)
|
)
|
||||||
|
|
||||||
fmt.Println(stmt.DebugSql())
|
//fmt.Println(stmt.DebugSql())
|
||||||
|
|
||||||
_, err = stmt.Exec(tx)
|
_, err = stmt.Exec(tx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -1257,7 +1256,7 @@ FROM test_sample.user;
|
||||||
err := stmt.Query(db, &dest)
|
err := stmt.Query(db, &dest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.PrintJson(dest)
|
//testutils.PrintJson(dest)
|
||||||
|
|
||||||
testutils.AssertJSON(t, dest, `
|
testutils.AssertJSON(t, dest, `
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/mysql"
|
"github.com/go-jet/jet/v2/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Actor = newActorTable()
|
var Actor = newActorTable("dvds", "actor", "")
|
||||||
|
|
||||||
type ActorTable struct {
|
type ActorTable struct {
|
||||||
mysql.Table
|
mysql.Table
|
||||||
|
|
@ -151,13 +151,16 @@ type ActorTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorTable with assigned alias
|
// AS creates new ActorTable with assigned alias
|
||||||
func (a *ActorTable) AS(alias string) ActorTable {
|
func (a ActorTable) AS(alias string) ActorTable {
|
||||||
aliasTable := newActorTable()
|
return newActorTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
var (
|
||||||
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = mysql.StringColumn("first_name")
|
FirstNameColumn = mysql.StringColumn("first_name")
|
||||||
|
|
@ -168,7 +171,7 @@ func newActorTable() ActorTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return ActorTable{
|
return ActorTable{
|
||||||
Table: mysql.NewTable("dvds", "actor", allColumns...),
|
Table: mysql.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
@ -218,7 +221,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/mysql"
|
"github.com/go-jet/jet/v2/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ActorInfo = newActorInfoTable()
|
var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||||
|
|
||||||
type ActorInfoTable struct {
|
type ActorInfoTable struct {
|
||||||
mysql.Table
|
mysql.Table
|
||||||
|
|
@ -234,13 +237,16 @@ type ActorInfoTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorInfoTable with assigned alias
|
// AS creates new ActorInfoTable with assigned alias
|
||||||
func (a *ActorInfoTable) AS(alias string) ActorInfoTable {
|
func (a ActorInfoTable) AS(alias string) ActorInfoTable {
|
||||||
aliasTable := newActorInfoTable()
|
return newActorInfoTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
var (
|
||||||
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
ActorIDColumn = mysql.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = mysql.StringColumn("first_name")
|
FirstNameColumn = mysql.StringColumn("first_name")
|
||||||
|
|
@ -251,7 +257,7 @@ func newActorInfoTable() ActorInfoTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return ActorInfoTable{
|
return ActorInfoTable{
|
||||||
Table: mysql.NewTable("dvds", "actor_info", allColumns...),
|
Table: mysql.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
|
||||||
|
|
@ -744,3 +744,46 @@ LIMIT 3;
|
||||||
|
|
||||||
require.Equal(t, len(dest), 3)
|
require.Equal(t, len(dest), 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_SchemaRename(t *testing.T) {
|
||||||
|
Film := Film.FromSchema("dvds2")
|
||||||
|
Language := Language.FromSchema("dvds2")
|
||||||
|
|
||||||
|
stmt := SELECT(
|
||||||
|
Film.FilmID,
|
||||||
|
Film.Title,
|
||||||
|
Language.LanguageID,
|
||||||
|
Language.Name,
|
||||||
|
).FROM(
|
||||||
|
Language.
|
||||||
|
INNER_JOIN(Film, Film.LanguageID.EQ(Language.LanguageID)),
|
||||||
|
).WHERE(
|
||||||
|
Language.LanguageID.EQ(Int(1)),
|
||||||
|
).ORDER_BY(
|
||||||
|
Language.LanguageID, Film.FilmID,
|
||||||
|
).LIMIT(5)
|
||||||
|
|
||||||
|
testutils.AssertDebugStatementSql(t, stmt, `
|
||||||
|
SELECT film.film_id AS "film.film_id",
|
||||||
|
film.title AS "film.title",
|
||||||
|
language.language_id AS "language.language_id",
|
||||||
|
language.name AS "language.name"
|
||||||
|
FROM dvds2.language
|
||||||
|
INNER JOIN dvds2.film ON (film.language_id = language.language_id)
|
||||||
|
WHERE language.language_id = 1
|
||||||
|
ORDER BY language.language_id, film.film_id
|
||||||
|
LIMIT 5;
|
||||||
|
`)
|
||||||
|
|
||||||
|
dest := struct {
|
||||||
|
model.Language
|
||||||
|
Films []model.Film
|
||||||
|
}{}
|
||||||
|
|
||||||
|
err := stmt.Query(db, &dest)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, dest.Films, 5)
|
||||||
|
require.Equal(t, dest.Films[0].Title, "ACADEMY DINOSAUR")
|
||||||
|
require.Equal(t, dest.Films[1].Title, "ACE GOLDFINGER")
|
||||||
|
require.Equal(t, dest.Films[4].Title, "AFRICAN EGG")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
. "github.com/go-jet/jet/v2/mysql"
|
. "github.com/go-jet/jet/v2/mysql"
|
||||||
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/dvds/table"
|
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/dvds/table"
|
||||||
|
|
@ -193,7 +192,7 @@ SET url = 'http://www.duckduckgo.com',
|
||||||
description = NULL
|
description = NULL
|
||||||
WHERE link.id = 201;
|
WHERE link.id = 201;
|
||||||
`
|
`
|
||||||
fmt.Println(stmt.DebugSql())
|
//fmt.Println(stmt.DebugSql())
|
||||||
|
|
||||||
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "http://www.duckduckgo.com", "DuckDuckGo", nil, int64(201))
|
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "http://www.duckduckgo.com", "DuckDuckGo", nil, int64(201))
|
||||||
testutils.AssertExec(t, stmt, db)
|
testutils.AssertExec(t, stmt, db)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package postgres
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
. "github.com/go-jet/jet/v2/postgres"
|
. "github.com/go-jet/jet/v2/postgres"
|
||||||
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/chinook/model"
|
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/chinook/model"
|
||||||
|
|
@ -17,7 +16,7 @@ func TestSelect(t *testing.T) {
|
||||||
SELECT(Album.AllColumns).
|
SELECT(Album.AllColumns).
|
||||||
ORDER_BY(Album.AlbumId.ASC())
|
ORDER_BY(Album.AlbumId.ASC())
|
||||||
|
|
||||||
fmt.Println(stmt.DebugSql())
|
//fmt.Println(stmt.DebugSql())
|
||||||
|
|
||||||
testutils.AssertDebugStatementSql(t, stmt, `
|
testutils.AssertDebugStatementSql(t, stmt, `
|
||||||
SELECT "Album"."AlbumId" AS "Album.AlbumId",
|
SELECT "Album"."AlbumId" AS "Album.AlbumId",
|
||||||
|
|
@ -330,8 +329,71 @@ ORDER BY "first10Artist"."Artist.ArtistId";
|
||||||
err := stmt.Query(db, &dest)
|
err := stmt.Query(db, &dest)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
//spew.Dump(dest)
|
func Test_SchemaRename(t *testing.T) {
|
||||||
|
|
||||||
|
Artist2 := Artist.FromSchema("chinook2")
|
||||||
|
Album2 := Album.FromSchema("chinook2")
|
||||||
|
|
||||||
|
first10Artist := Artist2.
|
||||||
|
SELECT(Artist2.AllColumns).
|
||||||
|
ORDER_BY(Artist2.ArtistId).
|
||||||
|
LIMIT(10).
|
||||||
|
AsTable("first10Artist")
|
||||||
|
|
||||||
|
artistID := Artist2.ArtistId.From(first10Artist)
|
||||||
|
|
||||||
|
first10Albums := Album2.
|
||||||
|
SELECT(Album2.AllColumns).
|
||||||
|
ORDER_BY(Album2.AlbumId).
|
||||||
|
LIMIT(10).
|
||||||
|
AsTable("first10Albums")
|
||||||
|
|
||||||
|
albumArtistID := Album2.ArtistId.From(first10Albums)
|
||||||
|
|
||||||
|
stmt := SELECT(first10Artist.AllColumns(), first10Albums.AllColumns()).
|
||||||
|
FROM(first10Artist.
|
||||||
|
INNER_JOIN(first10Albums, artistID.EQ(albumArtistID))).
|
||||||
|
ORDER_BY(artistID)
|
||||||
|
|
||||||
|
testutils.AssertDebugStatementSql(t, stmt, `
|
||||||
|
SELECT "first10Artist"."Artist.ArtistId" AS "Artist.ArtistId",
|
||||||
|
"first10Artist"."Artist.Name" AS "Artist.Name",
|
||||||
|
"first10Albums"."Album.AlbumId" AS "Album.AlbumId",
|
||||||
|
"first10Albums"."Album.Title" AS "Album.Title",
|
||||||
|
"first10Albums"."Album.ArtistId" AS "Album.ArtistId"
|
||||||
|
FROM (
|
||||||
|
SELECT "Artist"."ArtistId" AS "Artist.ArtistId",
|
||||||
|
"Artist"."Name" AS "Artist.Name"
|
||||||
|
FROM chinook2."Artist"
|
||||||
|
ORDER BY "Artist"."ArtistId"
|
||||||
|
LIMIT 10
|
||||||
|
) AS "first10Artist"
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT "Album"."AlbumId" AS "Album.AlbumId",
|
||||||
|
"Album"."Title" AS "Album.Title",
|
||||||
|
"Album"."ArtistId" AS "Album.ArtistId"
|
||||||
|
FROM chinook2."Album"
|
||||||
|
ORDER BY "Album"."AlbumId"
|
||||||
|
LIMIT 10
|
||||||
|
) AS "first10Albums" ON ("first10Artist"."Artist.ArtistId" = "first10Albums"."Album.ArtistId")
|
||||||
|
ORDER BY "first10Artist"."Artist.ArtistId";
|
||||||
|
`)
|
||||||
|
|
||||||
|
var dest []struct {
|
||||||
|
model.Artist
|
||||||
|
|
||||||
|
Album []model.Album
|
||||||
|
}
|
||||||
|
|
||||||
|
err := stmt.Query(db, &dest)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Len(t, dest, 2)
|
||||||
|
require.Equal(t, *dest[0].Artist.Name, "Apocalyptica")
|
||||||
|
require.Len(t, dest[0].Album, 1)
|
||||||
|
require.Equal(t, dest[0].Album[0].Title, "Plays Metallica By Four Cellos")
|
||||||
}
|
}
|
||||||
|
|
||||||
var album1 = model.Album{
|
var album1 = model.Album{
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Actor = newActorTable()
|
var Actor = newActorTable("dvds", "actor", "")
|
||||||
|
|
||||||
type actorTable struct {
|
type actorTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -190,20 +190,23 @@ type ActorTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorTable with assigned alias
|
// AS creates new ActorTable with assigned alias
|
||||||
func (a *ActorTable) AS(alias string) *ActorTable {
|
func (a ActorTable) AS(alias string) *ActorTable {
|
||||||
aliasTable := newActorTable()
|
return newActorTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return &ActorTable{
|
return &ActorTable{
|
||||||
actorTable: newActorTableImpl("dvds", "actor"),
|
actorTable: newActorTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newActorTableImpl("", "excluded"),
|
EXCLUDED: newActorTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newActorTableImpl(schemaName, tableName string) actorTable {
|
func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
var (
|
var (
|
||||||
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = postgres.StringColumn("first_name")
|
FirstNameColumn = postgres.StringColumn("first_name")
|
||||||
|
|
@ -214,7 +217,7 @@ func newActorTableImpl(schemaName, tableName string) actorTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return actorTable{
|
return actorTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
@ -264,7 +267,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ActorInfo = newActorInfoTable()
|
var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||||
|
|
||||||
type actorInfoTable struct {
|
type actorInfoTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -286,20 +289,23 @@ type ActorInfoTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new ActorInfoTable with assigned alias
|
// AS creates new ActorInfoTable with assigned alias
|
||||||
func (a *ActorInfoTable) AS(alias string) *ActorInfoTable {
|
func (a ActorInfoTable) AS(alias string) *ActorInfoTable {
|
||||||
aliasTable := newActorInfoTable()
|
return newActorInfoTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return &ActorInfoTable{
|
return &ActorInfoTable{
|
||||||
actorInfoTable: newActorInfoTableImpl("dvds", "actor_info"),
|
actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newActorInfoTableImpl("", "excluded"),
|
EXCLUDED: newActorInfoTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newActorInfoTableImpl(schemaName, tableName string) actorInfoTable {
|
func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
|
||||||
var (
|
var (
|
||||||
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
ActorIDColumn = postgres.IntegerColumn("actor_id")
|
||||||
FirstNameColumn = postgres.StringColumn("first_name")
|
FirstNameColumn = postgres.StringColumn("first_name")
|
||||||
|
|
@ -310,7 +316,7 @@ func newActorInfoTableImpl(schemaName, tableName string) actorInfoTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return actorInfoTable{
|
return actorInfoTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
ActorID: ActorIDColumn,
|
ActorID: ActorIDColumn,
|
||||||
|
|
@ -497,7 +503,7 @@ import (
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AllTypes = newAllTypesTable()
|
var AllTypes = newAllTypesTable("test_sample", "all_types", "")
|
||||||
|
|
||||||
type allTypesTable struct {
|
type allTypesTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
@ -576,20 +582,23 @@ type AllTypesTable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AS creates new AllTypesTable with assigned alias
|
// AS creates new AllTypesTable with assigned alias
|
||||||
func (a *AllTypesTable) AS(alias string) *AllTypesTable {
|
func (a AllTypesTable) AS(alias string) *AllTypesTable {
|
||||||
aliasTable := newAllTypesTable()
|
return newAllTypesTable(a.SchemaName(), a.TableName(), alias)
|
||||||
aliasTable.Table.AS(alias)
|
|
||||||
return aliasTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAllTypesTable() *AllTypesTable {
|
// Schema creates new AllTypesTable with assigned schema name
|
||||||
|
func (a AllTypesTable) FromSchema(schemaName string) *AllTypesTable {
|
||||||
|
return newAllTypesTable(schemaName, a.TableName(), a.Alias())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAllTypesTable(schemaName, tableName, alias string) *AllTypesTable {
|
||||||
return &AllTypesTable{
|
return &AllTypesTable{
|
||||||
allTypesTable: newAllTypesTableImpl("test_sample", "all_types"),
|
allTypesTable: newAllTypesTableImpl(schemaName, tableName, alias),
|
||||||
EXCLUDED: newAllTypesTableImpl("", "excluded"),
|
EXCLUDED: newAllTypesTableImpl("", "excluded", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAllTypesTableImpl(schemaName, tableName string) allTypesTable {
|
func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
|
||||||
var (
|
var (
|
||||||
SmallIntPtrColumn = postgres.IntegerColumn("small_int_ptr")
|
SmallIntPtrColumn = postgres.IntegerColumn("small_int_ptr")
|
||||||
SmallIntColumn = postgres.IntegerColumn("small_int")
|
SmallIntColumn = postgres.IntegerColumn("small_int")
|
||||||
|
|
@ -657,7 +666,7 @@ func newAllTypesTableImpl(schemaName, tableName string) allTypesTable {
|
||||||
)
|
)
|
||||||
|
|
||||||
return allTypesTable{
|
return allTypesTable{
|
||||||
Table: postgres.NewTable(schemaName, tableName, allColumns...),
|
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||||
|
|
||||||
//Columns
|
//Columns
|
||||||
SmallIntPtr: SmallIntPtrColumn,
|
SmallIntPtr: SmallIntPtrColumn,
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ FROM test_sample."User";
|
||||||
err := stmt.Query(db, &dest)
|
err := stmt.Query(db, &dest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.PrintJson(dest)
|
//testutils.PrintJson(dest)
|
||||||
|
|
||||||
testutils.AssertJSON(t, dest, `
|
testutils.AssertJSON(t, dest, `
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package postgres
|
package postgres
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
. "github.com/go-jet/jet/v2/postgres"
|
. "github.com/go-jet/jet/v2/postgres"
|
||||||
"github.com/go-jet/jet/v2/qrm"
|
"github.com/go-jet/jet/v2/qrm"
|
||||||
|
|
@ -93,7 +92,7 @@ func TestScanToStruct(t *testing.T) {
|
||||||
SELECT(Inventory.AllColumns).
|
SELECT(Inventory.AllColumns).
|
||||||
ORDER_BY(Inventory.InventoryID)
|
ORDER_BY(Inventory.InventoryID)
|
||||||
|
|
||||||
fmt.Println(query.DebugSql())
|
//fmt.Println(query.DebugSql())
|
||||||
|
|
||||||
t.Run("one struct", func(t *testing.T) {
|
t.Run("one struct", func(t *testing.T) {
|
||||||
dest := model.Inventory{}
|
dest := model.Inventory{}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package postgres
|
package postgres
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
. "github.com/go-jet/jet/v2/postgres"
|
. "github.com/go-jet/jet/v2/postgres"
|
||||||
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/dvds/enum"
|
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/dvds/enum"
|
||||||
|
|
@ -1255,7 +1254,7 @@ OFFSET 20;
|
||||||
LIMIT(10).
|
LIMIT(10).
|
||||||
OFFSET(20)
|
OFFSET(20)
|
||||||
|
|
||||||
fmt.Println(query.DebugSql())
|
//fmt.Println(query.DebugSql())
|
||||||
|
|
||||||
testutils.AssertDebugStatementSql(t, query, expectedQuery, float64(100), float64(200), int64(10), int64(20))
|
testutils.AssertDebugStatementSql(t, query, expectedQuery, float64(100), float64(200), int64(10), int64(20))
|
||||||
|
|
||||||
|
|
@ -1788,7 +1787,7 @@ func TestJoinViewWithTable(t *testing.T) {
|
||||||
Rentals []model.Rental
|
Rentals []model.Rental
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(query.DebugSql())
|
//fmt.Println(query.DebugSql())
|
||||||
|
|
||||||
err := query.Query(db, &dest)
|
err := query.Query(db, &dest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit ed53a505eb738d1be457877eee251f9ba0418df1
|
Subproject commit 391d936515d2f826df073707697de44907a7f67d
|
||||||
Loading…
Add table
Add a link
Reference in a new issue