Remove package name from txt helpers
This commit is contained in:
parent
81494a91d0
commit
be189323d9
2 changed files with 6 additions and 11 deletions
|
@ -27,7 +27,6 @@ type TxtToOne struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
Function struct {
|
Function struct {
|
||||||
PackageName string
|
|
||||||
Name string
|
Name string
|
||||||
ForeignName string
|
ForeignName string
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ type TxtToOne struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func txtsFromFKey(packageName string, tables []bdb.Table, table bdb.Table, fkey bdb.ForeignKey) TxtToOne {
|
func txtsFromFKey(tables []bdb.Table, table bdb.Table, fkey bdb.ForeignKey) TxtToOne {
|
||||||
r := TxtToOne{}
|
r := TxtToOne{}
|
||||||
|
|
||||||
r.ForeignKey = fkey
|
r.ForeignKey = fkey
|
||||||
|
@ -54,7 +53,6 @@ func txtsFromFKey(packageName string, tables []bdb.Table, table bdb.Table, fkey
|
||||||
r.ForeignTable.ColumnName = fkey.ForeignColumn
|
r.ForeignTable.ColumnName = fkey.ForeignColumn
|
||||||
r.ForeignTable.ColumnNameGo = strmangle.TitleCase(strmangle.Singular(fkey.ForeignColumn))
|
r.ForeignTable.ColumnNameGo = strmangle.TitleCase(strmangle.Singular(fkey.ForeignColumn))
|
||||||
|
|
||||||
r.Function.PackageName = packageName
|
|
||||||
r.Function.Name = strmangle.TitleCase(strmangle.Singular(strings.TrimSuffix(fkey.Column, "_id")))
|
r.Function.Name = strmangle.TitleCase(strmangle.Singular(strings.TrimSuffix(fkey.Column, "_id")))
|
||||||
plurality := strmangle.Plural
|
plurality := strmangle.Plural
|
||||||
if fkey.Unique {
|
if fkey.Unique {
|
||||||
|
@ -85,7 +83,7 @@ func txtsFromFKey(packageName string, tables []bdb.Table, table bdb.Table, fkey
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func txtsFromOneToOne(packageName string, tables []bdb.Table, table bdb.Table, oneToOne bdb.ToOneRelationship) TxtToOne {
|
func txtsFromOneToOne(tables []bdb.Table, table bdb.Table, oneToOne bdb.ToOneRelationship) TxtToOne {
|
||||||
fkey := bdb.ForeignKey{
|
fkey := bdb.ForeignKey{
|
||||||
Table: oneToOne.Table,
|
Table: oneToOne.Table,
|
||||||
Name: "none",
|
Name: "none",
|
||||||
|
@ -99,7 +97,7 @@ func txtsFromOneToOne(packageName string, tables []bdb.Table, table bdb.Table, o
|
||||||
ForeignColumnUnique: oneToOne.ForeignColumnUnique,
|
ForeignColumnUnique: oneToOne.ForeignColumnUnique,
|
||||||
}
|
}
|
||||||
|
|
||||||
rel := txtsFromFKey(packageName, tables, table, fkey)
|
rel := txtsFromFKey(tables, table, fkey)
|
||||||
col := table.GetColumn(oneToOne.Column)
|
col := table.GetColumn(oneToOne.Column)
|
||||||
|
|
||||||
// Reverse foreign key
|
// Reverse foreign key
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestTxtsFromOne(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
jets := bdb.GetTable(tables, "jets")
|
jets := bdb.GetTable(tables, "jets")
|
||||||
texts := txtsFromFKey("models", tables, jets, jets.FKeys[0])
|
texts := txtsFromFKey(tables, jets, jets.FKeys[0])
|
||||||
expect := TxtToOne{}
|
expect := TxtToOne{}
|
||||||
|
|
||||||
expect.ForeignKey = jets.FKeys[0]
|
expect.ForeignKey = jets.FKeys[0]
|
||||||
|
@ -32,7 +32,6 @@ func TestTxtsFromOne(t *testing.T) {
|
||||||
expect.ForeignTable.ColumnName = "id"
|
expect.ForeignTable.ColumnName = "id"
|
||||||
expect.ForeignTable.ColumnNameGo = "ID"
|
expect.ForeignTable.ColumnNameGo = "ID"
|
||||||
|
|
||||||
expect.Function.PackageName = "models"
|
|
||||||
expect.Function.Name = "Pilot"
|
expect.Function.Name = "Pilot"
|
||||||
expect.Function.ForeignName = "Jet"
|
expect.Function.ForeignName = "Jet"
|
||||||
expect.Function.Varname = "pilot"
|
expect.Function.Varname = "pilot"
|
||||||
|
@ -45,7 +44,7 @@ func TestTxtsFromOne(t *testing.T) {
|
||||||
t.Errorf("Want:\n%s\nGot:\n%s\n", spew.Sdump(expect), spew.Sdump(texts))
|
t.Errorf("Want:\n%s\nGot:\n%s\n", spew.Sdump(expect), spew.Sdump(texts))
|
||||||
}
|
}
|
||||||
|
|
||||||
texts = txtsFromFKey("models", tables, jets, jets.FKeys[1])
|
texts = txtsFromFKey(tables, jets, jets.FKeys[1])
|
||||||
expect = TxtToOne{}
|
expect = TxtToOne{}
|
||||||
expect.ForeignKey = jets.FKeys[1]
|
expect.ForeignKey = jets.FKeys[1]
|
||||||
|
|
||||||
|
@ -58,7 +57,6 @@ func TestTxtsFromOne(t *testing.T) {
|
||||||
expect.ForeignTable.ColumnName = "id"
|
expect.ForeignTable.ColumnName = "id"
|
||||||
expect.ForeignTable.ColumnNameGo = "ID"
|
expect.ForeignTable.ColumnNameGo = "ID"
|
||||||
|
|
||||||
expect.Function.PackageName = "models"
|
|
||||||
expect.Function.Name = "Airport"
|
expect.Function.Name = "Airport"
|
||||||
expect.Function.ForeignName = "Jets"
|
expect.Function.ForeignName = "Jets"
|
||||||
expect.Function.Varname = "airport"
|
expect.Function.Varname = "airport"
|
||||||
|
@ -85,7 +83,7 @@ func TestTxtsFromOneToOne(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pilots := bdb.GetTable(tables, "pilots")
|
pilots := bdb.GetTable(tables, "pilots")
|
||||||
texts := txtsFromOneToOne("models", tables, pilots, pilots.ToOneRelationships[0])
|
texts := txtsFromOneToOne(tables, pilots, pilots.ToOneRelationships[0])
|
||||||
expect := TxtToOne{}
|
expect := TxtToOne{}
|
||||||
|
|
||||||
expect.ForeignKey = bdb.ForeignKey{
|
expect.ForeignKey = bdb.ForeignKey{
|
||||||
|
@ -111,7 +109,6 @@ func TestTxtsFromOneToOne(t *testing.T) {
|
||||||
expect.ForeignTable.ColumnName = "pilot_id"
|
expect.ForeignTable.ColumnName = "pilot_id"
|
||||||
expect.ForeignTable.ColumnNameGo = "PilotID"
|
expect.ForeignTable.ColumnNameGo = "PilotID"
|
||||||
|
|
||||||
expect.Function.PackageName = "models"
|
|
||||||
expect.Function.Name = "Jet"
|
expect.Function.Name = "Jet"
|
||||||
expect.Function.ForeignName = "Pilot"
|
expect.Function.ForeignName = "Pilot"
|
||||||
expect.Function.Varname = "jet"
|
expect.Function.Varname = "jet"
|
||||||
|
|
Loading…
Reference in a new issue