diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..2d30c21 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**Environment (please complete the following information):** + - OS: [e.g. linux, windows, macosx] + - Database: [e.g. postgres, mysql, sqlite] +- Database driver: [e.g. pq, pgx] + - Jet version [e.g. 2.6.0 or branch name] + +**Code snippet** +Query statement and model files of interest. + +**Expected behavior** +A clear and concise description of what you expected to happen. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..ddb2d63 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,14 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: missing feature +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. diff --git a/examples/quick-start/.gen/jetdb/dvds/table/actor.go b/examples/quick-start/.gen/jetdb/dvds/table/actor.go index bbeb7e8..37e0f85 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/actor.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/actor.go @@ -42,6 +42,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), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/category.go b/examples/quick-start/.gen/jetdb/dvds/table/category.go index 563938d..87beb46 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/category.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/category.go @@ -41,6 +41,16 @@ func (a CategoryTable) FromSchema(schemaName string) *CategoryTable { return newCategoryTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new CategoryTable with assigned table prefix +func (a CategoryTable) WithPrefix(prefix string) *CategoryTable { + return newCategoryTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new CategoryTable with assigned table suffix +func (a CategoryTable) WithSuffix(suffix string) *CategoryTable { + return newCategoryTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newCategoryTable(schemaName, tableName, alias string) *CategoryTable { return &CategoryTable{ categoryTable: newCategoryTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film.go b/examples/quick-start/.gen/jetdb/dvds/table/film.go index 65db900..4636408 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film.go @@ -51,6 +51,16 @@ func (a FilmTable) FromSchema(schemaName string) *FilmTable { return newFilmTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new FilmTable with assigned table prefix +func (a FilmTable) WithPrefix(prefix string) *FilmTable { + return newFilmTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new FilmTable with assigned table suffix +func (a FilmTable) WithSuffix(suffix string) *FilmTable { + return newFilmTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newFilmTable(schemaName, tableName, alias string) *FilmTable { return &FilmTable{ filmTable: newFilmTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go b/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go index 30c3ad3..7fe60c3 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go @@ -41,6 +41,16 @@ func (a FilmActorTable) FromSchema(schemaName string) *FilmActorTable { return newFilmActorTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new FilmActorTable with assigned table prefix +func (a FilmActorTable) WithPrefix(prefix string) *FilmActorTable { + return newFilmActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new FilmActorTable with assigned table suffix +func (a FilmActorTable) WithSuffix(suffix string) *FilmActorTable { + return newFilmActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newFilmActorTable(schemaName, tableName, alias string) *FilmActorTable { return &FilmActorTable{ filmActorTable: newFilmActorTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film_category.go b/examples/quick-start/.gen/jetdb/dvds/table/film_category.go index 8368177..fb3bfb6 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film_category.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film_category.go @@ -41,6 +41,16 @@ func (a FilmCategoryTable) FromSchema(schemaName string) *FilmCategoryTable { return newFilmCategoryTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new FilmCategoryTable with assigned table prefix +func (a FilmCategoryTable) WithPrefix(prefix string) *FilmCategoryTable { + return newFilmCategoryTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new FilmCategoryTable with assigned table suffix +func (a FilmCategoryTable) WithSuffix(suffix string) *FilmCategoryTable { + return newFilmCategoryTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newFilmCategoryTable(schemaName, tableName, alias string) *FilmCategoryTable { return &FilmCategoryTable{ filmCategoryTable: newFilmCategoryTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/language.go b/examples/quick-start/.gen/jetdb/dvds/table/language.go index 5bddeeb..24f037d 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/language.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/language.go @@ -41,6 +41,16 @@ func (a LanguageTable) FromSchema(schemaName string) *LanguageTable { return newLanguageTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new LanguageTable with assigned table prefix +func (a LanguageTable) WithPrefix(prefix string) *LanguageTable { + return newLanguageTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new LanguageTable with assigned table suffix +func (a LanguageTable) WithSuffix(suffix string) *LanguageTable { + return newLanguageTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newLanguageTable(schemaName, tableName, alias string) *LanguageTable { return &LanguageTable{ languageTable: newLanguageTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go b/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go index 5bfa25d..23f81aa 100644 --- a/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go +++ b/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go @@ -42,6 +42,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), diff --git a/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go b/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go index c03a5ef..cdf14ca 100644 --- a/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go +++ b/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go @@ -47,6 +47,16 @@ func (a CustomerListTable) FromSchema(schemaName string) *CustomerListTable { return newCustomerListTable(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new CustomerListTable with assigned table prefix +func (a CustomerListTable) WithPrefix(prefix string) *CustomerListTable { + return newCustomerListTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new CustomerListTable with assigned table suffix +func (a CustomerListTable) WithSuffix(suffix string) *CustomerListTable { + return newCustomerListTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func newCustomerListTable(schemaName, tableName, alias string) *CustomerListTable { return &CustomerListTable{ customerListTable: newCustomerListTableImpl(schemaName, tableName, alias), diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index e3020ce..d1f1260 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -49,6 +49,16 @@ func (a {{tableTemplate.TypeName}}) FromSchema(schemaName string) {{tableTemplat return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new {{tableTemplate.TypeName}} with assigned table prefix +func (a {{tableTemplate.TypeName}}) WithPrefix(prefix string) {{tableTemplate.TypeName}} { + return new{{tableTemplate.TypeName}}(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new {{tableTemplate.TypeName}} with assigned table suffix +func (a {{tableTemplate.TypeName}}) WithSuffix(suffix string) {{tableTemplate.TypeName}} { + return new{{tableTemplate.TypeName}}(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) {{tableTemplate.TypeName}} { var ( {{- range $i, $c := .Columns}} @@ -119,6 +129,16 @@ func (a {{tableTemplate.TypeName}}) FromSchema(schemaName string) *{{tableTempla return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias()) } +// WithPrefix creates new {{tableTemplate.TypeName}} with assigned table prefix +func (a {{tableTemplate.TypeName}}) WithPrefix(prefix string) *{{tableTemplate.TypeName}} { + return new{{tableTemplate.TypeName}}(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new {{tableTemplate.TypeName}} with assigned table suffix +func (a {{tableTemplate.TypeName}}) WithSuffix(suffix string) *{{tableTemplate.TypeName}} { + return new{{tableTemplate.TypeName}}(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) *{{tableTemplate.TypeName}} { return &{{tableTemplate.TypeName}}{ {{structImplName}}: new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias), 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),