Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Nov 13, 2023
1 parent fe5cedd commit 8c0b058
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions pkg/sdk/poc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 17 additions & 20 deletions pkg/sdk/poc/generator/keyword_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/poc/generator/list_builders.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package generator

func (v *QueryStruct) List(name string, itemKind string, transformer FieldTransformer) *QueryStruct {
v.fields = append(v.fields, NewField(name, KindOfSlice(itemKind), Tags(), transformer))
func (v *QueryStruct) List(name string, itemKind string, transformer *ListTransformer) *QueryStruct {
v.fields = append(v.fields, NewField(name, KindOfSlice(itemKind), Tags().List(), transformer))
return v
}
4 changes: 2 additions & 2 deletions pkg/sdk/stages_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down

0 comments on commit 8c0b058

Please sign in to comment.