-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathSqlScriptGeneratorVisitor.CreateExternalModelStatement.cs
More file actions
137 lines (126 loc) · 5 KB
/
Copy pathSqlScriptGeneratorVisitor.CreateExternalModelStatement.cs
File metadata and controls
137 lines (126 loc) · 5 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
//------------------------------------------------------------------------------
// <copyright file="SqlScriptGeneratorVisitor.CreateExternalModelStatement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Globalization;
using Microsoft.SqlServer.TransactSql.ScriptDom;
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
{
partial class SqlScriptGeneratorVisitor
{
public override void ExplicitVisit(CreateExternalModelStatement node)
{
GenerateKeyword(TSqlTokenType.Create);
GenerateSpaceAndIdentifier(CodeGenerationSupporter.External);
GenerateSpaceAndIdentifier(CodeGenerationSupporter.Model);
GenerateCreateExternalModelStatementBody(node);
}
protected static Dictionary<ExternalModelTypeOption, string> _externalModelTypeOption = new Dictionary<ExternalModelTypeOption, string>()
{
{ExternalModelTypeOption.EMBEDDINGS, CodeGenerationSupporter.Embeddings}
};
protected void GenerateCreateExternalModelStatementBody(CreateExternalModelStatement node)
{
// external model name
GenerateSpaceAndFragmentIfNotNull(node.Name);
GenerateOwnerIfNotNull(node.Owner);
NewLine();
GenerateKeywordAndSpace(TSqlTokenType.With);
GenerateKeyword(TSqlTokenType.LeftParenthesis);
bool ifFirst = true;
// external model location
if (node.Location != null)
{
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.Location, node.Location);
ifFirst = false;
}
// external model API Format options
if (node.ApiFormat != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.ApiFormat, node.ApiFormat);
}
// external model Model Type options
if (node.ModelTypeSpecification != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateFragmentIfNotNull(node.ModelTypeSpecification);
}
else if (node.ModelType != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
string externalModelTypeOption = GetValueForEnumKey(_externalModelTypeOption, node.ModelType.Value);
GenerateNameEqualsValue(CodeGenerationSupporter.ModelType, externalModelTypeOption);
}
// external model name options
if (node.ModelName != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.ModelName, node.ModelName);
}
// external model credential options
if (node.Credential != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.Credential, node.Credential);
}
// external model parameters options
if (node.Parameters != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.Parameters, node.Parameters);
}
// external model local runtime path options
if (node.LocalRuntimePath != null)
{
if (!ifFirst)
{
GenerateSymbol(TSqlTokenType.Comma);
}
ifFirst = false;
NewLine();
GenerateNameEqualsValue(CodeGenerationSupporter.LocalRuntimePath, node.LocalRuntimePath);
}
NewLine();
GenerateKeyword(TSqlTokenType.RightParenthesis);
}
public override void ExplicitVisit(ExternalModelTypeSpecification node)
{
string optionKindString = GetValueForEnumKey(_externalModelTypeOption, node.OptionKind);
GenerateNameEqualsValue(CodeGenerationSupporter.ModelType, optionKindString);
}
}
}