-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path09-constant-examples.mdl
More file actions
183 lines (158 loc) · 4.54 KB
/
09-constant-examples.mdl
File metadata and controls
183 lines (158 loc) · 4.54 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
-- ############################################################################
-- CONSTANT EXAMPLES
-- ############################################################################
--
-- This file demonstrates the MDL syntax for managing constants.
-- Constants are module-level values that can be configured per environment.
--
-- Prerequisites: Assumes a module 'CoTest' exists.
--
-- ############################################################################
create module CoTest;
-- MARK: - Create Constants
/**
* Level 1.1: Create a string constant
* String constants are useful for configuration values like URLs and API keys.
*/
CREATE CONSTANT CoTest.ServiceEndpoint
TYPE String
DEFAULT 'https://api.example.com/v1';
/
/**
* Level 1.2: Create a string constant with a comment
* Comments help explain the purpose and expected values.
*/
CREATE CONSTANT CoTest.ApiKey
TYPE String
DEFAULT ''
COMMENT 'API key for external service. Configure per environment.';
/
/**
* Level 1.3: Create an integer constant
* Integer constants are useful for configuration like timeouts and limits.
*/
CREATE CONSTANT CoTest.MaxRetries
TYPE Integer
DEFAULT 3;
/
/**
* Level 1.4: Create a long constant
* Long constants support larger numeric values.
*/
CREATE CONSTANT CoTest.MaxFileSize
TYPE Long
DEFAULT 10485760
COMMENT 'Maximum file upload size in bytes (default 10MB)';
/
/**
* Level 1.5: Create a decimal constant
* Decimal constants are useful for precise numeric values like rates.
*/
CREATE CONSTANT CoTest.TaxRate
TYPE Decimal
DEFAULT 0.21
COMMENT 'Default tax rate (21%)';
/
/**
* Level 1.6: Create a boolean constant
* Boolean constants are useful for feature flags.
*/
CREATE CONSTANT CoTest.EnableDebugLogging
TYPE Boolean
DEFAULT false
COMMENT 'Enable verbose debug logging';
/
/**
* Level 1.7: Create a DateTime constant
* DateTime constants for default timestamps.
*/
CREATE CONSTANT CoTest.LaunchDate
TYPE DateTime
DEFAULT '[%BeginOfCurrentDay%]';
/
-- MARK: - Show Constants
/**
* Level 2.1: Show all constants in the project
* Lists all constants across all modules with their types and default values.
*/
SHOW CONSTANTS;
/
/**
* Level 2.2: Show constants in a specific module
* Lists only constants defined in the specified module.
*/
SHOW CONSTANTS IN CoTest;
/
/**
* Level 2.3: Show constant values across all configurations
* Displays one row per constant per configuration for easy comparison.
*/
SHOW CONSTANT VALUES;
/
/**
* Level 2.4: Show constant values for a specific module
*/
SHOW CONSTANT VALUES IN CoTest;
/
-- MARK: - Describe Constant
/**
* Level 3.1: Describe a constant
* Shows the full definition of a constant including its type and default value.
*/
DESCRIBE CONSTANT CoTest.ServiceEndpoint;
/
-- MARK: - Create Or Modify Constants
/**
* Level 3.2: Create or modify a constant (upsert)
* Creates the constant if it does not exist, or updates it if it does.
* Use this when you want to ensure a constant has a specific value
* regardless of whether it was previously created.
*/
CREATE OR MODIFY CONSTANT CoTest.ServiceEndpoint
TYPE String
DEFAULT 'https://api.staging.example.com/v2'
COMMENT 'Updated endpoint for staging environment';
/
/**
* Level 3.3: Create or modify a boolean constant
* Useful for toggling feature flags idempotently in scripts.
*/
CREATE OR MODIFY CONSTANT CoTest.EnableDebugLogging
TYPE Boolean
DEFAULT true;
/
-- MARK: - Drop Constants
/**
* Level 4.1: Drop a constant
* Removes a constant from the module.
*/
DROP CONSTANT CoTest.LaunchDate;
/
-- MARK: - Constants in Microflow Expressions (regression: issue #178)
/**
* Level 5.1: Use @Module.Const in a microflow DECLARE
* Tests that `@Module.Const` syntax parses and round-trips correctly.
* Regression test for: DESCRIBE → re-parse roundtrip with @-style constant refs.
*/
CREATE OR REPLACE MICROFLOW CoTest.UseConstantRef ()
RETURNS Nothing
BEGIN
DECLARE $Endpoint String = @CoTest.ServiceEndpoint;
DECLARE $Retries Integer = @CoTest.MaxRetries;
DECLARE $IsTaxable Boolean = @CoTest.EnableDebugLogging;
END;
/
/**
* Level 5.2: Mix @Module.Const with other expressions
* Confirms constant references work in compound expressions alongside literals.
*/
CREATE OR REPLACE MICROFLOW CoTest.MixedConstantExpressions ()
RETURNS Nothing
BEGIN
DECLARE $Limit Decimal = @CoTest.TaxRate + 0.05;
DECLARE $Msg String = 'Endpoint: ' + @CoTest.ServiceEndpoint;
END;
/
-- ############################################################################
-- END OF CONSTANT EXAMPLES
-- ############################################################################