-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add ShowByID filtering generation (#3227)
<!-- Feel free to delete comments as you fill this in --> <!-- summary of changes --> ## Changes - Added ShowByID filtering options to `implement_functions` template - New filed in `Operation` struct with Filtering options To generate filtering options, add filtering options in `ShowByIDOperation`: ```go ).ShowByIdOperation( g.ShowByIDLikeFiltering, g.ShowByIDExtendedInFiltering, ) ``` ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> Generation for `Like` and `ExtendedIn` for SchemaObjectidentifier (Secrets): * [x] acceptance tests * [x] integration tests * [x] unit tests --- Generation for `Like` and `In` for SchemaObjectIdentifier (Streamlits): * [x] acceptance tests * [x] integration tests * [x] unit tests --- Generation for `Like` for AccountObjectIdentifier (Connections): * [x] acceptance tests * [x] integration tests * [x] unit tests --- Generation for `ApplicationName` for DatabaseObjectIdentifier (Application Roles): * [x] acceptance tests * [x] integration tests * [x] unit tests ## Notes - `WithIn` and `WithLike` are mostly used in `ShowByID()` - no objects use `Limit` and `StartsWith` in `ShowByID()` - `application_roles` is the only `DatabaseObejctIdentifier` with a `_def` file - `application_roles` does not implement any of the common filtering options e.g. `OptionalLike()` or `OptionalIn()` - `application_roles` implement `WithApplicationName` filtering option that has been added
- Loading branch information
1 parent
246547f
commit 548ec42
Showing
15 changed files
with
185 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package generator | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
type ShowByIDFilteringKind uint | ||
|
||
const ( | ||
ShowByIDLikeFiltering ShowByIDFilteringKind = iota | ||
ShowByIDInFiltering | ||
ShowByIDExtendedInFiltering | ||
ShowByIDApplicationNameFiltering | ||
ShowByIDNoFiltering | ||
) | ||
|
||
type idPrefix string | ||
|
||
const ( | ||
AccountIdentifierPrefix idPrefix = "Account" | ||
DatabaseIdentifierPrefix idPrefix = "Database" | ||
SchemaIdentifierPrefix idPrefix = "Schema" | ||
) | ||
|
||
func identifierStringToPrefix(s string) idPrefix { | ||
switch s { | ||
case "AccountObjectIdentifier": | ||
return AccountIdentifierPrefix | ||
case "DatabaseObjectIdentifier": | ||
return DatabaseIdentifierPrefix | ||
case "SchemaObjectIdentifier": | ||
return SchemaIdentifierPrefix | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
type ShowByIDFiltering interface { | ||
WithFiltering() string | ||
} | ||
|
||
type showByIDFilter struct { | ||
Name string | ||
Kind string | ||
Args string | ||
} | ||
|
||
func (s *showByIDFilter) WithFiltering() string { | ||
return fmt.Sprintf("With%s(%s{%s})", s.Name, s.Kind, s.Args) | ||
} | ||
|
||
func newShowByIDFiltering(name, kind, args string) ShowByIDFiltering { | ||
return &showByIDFilter{ | ||
Name: name, | ||
Kind: kind, | ||
Args: args, | ||
} | ||
} | ||
|
||
func newShowByIDNoFiltering() ShowByIDFiltering { | ||
return newShowByIDFiltering("NoFiltering", "", "") | ||
} | ||
|
||
func newShowByIDLikeFiltering() ShowByIDFiltering { | ||
return newShowByIDFiltering("Like", "Like", "Pattern: String(id.Name())") | ||
} | ||
|
||
func newShowByIDInFiltering(identifierKind idPrefix) ShowByIDFiltering { | ||
return newShowByIDFiltering("In", "In", fmt.Sprintf("%[1]v: id.%[1]vId()", identifierKind)) | ||
} | ||
|
||
func newShowByIDExtendedInFiltering(identifierKind idPrefix) ShowByIDFiltering { | ||
return newShowByIDFiltering("In", "ExtendedIn", fmt.Sprintf("In: In{%[1]v: id.%[1]vId()}", identifierKind)) | ||
} | ||
|
||
type showByIDApplicationFilter struct { | ||
showByIDFilter | ||
} | ||
|
||
func (s *showByIDApplicationFilter) WithFiltering() string { | ||
return fmt.Sprintf("With%s(%s)", s.Name, s.Args) | ||
} | ||
|
||
func newShowByIDApplicationFiltering() ShowByIDFiltering { | ||
return &showByIDApplicationFilter{ | ||
showByIDFilter: showByIDFilter{ | ||
Name: "ApplicationName", | ||
Kind: "", | ||
Args: "id.DatabaseId()", | ||
}, | ||
} | ||
} | ||
|
||
func (s *Operation) withFiltering(filtering ...ShowByIDFilteringKind) *Operation { | ||
for _, filteringKind := range filtering { | ||
switch filteringKind { | ||
case ShowByIDInFiltering: | ||
s.ShowByIDFiltering = append(s.ShowByIDFiltering, newShowByIDInFiltering(s.ObjectInterface.ObjectIdentifierPrefix())) | ||
case ShowByIDExtendedInFiltering: | ||
s.ShowByIDFiltering = append(s.ShowByIDFiltering, newShowByIDExtendedInFiltering(s.ObjectInterface.ObjectIdentifierPrefix())) | ||
case ShowByIDLikeFiltering: | ||
s.ShowByIDFiltering = append(s.ShowByIDFiltering, newShowByIDLikeFiltering()) | ||
case ShowByIDApplicationNameFiltering: | ||
s.ShowByIDFiltering = append(s.ShowByIDFiltering, newShowByIDApplicationFiltering()) | ||
case ShowByIDNoFiltering: | ||
s.ShowByIDFiltering = []ShowByIDFiltering{newShowByIDNoFiltering()} | ||
default: | ||
log.Println("No showByID filtering found for kind:", filteringKind) | ||
} | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters