diff --git a/tests/mysql/generator_test.go b/tests/mysql/generator_test.go index a414df3..9c3d3fb 100644 --- a/tests/mysql/generator_test.go +++ b/tests/mysql/generator_test.go @@ -236,6 +236,16 @@ func (a ActorTable) FromSchema(schemaName string) ActorTable { return newActorTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new ActorTable with assigned table prefix +func (a ActorTable) WithPrefix(prefix string) ActorTable { + return newActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ActorTable with assigned table suffix +func (a ActorTable) WithSuffix(suffix string) ActorTable { + return newActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newActorTable(schemaName, tableName, alias string) ActorTable { var ( ActorIDColumn = mysql.IntegerColumn("actor_id") @@ -322,6 +332,16 @@ func (a ActorInfoTable) FromSchema(schemaName string) ActorInfoTable { return newActorInfoTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new ActorInfoTable with assigned table prefix +func (a ActorInfoTable) WithPrefix(prefix string) ActorInfoTable { + return newActorInfoTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ActorInfoTable with assigned table suffix +func (a ActorInfoTable) WithSuffix(suffix string) ActorInfoTable { + return newActorInfoTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newActorInfoTable(schemaName, tableName, alias string) ActorInfoTable { var ( ActorIDColumn = mysql.IntegerColumn("actor_id") diff --git a/tests/postgres/generator_test.go b/tests/postgres/generator_test.go index 852745b..a2cc7de 100644 --- a/tests/postgres/generator_test.go +++ b/tests/postgres/generator_test.go @@ -313,6 +313,16 @@ func (a ActorTable) FromSchema(schemaName string) *ActorTable { return newActorTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new ActorTable with assigned table prefix +func (a ActorTable) WithPrefix(prefix string) *ActorTable { + return newActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ActorTable with assigned table suffix +func (a ActorTable) WithSuffix(suffix string) *ActorTable { + return newActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newActorTable(schemaName, tableName, alias string) *ActorTable { return &ActorTable{ actorTable: newActorTableImpl(schemaName, tableName, alias), @@ -412,6 +422,16 @@ func (a ActorInfoTable) FromSchema(schemaName string) *ActorInfoTable { return newActorInfoTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new ActorInfoTable with assigned table prefix +func (a ActorInfoTable) WithPrefix(prefix string) *ActorInfoTable { + return newActorInfoTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ActorInfoTable with assigned table suffix +func (a ActorInfoTable) WithSuffix(suffix string) *ActorInfoTable { + return newActorInfoTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newActorInfoTable(schemaName, tableName, alias string) *ActorInfoTable { return &ActorInfoTable{ actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias), @@ -705,6 +725,16 @@ func (a AllTypesTable) FromSchema(schemaName string) *AllTypesTable { return newAllTypesTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new AllTypesTable with assigned table prefix +func (a AllTypesTable) WithPrefix(prefix string) *AllTypesTable { + return newAllTypesTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new AllTypesTable with assigned table suffix +func (a AllTypesTable) WithSuffix(suffix string) *AllTypesTable { + return newAllTypesTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newAllTypesTable(schemaName, tableName, alias string) *AllTypesTable { return &AllTypesTable{ allTypesTable: newAllTypesTableImpl(schemaName, tableName, alias), diff --git a/tests/sqlite/generator_test.go b/tests/sqlite/generator_test.go index b8280fd..9665387 100644 --- a/tests/sqlite/generator_test.go +++ b/tests/sqlite/generator_test.go @@ -1,16 +1,17 @@ package sqlite import ( - "github.com/go-jet/jet/v2/generator/sqlite" - "github.com/go-jet/jet/v2/internal/testutils" - "github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/sakila/model" - "github.com/go-jet/jet/v2/tests/internal/utils/repo" - "github.com/stretchr/testify/require" "io/ioutil" "os" "os/exec" "reflect" "testing" + + "github.com/go-jet/jet/v2/generator/sqlite" + "github.com/go-jet/jet/v2/internal/testutils" + "github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/sakila/model" + "github.com/go-jet/jet/v2/tests/internal/utils/repo" + "github.com/stretchr/testify/require" ) func TestGeneratedModel(t *testing.T) { @@ -183,6 +184,16 @@ func (a ActorTable) FromSchema(schemaName string) *ActorTable { return newActorTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new ActorTable with assigned table prefix +func (a ActorTable) WithPrefix(prefix string) *ActorTable { + return newActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ActorTable with assigned table suffix +func (a ActorTable) WithSuffix(suffix string) *ActorTable { + return newActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newActorTable(schemaName, tableName, alias string) *ActorTable { return &ActorTable{ actorTable: newActorTableImpl(schemaName, tableName, alias), @@ -264,6 +275,16 @@ func (a FilmListTable) FromSchema(schemaName string) *FilmListTable { return newFilmListTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new FilmListTable with assigned table prefix +func (a FilmListTable) WithPrefix(prefix string) *FilmListTable { + return newFilmListTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new FilmListTable with assigned table suffix +func (a FilmListTable) WithSuffix(suffix string) *FilmListTable { + return newFilmListTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newFilmListTable(schemaName, tableName, alias string) *FilmListTable { return &FilmListTable{ filmListTable: newFilmListTableImpl(schemaName, tableName, alias),