-
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.
- Loading branch information
1 parent
922358a
commit 7060e2d
Showing
9 changed files
with
783 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,152 @@ | ||
package sdk | ||
|
||
// placeholder for the real implementation. | ||
type TagCreateOptions struct{} | ||
import ( | ||
"context" | ||
"database/sql" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Tags interface { | ||
Create(ctx context.Context, request *CreateTagRequest) error | ||
Show(ctx context.Context, opts *ShowTagRequest) ([]Tag, error) | ||
ShowByID(ctx context.Context, id AccountObjectIdentifier) (*Tag, error) | ||
Drop(ctx context.Context, request *DropTagRequest) error | ||
Undrop(ctx context.Context, request *UndropTagRequest) error | ||
} | ||
|
||
// createTagOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-tag | ||
type createTagOptions struct { | ||
create bool `ddl:"static" sql:"CREATE"` | ||
OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` | ||
tag string `ddl:"static" sql:"TAG"` | ||
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` | ||
name AccountObjectIdentifier `ddl:"identifier"` | ||
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` | ||
AllowedValues *AllowedValues `ddl:"keyword" sql:"ALLOWED_VALUES"` | ||
} | ||
|
||
type AllowedValues struct { | ||
Values []AllowedValue `ddl:"list,comma"` | ||
} | ||
|
||
type AllowedValue struct { | ||
Value string `ddl:"keyword,single_quotes"` | ||
} | ||
|
||
// showTagOptions is based on https://docs.snowflake.com/en/sql-reference/sql/show-tags | ||
type showTagOptions struct { | ||
show bool `ddl:"static" sql:"SHOW"` | ||
tag bool `ddl:"static" sql:"TAGS"` | ||
Like *Like `ddl:"keyword" sql:"LIKE"` | ||
In *In `ddl:"keyword" sql:"IN"` | ||
} | ||
|
||
type Tag struct { | ||
DatabaseName string | ||
SchemaName string | ||
Name string | ||
CreatedOn time.Time | ||
Name string | ||
DatabaseName string | ||
SchemaName string | ||
Owner string | ||
Comment string | ||
AllowedValues []string | ||
OwnerRole string | ||
} | ||
|
||
func (v *Tag) ID() SchemaObjectIdentifier { | ||
return NewSchemaObjectIdentifier(v.DatabaseName, v.SchemaName, v.Name) | ||
} | ||
|
||
func (v *Tag) ObjectType() ObjectType { | ||
return ObjectTypeTag | ||
type tagRow struct { | ||
CreatedOn time.Time `db:"created_on"` | ||
Name string `db:"name"` | ||
DatabaseName string `db:"database_name"` | ||
SchemaName string `db:"schema_name"` | ||
Owner string `db:"owner"` | ||
Comment string `db:"comment"` | ||
AllowedValues sql.NullString `db:"allowed_values"` | ||
OwnerRoleType string `db:"owner_role_type"` | ||
} | ||
|
||
func (tr tagRow) convert() *Tag { | ||
t := &Tag{ | ||
CreatedOn: tr.CreatedOn, | ||
Name: tr.Name, | ||
DatabaseName: tr.DatabaseName, | ||
SchemaName: tr.SchemaName, | ||
Owner: tr.Owner, | ||
Comment: tr.Comment, | ||
OwnerRole: tr.OwnerRoleType, | ||
} | ||
if tr.AllowedValues.Valid { | ||
s := strings.Trim(tr.AllowedValues.String, "[]") // remove brackets | ||
items := strings.Split(s, ",") | ||
values := make([]string, len(items)) | ||
for i, item := range items { | ||
values[i] = strings.Trim(item, `"`) // remove quotes | ||
} | ||
t.AllowedValues = values | ||
} | ||
return t | ||
} | ||
|
||
type TagSetMaskingPolicies struct { | ||
MaskingPolicies []TagMaskingPolicy `ddl:"list,comma"` | ||
Force *bool `ddl:"keyword" sql:"FORCE"` | ||
} | ||
|
||
type TagUnsetMaskingPolicies struct { | ||
MaskingPolicies []TagMaskingPolicy `ddl:"list,comma"` | ||
} | ||
|
||
type TagMaskingPolicy struct { | ||
Name string `ddl:"parameter,no_equals" sql:"MASKING POLICY"` | ||
} | ||
|
||
type TagSet struct { | ||
MaskingPolicies *TagSetMaskingPolicies `ddl:"keyword"` | ||
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` | ||
} | ||
|
||
type TagUnset struct { | ||
MaskingPolicies *TagUnsetMaskingPolicies `ddl:"keyword"` | ||
AllowedValues *bool `ddl:"keyword" sql:"ALLOWED_VALUES"` | ||
Comment *bool `ddl:"keyword" sql:"COMMENT"` | ||
} | ||
|
||
type TagAdd struct { | ||
AllowedValues *AllowedValues `ddl:"keyword" sql:"ALLOWED_VALUES"` | ||
} | ||
|
||
type TagDrop struct { | ||
AllowedValues *AllowedValues `ddl:"keyword" sql:"ALLOWED_VALUES"` | ||
} | ||
|
||
// alterTagOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-tag | ||
type alterTagOptions struct { | ||
alter bool `ddl:"static" sql:"ALTER"` | ||
tag string `ddl:"static" sql:"TAG"` | ||
name AccountObjectIdentifier `ddl:"identifier"` | ||
|
||
// One of | ||
Add *TagAdd `ddl:"keyword" sql:"ADD"` | ||
Drop *TagDrop `ddl:"keyword" sql:"DROP"` | ||
Set *TagSet `ddl:"keyword" sql:"SET"` | ||
Unset *TagUnset `ddl:"keyword" sql:"UNSET"` | ||
RenameTo *string `ddl:"parameter,no_equals" sql:"RENAME TO"` | ||
} | ||
|
||
// dropTagOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-tag | ||
type dropTagOptions struct { | ||
drop bool `ddl:"static" sql:"DROP"` | ||
tag string `ddl:"static" sql:"TAG"` | ||
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` | ||
name AccountObjectIdentifier `ddl:"identifier"` | ||
} | ||
|
||
// undropTagOptions is based on https://docs.snowflake.com/en/sql-reference/sql/undrop-tag | ||
type undropTagOptions struct { | ||
undrop bool `ddl:"static" sql:"UNDROP"` | ||
tag string `ddl:"static" sql:"TAG"` | ||
name AccountObjectIdentifier `ddl:"identifier"` | ||
} |
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,34 @@ | ||
package sdk | ||
|
||
var ( | ||
_ optionsProvider[createTagOptions] = new(CreateTagRequest) | ||
_ optionsProvider[showTagOptions] = new(ShowTagRequest) | ||
_ optionsProvider[dropTagOptions] = new(DropTagRequest) | ||
_ optionsProvider[undropTagOptions] = new(UndropTagRequest) | ||
) | ||
|
||
type CreateTagRequest struct { | ||
orReplace bool | ||
ifNotExists bool | ||
|
||
name AccountObjectIdentifier // required | ||
|
||
// One of | ||
comment *string | ||
allowedValues *AllowedValues | ||
} | ||
|
||
type ShowTagRequest struct { | ||
like *Like | ||
in *In | ||
} | ||
|
||
type DropTagRequest struct { | ||
ifNotExists bool | ||
|
||
name AccountObjectIdentifier // required | ||
} | ||
|
||
type UndropTagRequest struct { | ||
name AccountObjectIdentifier // required | ||
} |
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,69 @@ | ||
package sdk | ||
|
||
func NewCreateTagRequest(name AccountObjectIdentifier) *CreateTagRequest { | ||
s := CreateTagRequest{} | ||
s.name = name | ||
return &s | ||
} | ||
|
||
func (s *CreateTagRequest) WithOrReplace(orReplace bool) *CreateTagRequest { | ||
s.orReplace = orReplace | ||
return s | ||
} | ||
|
||
func (s *CreateTagRequest) WithIfNotExists(ifNotExists bool) *CreateTagRequest { | ||
s.ifNotExists = ifNotExists | ||
return s | ||
} | ||
|
||
func (s *CreateTagRequest) WithComment(comment *string) *CreateTagRequest { | ||
s.comment = comment | ||
return s | ||
} | ||
|
||
func (s *CreateTagRequest) WithAllowedValues(values []string) *CreateTagRequest { | ||
if len(values) > 0 { | ||
s.allowedValues = &AllowedValues{ | ||
Values: make([]AllowedValue, 0, len(values)), | ||
} | ||
for _, value := range values { | ||
s.allowedValues.Values = append(s.allowedValues.Values, AllowedValue{ | ||
Value: value, | ||
}) | ||
} | ||
} | ||
return s | ||
} | ||
|
||
func NewShowTagRequest() *ShowTagRequest { | ||
return &ShowTagRequest{} | ||
} | ||
|
||
func (s *ShowTagRequest) WithLike(pattern string) *ShowTagRequest { | ||
s.like = &Like{ | ||
Pattern: String(pattern), | ||
} | ||
return s | ||
} | ||
|
||
func (s *ShowTagRequest) WithIn(in *In) *ShowTagRequest { | ||
s.in = in | ||
return s | ||
} | ||
|
||
func NewDropTagRequest(name AccountObjectIdentifier) *DropTagRequest { | ||
s := DropTagRequest{} | ||
s.name = name | ||
return &s | ||
} | ||
|
||
func (s *DropTagRequest) WithIfNotExists(ifNotExists bool) *DropTagRequest { | ||
s.ifNotExists = ifNotExists | ||
return s | ||
} | ||
|
||
func NewUndropTagRequest(name AccountObjectIdentifier) *UndropTagRequest { | ||
s := UndropTagRequest{} | ||
s.name = name | ||
return &s | ||
} |
Oops, something went wrong.