Skip to content

Commit 4e4bc70

Browse files
authored
Add BACKUP/RESTORE key statement parsing support (#50)
1 parent 2af7220 commit 4e4bc70

75 files changed

Lines changed: 3975 additions & 280 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ast/alter_database_set_statement.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ func (o *OnOffDatabaseOption) createDatabaseOption() {}
6464
func (i *IdentifierDatabaseOption) createDatabaseOption() {}
6565
func (d *DelayedDurabilityDatabaseOption) createDatabaseOption() {}
6666

67+
// MaxSizeDatabaseOption represents a MAXSIZE option.
68+
type MaxSizeDatabaseOption struct {
69+
OptionKind string `json:"OptionKind,omitempty"`
70+
MaxSize ScalarExpression `json:"MaxSize,omitempty"`
71+
Units string `json:"Units,omitempty"` // "GB", "TB", etc.
72+
}
73+
74+
func (m *MaxSizeDatabaseOption) node() {}
75+
func (m *MaxSizeDatabaseOption) databaseOption() {}
76+
func (m *MaxSizeDatabaseOption) createDatabaseOption() {}
77+
78+
// LiteralDatabaseOption represents a database option with a literal value (e.g., EDITION).
79+
type LiteralDatabaseOption struct {
80+
OptionKind string `json:"OptionKind,omitempty"`
81+
Value ScalarExpression `json:"Value,omitempty"`
82+
}
83+
84+
func (l *LiteralDatabaseOption) node() {}
85+
func (l *LiteralDatabaseOption) databaseOption() {}
86+
func (l *LiteralDatabaseOption) createDatabaseOption() {}
87+
6788
// AlterDatabaseAddFileStatement represents ALTER DATABASE ... ADD FILE statement
6889
type AlterDatabaseAddFileStatement struct {
6990
DatabaseName *Identifier

ast/alter_function_statement.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type TableValuedFunctionReturnType struct {
4343

4444
func (r *TableValuedFunctionReturnType) functionReturnTypeNode() {}
4545

46-
// SelectFunctionReturnType represents a SELECT function return type
46+
// SelectFunctionReturnType represents a SELECT function return type (inline table-valued function)
4747
type SelectFunctionReturnType struct {
48-
// Simplified - will be expanded later
48+
SelectStatement *SelectStatement
4949
}
5050

5151
func (r *SelectFunctionReturnType) functionReturnTypeNode() {}

ast/alter_simple_statements.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ func (s *AlterApplicationRoleStatement) statement() {}
5757

5858
// AlterAsymmetricKeyStatement represents an ALTER ASYMMETRIC KEY statement.
5959
type AlterAsymmetricKeyStatement struct {
60-
Name *Identifier `json:"Name,omitempty"`
60+
Name *Identifier `json:"Name,omitempty"`
61+
Kind string `json:"Kind,omitempty"`
62+
AttestedBy ScalarExpression `json:"AttestedBy,omitempty"`
63+
EncryptionPassword ScalarExpression `json:"EncryptionPassword,omitempty"`
64+
DecryptionPassword ScalarExpression `json:"DecryptionPassword,omitempty"`
6165
}
6266

6367
func (s *AlterAsymmetricKeyStatement) node() {}
@@ -92,6 +96,19 @@ type AlterPartitionFunctionStatement struct {
9296
func (s *AlterPartitionFunctionStatement) node() {}
9397
func (s *AlterPartitionFunctionStatement) statement() {}
9498

99+
// CreateFullTextCatalogStatement represents a CREATE FULLTEXT CATALOG statement.
100+
type CreateFullTextCatalogStatement struct {
101+
Name *Identifier `json:"Name,omitempty"`
102+
FileGroup *Identifier `json:"FileGroup,omitempty"`
103+
Path ScalarExpression `json:"Path,omitempty"`
104+
Owner *Identifier `json:"Owner,omitempty"`
105+
Options []*OnOffFullTextCatalogOption `json:"Options,omitempty"`
106+
IsDefault bool `json:"IsDefault"`
107+
}
108+
109+
func (s *CreateFullTextCatalogStatement) node() {}
110+
func (s *CreateFullTextCatalogStatement) statement() {}
111+
95112
// AlterFulltextCatalogStatement represents an ALTER FULLTEXT CATALOG statement.
96113
type AlterFulltextCatalogStatement struct {
97114
Name *Identifier `json:"Name,omitempty"`

ast/alter_table_alter_index_statement.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,22 @@ type IndexExpressionOption struct {
3434

3535
func (i *IndexExpressionOption) indexOption() {}
3636
func (i *IndexExpressionOption) node() {}
37+
38+
// CompressionDelayIndexOption represents a COMPRESSION_DELAY option
39+
type CompressionDelayIndexOption struct {
40+
Expression ScalarExpression
41+
TimeUnit string // "Unitless", "Minute", "Minutes"
42+
OptionKind string // "CompressionDelay"
43+
}
44+
45+
func (c *CompressionDelayIndexOption) indexOption() {}
46+
func (c *CompressionDelayIndexOption) node() {}
47+
48+
// OrderIndexOption represents an ORDER option for clustered columnstore indexes
49+
type OrderIndexOption struct {
50+
Columns []*ColumnReferenceExpression
51+
OptionKind string // "Order"
52+
}
53+
54+
func (o *OrderIndexOption) indexOption() {}
55+
func (o *OrderIndexOption) node() {}

ast/alter_trigger_statement.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type AlterTriggerStatement struct {
66
TriggerObject *TriggerObject
77
TriggerType string // "For", "After", "InsteadOf"
88
TriggerActions []*TriggerAction
9-
Options []*TriggerOption
9+
Options []TriggerOptionType
1010
WithAppend bool
1111
IsNotForReplication bool
1212
MethodSpecifier *MethodSpecifier
@@ -28,12 +28,33 @@ type TriggerAction struct {
2828
EventTypeGroup *EventTypeContainer // For database/server events
2929
}
3030

31+
// TriggerOptionType is the interface for trigger options
32+
type TriggerOptionType interface {
33+
triggerOption()
34+
}
35+
3136
// TriggerOption represents a trigger option
3237
type TriggerOption struct {
3338
OptionKind string
3439
OptionState string
3540
}
3641

42+
func (o *TriggerOption) triggerOption() {}
43+
44+
// ExecuteAsClause represents an EXECUTE AS clause
45+
type ExecuteAsClause struct {
46+
ExecuteAsOption string // Caller, Self, Owner, or specific user
47+
Principal ScalarExpression
48+
}
49+
50+
// ExecuteAsTriggerOption represents an EXECUTE AS trigger option
51+
type ExecuteAsTriggerOption struct {
52+
OptionKind string // "ExecuteAsClause"
53+
ExecuteAsClause *ExecuteAsClause
54+
}
55+
56+
func (o *ExecuteAsTriggerOption) triggerOption() {}
57+
3758
// MethodSpecifier represents a CLR method specifier
3859
type MethodSpecifier struct {
3960
AssemblyName *Identifier

ast/backup_statement.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ func (s *BackupDatabaseStatement) statementNode() {}
1111
func (s *BackupDatabaseStatement) statement() {}
1212
func (s *BackupDatabaseStatement) node() {}
1313

14+
// BackupTransactionLogStatement represents a BACKUP LOG statement
15+
type BackupTransactionLogStatement struct {
16+
DatabaseName *IdentifierOrValueExpression
17+
Devices []*DeviceInfo
18+
Options []*BackupOption
19+
}
20+
21+
func (s *BackupTransactionLogStatement) statementNode() {}
22+
func (s *BackupTransactionLogStatement) statement() {}
23+
func (s *BackupTransactionLogStatement) node() {}
24+
1425
// BackupOption represents a backup option
1526
type BackupOption struct {
1627
OptionKind string // Compression, NoCompression, StopOnError, ContinueAfterError, etc.
@@ -29,3 +40,33 @@ type BackupCertificateStatement struct {
2940

3041
func (s *BackupCertificateStatement) statement() {}
3142
func (s *BackupCertificateStatement) node() {}
43+
44+
// BackupServiceMasterKeyStatement represents a BACKUP SERVICE MASTER KEY statement
45+
type BackupServiceMasterKeyStatement struct {
46+
File ScalarExpression
47+
Password ScalarExpression
48+
}
49+
50+
func (s *BackupServiceMasterKeyStatement) statement() {}
51+
func (s *BackupServiceMasterKeyStatement) node() {}
52+
53+
// RestoreServiceMasterKeyStatement represents a RESTORE SERVICE MASTER KEY statement
54+
type RestoreServiceMasterKeyStatement struct {
55+
File ScalarExpression
56+
Password ScalarExpression
57+
IsForce bool
58+
}
59+
60+
func (s *RestoreServiceMasterKeyStatement) statement() {}
61+
func (s *RestoreServiceMasterKeyStatement) node() {}
62+
63+
// RestoreMasterKeyStatement represents a RESTORE MASTER KEY statement
64+
type RestoreMasterKeyStatement struct {
65+
File ScalarExpression
66+
Password ScalarExpression
67+
EncryptionPassword ScalarExpression
68+
IsForce bool
69+
}
70+
71+
func (s *RestoreMasterKeyStatement) statement() {}
72+
func (s *RestoreMasterKeyStatement) node() {}

ast/begin_end_block_statement.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ type BeginEndBlockStatement struct {
88
func (b *BeginEndBlockStatement) node() {}
99
func (b *BeginEndBlockStatement) statement() {}
1010

11+
// BeginEndAtomicBlockStatement represents a BEGIN ATOMIC...END block (for Hekaton/In-Memory OLTP).
12+
type BeginEndAtomicBlockStatement struct {
13+
Options []AtomicBlockOption
14+
StatementList *StatementList
15+
}
16+
17+
func (b *BeginEndAtomicBlockStatement) node() {}
18+
func (b *BeginEndAtomicBlockStatement) statement() {}
19+
20+
// AtomicBlockOption is an interface for atomic block options.
21+
type AtomicBlockOption interface {
22+
atomicBlockOption()
23+
}
24+
25+
// IdentifierAtomicBlockOption represents an atomic block option with an identifier value.
26+
type IdentifierAtomicBlockOption struct {
27+
OptionKind string
28+
Value *Identifier
29+
}
30+
31+
func (o *IdentifierAtomicBlockOption) atomicBlockOption() {}
32+
33+
// LiteralAtomicBlockOption represents an atomic block option with a literal value.
34+
type LiteralAtomicBlockOption struct {
35+
OptionKind string
36+
Value ScalarExpression
37+
}
38+
39+
func (o *LiteralAtomicBlockOption) atomicBlockOption() {}
40+
1141
// StatementList is a list of statements.
1242
type StatementList struct {
1343
Statements []Statement `json:"Statements,omitempty"`

ast/create_columnstore_index_statement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type CreateColumnStoreIndexStatement struct {
99
Columns []*ColumnReferenceExpression
1010
OrderedColumns []*ColumnReferenceExpression
1111
IndexOptions []IndexOption
12-
FilterClause ScalarExpression
12+
FilterClause BooleanExpression
1313
OnPartition *PartitionSpecifier
1414
}
1515

ast/create_simple_statements.go

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type CreateDatabaseStatement struct {
55
DatabaseName *Identifier `json:"DatabaseName,omitempty"`
66
Options []CreateDatabaseOption `json:"Options,omitempty"`
77
AttachMode string `json:"AttachMode,omitempty"` // "None", "Attach", "AttachRebuildLog"
8+
CopyOf *MultiPartIdentifier `json:"CopyOf,omitempty"` // For AS COPY OF syntax
89
}
910

1011
func (s *CreateDatabaseStatement) node() {}
@@ -92,12 +93,63 @@ func (s *CreateCertificateStatement) statement() {}
9293

9394
// CreateAsymmetricKeyStatement represents a CREATE ASYMMETRIC KEY statement.
9495
type CreateAsymmetricKeyStatement struct {
95-
Name *Identifier `json:"Name,omitempty"`
96+
Name *Identifier `json:"Name,omitempty"`
97+
KeySource EncryptionSource `json:"KeySource,omitempty"`
98+
EncryptionAlgorithm string `json:"EncryptionAlgorithm,omitempty"`
99+
Password ScalarExpression `json:"Password,omitempty"`
96100
}
97101

98102
func (s *CreateAsymmetricKeyStatement) node() {}
99103
func (s *CreateAsymmetricKeyStatement) statement() {}
100104

105+
// EncryptionSource is an interface for key sources.
106+
type EncryptionSource interface {
107+
Node
108+
encryptionSource()
109+
}
110+
111+
// ProviderEncryptionSource represents a key source from a provider.
112+
type ProviderEncryptionSource struct {
113+
Name *Identifier `json:"Name,omitempty"`
114+
KeyOptions []KeyOption `json:"KeyOptions,omitempty"`
115+
}
116+
117+
func (p *ProviderEncryptionSource) node() {}
118+
func (p *ProviderEncryptionSource) encryptionSource() {}
119+
120+
// KeyOption is an interface for key options.
121+
type KeyOption interface {
122+
Node
123+
keyOption()
124+
}
125+
126+
// AlgorithmKeyOption represents an ALGORITHM key option.
127+
type AlgorithmKeyOption struct {
128+
Algorithm string `json:"Algorithm,omitempty"`
129+
OptionKind string `json:"OptionKind,omitempty"`
130+
}
131+
132+
func (a *AlgorithmKeyOption) node() {}
133+
func (a *AlgorithmKeyOption) keyOption() {}
134+
135+
// ProviderKeyNameKeyOption represents a PROVIDER_KEY_NAME key option.
136+
type ProviderKeyNameKeyOption struct {
137+
KeyName ScalarExpression `json:"KeyName,omitempty"`
138+
OptionKind string `json:"OptionKind,omitempty"`
139+
}
140+
141+
func (p *ProviderKeyNameKeyOption) node() {}
142+
func (p *ProviderKeyNameKeyOption) keyOption() {}
143+
144+
// CreationDispositionKeyOption represents a CREATION_DISPOSITION key option.
145+
type CreationDispositionKeyOption struct {
146+
IsCreateNew bool `json:"IsCreateNew,omitempty"`
147+
OptionKind string `json:"OptionKind,omitempty"`
148+
}
149+
150+
func (c *CreationDispositionKeyOption) node() {}
151+
func (c *CreationDispositionKeyOption) keyOption() {}
152+
101153
// CreateSymmetricKeyStatement represents a CREATE SYMMETRIC KEY statement.
102154
type CreateSymmetricKeyStatement struct {
103155
Name *Identifier `json:"Name,omitempty"`
@@ -206,6 +258,34 @@ type CreateTypeStatement struct {
206258
func (s *CreateTypeStatement) node() {}
207259
func (s *CreateTypeStatement) statement() {}
208260

261+
// CreateTypeUddtStatement represents a CREATE TYPE ... FROM statement (user-defined data type).
262+
type CreateTypeUddtStatement struct {
263+
Name *SchemaObjectName
264+
DataType DataTypeReference
265+
NullableConstraint *NullableConstraintDefinition
266+
}
267+
268+
func (s *CreateTypeUddtStatement) node() {}
269+
func (s *CreateTypeUddtStatement) statement() {}
270+
271+
// CreateTypeUdtStatement represents a CREATE TYPE ... EXTERNAL NAME statement (CLR user-defined type).
272+
type CreateTypeUdtStatement struct {
273+
Name *SchemaObjectName
274+
AssemblyName *AssemblyName
275+
}
276+
277+
func (s *CreateTypeUdtStatement) node() {}
278+
func (s *CreateTypeUdtStatement) statement() {}
279+
280+
// CreateTypeTableStatement represents a CREATE TYPE ... AS TABLE statement (table type).
281+
type CreateTypeTableStatement struct {
282+
Name *SchemaObjectName `json:"Name,omitempty"`
283+
Definition *TableDefinition `json:"Definition,omitempty"`
284+
}
285+
286+
func (s *CreateTypeTableStatement) node() {}
287+
func (s *CreateTypeTableStatement) statement() {}
288+
209289
// CreateXmlIndexStatement represents a CREATE XML INDEX statement.
210290
type CreateXmlIndexStatement struct {
211291
Name *Identifier `json:"Name,omitempty"`

ast/create_table_statement.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ func (t *TableDefinition) node() {}
2525

2626
// ColumnDefinition represents a column definition in CREATE TABLE
2727
type ColumnDefinition struct {
28-
ColumnIdentifier *Identifier
29-
DataType DataTypeReference
30-
Collation *Identifier
31-
DefaultConstraint *DefaultConstraintDefinition
32-
IdentityOptions *IdentityOptions
33-
Constraints []ConstraintDefinition
34-
IsPersisted bool
35-
IsRowGuidCol bool
36-
IsHidden bool
37-
IsMasked bool
38-
Nullable *NullableConstraintDefinition
28+
ColumnIdentifier *Identifier
29+
DataType DataTypeReference
30+
ComputedColumnExpression ScalarExpression
31+
Collation *Identifier
32+
DefaultConstraint *DefaultConstraintDefinition
33+
IdentityOptions *IdentityOptions
34+
Constraints []ConstraintDefinition
35+
IsPersisted bool
36+
IsRowGuidCol bool
37+
IsHidden bool
38+
IsMasked bool
39+
Nullable *NullableConstraintDefinition
3940
}
4041

4142
func (c *ColumnDefinition) node() {}

0 commit comments

Comments
 (0)