Skip to content
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: fix missing references in toOpts and changes with newlines #3240

Merged
merged 13 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package example

import (
g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator"
)

//go:generate go run ../main.go

var ToOptsOptionalExample = g.NewInterface(
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
"ToOptsOptionalExamples",
"ToOptsOptionalExample",
g.KindOfT[DatabaseObjectIdentifier](),
).AlterOperation("https://example.com",
g.NewQueryStruct("Alter").
Alter().
IfExists().
Name().
OptionalQueryStructField(
"OptionalField",
g.NewQueryStruct("OptionalField").
List("SomeList", "DatabaseObjectIdentifier", g.ListOptions()),
g.KeywordOptions(),
).
QueryStructField(
"RequiredField",
g.NewQueryStruct("RequiredField").
List("SomeRequiredList", "DatabaseObjectIdentifier", g.ListOptions()),
g.KeywordOptions(),
),
)
20 changes: 20 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_dto_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package example

//go:generate go run ./dto-builder-generator/main.go

var _ optionsProvider[AlterToOptsOptionalExampleOptions] = new(AlterToOptsOptionalExampleRequest)

type AlterToOptsOptionalExampleRequest struct {
IfExists *bool
name DatabaseObjectIdentifier // required
OptionalField *OptionalFieldRequest
RequiredField RequiredFieldRequest
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
}

type OptionalFieldRequest struct {
SomeList []DatabaseObjectIdentifier
}

type RequiredFieldRequest struct {
SomeRequiredList []DatabaseObjectIdentifier
}
22 changes: 22 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package example

import "context"

type ToOptsOptionalExamples interface {
Alter(ctx context.Context, request *AlterToOptsOptionalExampleRequest) error
}

// AlterToOptsOptionalExampleOptions is based on https://example.com.
type AlterToOptsOptionalExampleOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name DatabaseObjectIdentifier `ddl:"identifier"`
OptionalField *OptionalField `ddl:"keyword"`
RequiredField RequiredField `ddl:"keyword"`
}
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
type OptionalField struct {
SomeList []DatabaseObjectIdentifier `ddl:"list"`
}
type RequiredField struct {
SomeRequiredList []DatabaseObjectIdentifier `ddl:"list"`
}
34 changes: 34 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_impl_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package example

import (
"context"
)

var _ ToOptsOptionalExamples = (*toOptsOptionalExamples)(nil)

type toOptsOptionalExamples struct {
client *Client
}

func (v *toOptsOptionalExamples) Alter(ctx context.Context, request *AlterToOptsOptionalExampleRequest) error {
opts := request.toOpts()
return validateAndExec(v.client, ctx, opts)
}

func (r *AlterToOptsOptionalExampleRequest) toOpts() *AlterToOptsOptionalExampleOptions {
opts := &AlterToOptsOptionalExampleOptions{
IfExists: r.IfExists,
name: r.name,
}

if r.OptionalField != nil {
opts.OptionalField = &OptionalField{
SomeList: r.OptionalField.SomeList,
}
}
opts.RequiredField = RequiredField{
SomeRequiredList: r.RequiredField.SomeRequiredList,
}

return opts
}
13 changes: 13 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_validations_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package example

import "errors"

var _ validatable = new(AlterToOptsOptionalExampleOptions)

func (opts *AlterToOptsOptionalExampleOptions) validate() error {
if opts == nil {
return ErrNilOptions
}
var errs []error
return errors.Join(errs...)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
if r{{ .Path }} != nil {
{{ end }}

{{- if not .IsSlice }}
opts{{ .Path }} = {{ template "toOptsMapping" . -}}{{/* Recursive call */}}
{{- if not .IsSlice -}}
opts{{ .Path }} = {{ if .IsPointer }}&{{else}}{{end}}{{ template "toOptsMapping" . -}}{{/* Recursive call */}}
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
{{- else }}
s := make({{ .Kind }}, len(r{{ .Path }}))
for i, v := range r{{ .Path }} {
Expand All @@ -28,9 +28,9 @@
opts{{ .Path }} = s
{{ end -}}

{{ if or .IsPointer .IsSlice }}
{{ if or .IsPointer .IsSlice -}}
}
{{ end }}
{{- end -}}
{{- end -}}
{{ end -}}
{{ end }}
1 change: 1 addition & 0 deletions pkg/sdk/poc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var definitionMapping = map[string]*generator.Interface{
"database_role_def.go": example.DatabaseRole,
"to_opts_optional_example_def.go": example.ToOptsOptionalExample,
"network_policies_def.go": sdk.NetworkPoliciesDef,
"session_policies_def.go": sdk.SessionPoliciesDef,
"tasks_def.go": sdk.TasksDef,
Expand Down
Loading