-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Make ShowByID configurable in generator #2822
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package generator | ||
|
||
type Config struct { | ||
Values map[string]any | ||
} | ||
|
||
func NewConfig() *Config { | ||
return &Config{ | ||
Values: make(map[string]any), | ||
} | ||
} | ||
|
||
type Pattern struct { | ||
Field string | ||
Pattern string | ||
} | ||
|
||
func (c *Config) WithLike(patterns []Pattern) *Config { | ||
c.Values["Like"] = patterns | ||
return c | ||
} | ||
|
||
func (c *Config) WithIn(patterns []Pattern) *Config { | ||
c.Values["In"] = patterns | ||
return c | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ func (v *plainStruct) OptionalNumber(dbName string) *plainStruct { | |
return v.Field(dbName, "*int") | ||
} | ||
|
||
func (v *plainStruct) PlainStructField(name string, plainStruct *plainStruct) *plainStruct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not used anywhere (or I missed something), do you think it's needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used it earlier, forgot to remove. |
||
return v.Field(name, plainStruct.IntoField().Kind) | ||
} | ||
|
||
func (v *plainStruct) IntoField() *Field { | ||
f := NewField(v.name, v.name, nil, nil) | ||
for _, field := range v.fields { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,11 @@ var ViewsDef = g.NewInterface( | |
OptionalStartsWith(). | ||
OptionalLimit(), | ||
). | ||
ShowByIdOperation(). | ||
ShowByIdOperation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like an additional layer of abstraction would be better. I think receiving an enum for common presets would be sufficient (like in the case of DescribeOperation), e.g. // enum names could be better, but that's what I imagined it like
ShowByIdOperation(g.ShowByIdLikeFiltering)
ShowByIdOperation(g.ShowByIdInDatabaseWithLikeFiltering)
ShowByIdOperation(g.ShowByIdInSchemaWithLikeFiltering) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exactly what I wanted to point out. I would even say that it would be possible to base the |
||
*g.NewConfig(). | ||
WithIn([]g.Pattern{{Field: "Schema", Pattern: "NewDatabaseObjectIdentifier(id.DatabaseName(), id.SchemaName())"}}). | ||
WithLike([]g.Pattern{{Field: "Pattern", Pattern: "String(id.Name())"}}), | ||
). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSlice, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-view", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config is very generic, maybe something like
ShowByIdConfig
would be better. Oh ok, I see it's made to be more generic, but as I mentioned this could be replaced most likely with enum value on Operation struct level like in the case of Describe's different "modes". wdyt?