-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathdatabase_role_def.go
67 lines (60 loc) · 2.17 KB
/
database_role_def.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package example
import (
g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator"
)
//go:generate go run ../main.go
var (
dbRoleRename = g.NewQueryStruct("DatabaseRoleRename").
// Fields
Identifier("Name", g.KindOfT[DatabaseObjectIdentifier](), g.IdentifierOptions().Required()).
// Validations
WithValidation(g.ValidIdentifier, "Name")
nestedThirdLevel = g.NewQueryStruct("NestedThirdLevel").
// Fields
Identifier("Field", g.KindOfT[DatabaseObjectIdentifier](), g.IdentifierOptions().Required()).
// Validations
WithValidation(g.AtLeastOneValueSet, "Field")
dbRoleSet = g.NewQueryStruct("DatabaseRoleSet").
// Fields
TextAssignment("COMMENT", g.ParameterOptions().SingleQuotes().Required()).
OptionalQueryStructField("NestedThirdLevel", nestedThirdLevel, g.ListOptions().NoParentheses().SQL("NESTED"))
dbRoleUnset = g.NewQueryStruct("DatabaseRoleUnset").
// Fields
OptionalSQL("COMMENT").
// Validations
WithValidation(g.AtLeastOneValueSet, "Comment")
DatabaseRole = g.NewInterface(
"DatabaseRoles",
"DatabaseRole",
"DatabaseObjectIdentifier",
).
CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-database-role",
g.NewQueryStruct("CreateDatabaseRole").
// Fields
Create().
OrReplace().
SQL("DATABASE ROLE").
IfNotExists().
Name().
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
// Validations
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"),
).
AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-database-role",
g.NewQueryStruct("AlterDatabaseRole").
// Fields
Alter().
SQL("DATABASE ROLE").
IfExists().
Name().
OptionalQueryStructField("Rename", dbRoleRename, g.ListOptions().NoParentheses().SQL("RENAME TO")).
OptionalQueryStructField("Set", dbRoleSet, g.ListOptions().NoParentheses().SQL("SET")).
OptionalQueryStructField("Unset", dbRoleUnset, g.ListOptions().NoParentheses().SQL("UNSET")).
// Validations
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ExactlyOneValueSet, "Rename", "Set", "Unset"),
)
)