added a check for skipping generation of table SQL builder code
This commit is contained in:
parent
a792fe6e0a
commit
882d5562f3
3 changed files with 41 additions and 5 deletions
|
|
@ -71,16 +71,20 @@ func processTableSQLBuilderSetSchema(dirPath string, schemaMetadata metadata.Sch
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Generating global `SetSchema` method...")
|
|
||||||
|
|
||||||
err := utils.EnsureDirPath(dirPath)
|
err := utils.EnsureDirPath(dirPath)
|
||||||
throw.OnError(err)
|
throw.OnError(err)
|
||||||
|
|
||||||
var builders []TableSQLBuilder
|
var builders []TableSQLBuilder
|
||||||
for _, tm := range schemaMetadata.TablesMetaData {
|
for _, tm := range schemaMetadata.TablesMetaData {
|
||||||
builders = append(builders, builderTemplate.Table(tm))
|
table := builderTemplate.Table(tm)
|
||||||
|
builders = append(builders, table)
|
||||||
|
|
||||||
|
if table.Skip {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Generating global `SetSchema` method...")
|
||||||
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
||||||
|
|
||||||
funcPath := path.Join(dirPath, builders[0].Path)
|
funcPath := path.Join(dirPath, builders[0].Path)
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/go-jet/jet/v2/generator/postgres"
|
"github.com/go-jet/jet/v2/generator/postgres"
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/dvds/model"
|
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/dvds/model"
|
||||||
)
|
)
|
||||||
|
|
@ -913,4 +914,15 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
|
||||||
MutableColumns: mutableColumns,
|
MutableColumns: mutableColumns,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetTestSampleSchema(schema string) {
|
||||||
|
AllTypes = AllTypes.FromSchema(schema)
|
||||||
|
Link = Link.FromSchema(schema)
|
||||||
|
Employee = Employee.FromSchema(schema)
|
||||||
|
Person = Person.FromSchema(schema)
|
||||||
|
PersonPhone = PersonPhone.FromSchema(schema)
|
||||||
|
WeirdNamesTable = WeirdNamesTable.FromSchema(schema)
|
||||||
|
User = User.FromSchema(schema)
|
||||||
|
Floats = Floats.FromSchema(schema)
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/go-jet/jet/v2/generator/sqlite"
|
"github.com/go-jet/jet/v2/generator/sqlite"
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"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/.gentestdata/sqlite/sakila/model"
|
||||||
"github.com/go-jet/jet/v2/tests/internal/utils/repo"
|
"github.com/go-jet/jet/v2/tests/internal/utils/repo"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGeneratedModel(t *testing.T) {
|
func TestGeneratedModel(t *testing.T) {
|
||||||
|
|
@ -224,6 +225,25 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
MutableColumns: mutableColumns,
|
MutableColumns: mutableColumns,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetSchema(schema string) {
|
||||||
|
Actor = Actor.FromSchema(schema)
|
||||||
|
Address = Address.FromSchema(schema)
|
||||||
|
Category = Category.FromSchema(schema)
|
||||||
|
City = City.FromSchema(schema)
|
||||||
|
Country = Country.FromSchema(schema)
|
||||||
|
Customer = Customer.FromSchema(schema)
|
||||||
|
Film = Film.FromSchema(schema)
|
||||||
|
FilmActor = FilmActor.FromSchema(schema)
|
||||||
|
FilmCategory = FilmCategory.FromSchema(schema)
|
||||||
|
FilmText = FilmText.FromSchema(schema)
|
||||||
|
Inventory = Inventory.FromSchema(schema)
|
||||||
|
Language = Language.FromSchema(schema)
|
||||||
|
Payment = Payment.FromSchema(schema)
|
||||||
|
Rental = Rental.FromSchema(schema)
|
||||||
|
Staff = Staff.FromSchema(schema)
|
||||||
|
Store = Store.FromSchema(schema)
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const filmListSQLBuilderFile = `
|
const filmListSQLBuilderFile = `
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue