diff --git a/pkg/sdk/poc/README.md b/pkg/sdk/poc/README.md index 73b011d9de9..9aedab77d17 100644 --- a/pkg/sdk/poc/README.md +++ b/pkg/sdk/poc/README.md @@ -99,6 +99,9 @@ find a better solution to solve the issue (add more logic to the templates ?) - cleanup the design of builders in DSL (e.g. why transformer has to be always added?) - generate getters for requests, at least for identifier/name - generate integration tests in child package (because now we keep them in `testint` package) +- struct_to_builder is not supporting templated-like values. See stages_def.go where in SQL there could be value, where 'n' can be replaced with any number + - SKIP_FILE_n - this looks more like keyword without a space between SQL prefix and int + - SKIP_FILE_n% (e.g. SKIP_FILE_123%) - this is more template-like behaviour, notice that 'n' is inside the value (we cannot reproduce that right now with struct_to_builder capabilities) ##### Known issues - generating two converts when Show and Desc use the same data structure diff --git a/pkg/sdk/poc/generator/keyword_builders.go b/pkg/sdk/poc/generator/keyword_builders.go index b75ae8d8535..247a55b7104 100644 --- a/pkg/sdk/poc/generator/keyword_builders.go +++ b/pkg/sdk/poc/generator/keyword_builders.go @@ -5,6 +5,11 @@ func (v *QueryStruct) OptionalSQL(sql string) *QueryStruct { return v } +func (v *QueryStruct) NamedList(sql string, itemKind string) *QueryStruct { + v.fields = append(v.fields, NewField(sqlToFieldName(sql, true), KindOfSlice(itemKind), Tags().Keyword().SQL(sql), nil)) + return v +} + func (v *QueryStruct) OrReplace() *QueryStruct { return v.OptionalSQL("OR REPLACE") } @@ -42,53 +47,45 @@ func (v *QueryStruct) OptionalNumber(name string, transformer *KeywordTransforme } func (v *QueryStruct) OptionalLimitFrom() *QueryStruct { - v.fields = append(v.fields, NewField("Limit", "*LimitFrom", Tags().Keyword().SQL("LIMIT"), nil)) - return v + return v.PredefinedQueryStructField("Limit", "*LimitFrom", KeywordOptions().SQL("LIMIT")) } func (v *QueryStruct) OptionalSessionParameters() *QueryStruct { - v.fields = append(v.fields, NewField("SessionParameters", "*SessionParameters", Tags().List().NoParentheses(), nil).withValidations(NewValidation(ValidateValue, "SessionParameters"))) - return v + return v.PredefinedQueryStructField("SessionParameters", "*SessionParameters", ListOptions().NoParentheses()). + WithValidation(ValidateValue, "SessionParameters") } func (v *QueryStruct) OptionalSessionParametersUnset() *QueryStruct { - v.fields = append(v.fields, NewField("SessionParametersUnset", "*SessionParametersUnset", Tags().List().NoParentheses(), nil).withValidations(NewValidation(ValidateValue, "SessionParametersUnset"))) - return v + return v.PredefinedQueryStructField("SessionParametersUnset", "*SessionParametersUnset", ListOptions().NoParentheses()). + WithValidation(ValidateValue, "SessionParametersUnset") } func (v *QueryStruct) OptionalTags() *QueryStruct { - v.fields = append(v.fields, NewField("Tag", "[]TagAssociation", Tags().Keyword().Parentheses().SQL("TAG"), nil)) - return v + return v.PredefinedQueryStructField("Tag", "[]TagAssociation", KeywordOptions().Parentheses().SQL("TAG")) } func (v *QueryStruct) SetTags() *QueryStruct { - v.fields = append(v.fields, NewField("SetTags", "[]TagAssociation", Tags().Keyword().SQL("SET TAG"), nil)) - return v + return v.PredefinedQueryStructField("SetTags", "[]TagAssociation", KeywordOptions().SQL("SET TAG")) } func (v *QueryStruct) UnsetTags() *QueryStruct { - v.fields = append(v.fields, NewField("UnsetTags", "[]ObjectIdentifier", Tags().Keyword().SQL("UNSET TAG"), nil)) - return v + return v.PredefinedQueryStructField("UnsetTags", "[]ObjectIdentifier", KeywordOptions().SQL("UNSET TAG")) } func (v *QueryStruct) OptionalLike() *QueryStruct { - v.fields = append(v.fields, NewField("Like", "*Like", Tags().Keyword().SQL("LIKE"), nil)) - return v + return v.PredefinedQueryStructField("Like", "*Like", KeywordOptions().SQL("LIKE")) } func (v *QueryStruct) OptionalIn() *QueryStruct { - v.fields = append(v.fields, NewField("In", "*In", Tags().Keyword().SQL("IN"), nil)) - return v + return v.PredefinedQueryStructField("In", "*In", KeywordOptions().SQL("IN")) } func (v *QueryStruct) OptionalStartsWith() *QueryStruct { - v.fields = append(v.fields, NewField("StartsWith", "*string", Tags().Parameter().NoEquals().SingleQuotes().SQL("STARTS WITH"), nil)) - return v + return v.PredefinedQueryStructField("StartsWith", "*string", ParameterOptions().NoEquals().SingleQuotes().SQL("STARTS WITH")) } func (v *QueryStruct) OptionalLimit() *QueryStruct { - v.fields = append(v.fields, NewField("Limit", "*LimitFrom", Tags().Keyword().SQL("LIMIT"), nil)) - return v + return v.PredefinedQueryStructField("Limit", "*LimitFrom", KeywordOptions().SQL("LIMIT")) } func (v *QueryStruct) OptionalCopyGrants() *QueryStruct { diff --git a/pkg/sdk/stages_def.go b/pkg/sdk/stages_def.go index f47c1e90e40..a71688d92ee 100644 --- a/pkg/sdk/stages_def.go +++ b/pkg/sdk/stages_def.go @@ -272,8 +272,8 @@ var StagesDef = g.NewInterface( IfExists(). Name(). OptionalIdentifier("RenameTo", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). - List("SetTags", g.KindOfT[TagAssociation](), g.KeywordOptions().SQL("SET TAG")). - List("UnsetTags", g.KindOfT[ObjectIdentifier](), g.KeywordOptions().SQL("UNSET TAG")). + NamedList("SET TAG", g.KindOfT[TagAssociation]()). + NamedList("UNSET TAG", g.KindOfT[ObjectIdentifier]()). WithValidation(g.ValidIdentifierIfSet, "RenameTo"). WithValidation(g.ExactlyOneValueSet, "RenameTo", "SetTags", "UnsetTags"). WithValidation(g.ConflictingFields, "IfExists", "UnsetTags").