mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 17:22:42 -05:00
Swapping Record usage to Map in SQL Projects (#22758)
* Changing SqlCmdVars from Record to Map * Converting the rest * Updating tests * more cleanup * Updating test to use new test creation API
This commit is contained in:
@@ -16,7 +16,7 @@ export interface ISqlProjectPublishSettings {
|
||||
databaseName: string;
|
||||
serverName: string;
|
||||
connectionUri: string;
|
||||
sqlCmdVariables?: Record<string, string>;
|
||||
sqlCmdVariables?: Map<string, string>;
|
||||
deploymentOptions?: DeploymentOptions;
|
||||
profileUsed?: boolean;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class Project implements ISqlProject {
|
||||
private _folders: FileProjectEntry[] = [];
|
||||
private _dataSources: DataSource[] = [];
|
||||
private _databaseReferences: IDatabaseReferenceProjectEntry[] = [];
|
||||
private _sqlCmdVariables: Record<string, string> = {};
|
||||
private _sqlCmdVariables: Map<string, string> = new Map();
|
||||
private _preDeployScripts: FileProjectEntry[] = [];
|
||||
private _postDeployScripts: FileProjectEntry[] = [];
|
||||
private _noneDeployScripts: FileProjectEntry[] = [];
|
||||
@@ -97,7 +97,7 @@ export class Project implements ISqlProject {
|
||||
return this._databaseReferences;
|
||||
}
|
||||
|
||||
public get sqlCmdVariables(): Record<string, string> {
|
||||
public get sqlCmdVariables(): Map<string, string> {
|
||||
return this._sqlCmdVariables;
|
||||
}
|
||||
|
||||
@@ -267,10 +267,10 @@ export class Project implements ISqlProject {
|
||||
throw new Error(constants.errorReadingProject(constants.sqlCmdVariables, this.projectFilePath, sqlcmdVariablesResult.errorMessage));
|
||||
}
|
||||
|
||||
this._sqlCmdVariables = {};
|
||||
this._sqlCmdVariables = new Map();
|
||||
|
||||
for (const variable of sqlcmdVariablesResult.sqlCmdVariables) {
|
||||
this._sqlCmdVariables[variable.varName] = variable.defaultValue; // store the default value that's specified in the .sqlproj
|
||||
this._sqlCmdVariables.set(variable.varName, variable.defaultValue); // store the default value that's specified in the .sqlproj
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ export class Project implements ISqlProject {
|
||||
private resetProject(): void {
|
||||
this._files = [];
|
||||
this._databaseReferences = [];
|
||||
this._sqlCmdVariables = {};
|
||||
this._sqlCmdVariables = new Map();
|
||||
this._preDeployScripts = [];
|
||||
this._postDeployScripts = [];
|
||||
this._noneDeployScripts = [];
|
||||
@@ -843,7 +843,8 @@ export class Project implements ISqlProject {
|
||||
* @param defaultValue
|
||||
*/
|
||||
public async addSqlCmdVariable(name: string, defaultValue: string): Promise<void> {
|
||||
await this.sqlProjService.addSqlCmdVariable(this.projectFilePath, name, defaultValue);
|
||||
const result = await this.sqlProjService.addSqlCmdVariable(this.projectFilePath, name, defaultValue);
|
||||
this.throwIfFailed(result);
|
||||
await this.readSqlCmdVariables();
|
||||
}
|
||||
|
||||
@@ -853,7 +854,8 @@ export class Project implements ISqlProject {
|
||||
* @param defaultValue
|
||||
*/
|
||||
public async updateSqlCmdVariable(name: string, defaultValue: string): Promise<void> {
|
||||
await this.sqlProjService.updateSqlCmdVariable(this.projectFilePath, name, defaultValue);
|
||||
const result = await this.sqlProjService.updateSqlCmdVariable(this.projectFilePath, name, defaultValue);
|
||||
this.throwIfFailed(result);
|
||||
await this.readSqlCmdVariables();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface PublishProfile {
|
||||
serverName: string;
|
||||
connectionId: string;
|
||||
connection: string;
|
||||
sqlCmdVariables: Record<string, string>;
|
||||
sqlCmdVariables: Map<string, string>;
|
||||
options?: mssql.DeploymentOptions | vscodeMssql.DeploymentOptions;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function load(profileUri: vscode.Uri, dacfxService: utils.IDacFxSer
|
||||
.withAdditionalProperties({
|
||||
hasTargetDbName: (!!targetDbName).toString(),
|
||||
hasConnectionString: (!!connectionInfo?.connectionId).toString(),
|
||||
hasSqlCmdVariables: (Object.keys(sqlCmdVariables).length > 0).toString()
|
||||
hasSqlCmdVariables: (sqlCmdVariables.size > 0).toString()
|
||||
}).send();
|
||||
|
||||
return {
|
||||
@@ -129,7 +129,7 @@ async function readConnectionString(xmlDoc: any): Promise<{ connectionId: string
|
||||
/**
|
||||
* saves publish settings to the specified profile file
|
||||
*/
|
||||
export async function savePublishProfile(profilePath: string, databaseName: string, connectionString: string, sqlCommandVariableValues?: Record<string, string>, deploymentOptions?: mssql.DeploymentOptions): Promise<void> {
|
||||
export async function savePublishProfile(profilePath: string, databaseName: string, connectionString: string, sqlCommandVariableValues?: Map<string, string>, deploymentOptions?: mssql.DeploymentOptions): Promise<void> {
|
||||
const dacFxService = await utils.getDacFxService();
|
||||
await dacFxService.savePublishProfile(profilePath, databaseName, connectionString, sqlCommandVariableValues, deploymentOptions);
|
||||
}
|
||||
|
||||
@@ -23,21 +23,19 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
|
||||
* @param sqlCmdVariables Collection of SQLCMD variables in the project
|
||||
* @param project
|
||||
*/
|
||||
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>) {
|
||||
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Map<string, string>) {
|
||||
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri);
|
||||
|
||||
this.construct(sqlCmdVariables);
|
||||
}
|
||||
|
||||
private construct(sqlCmdVariables: Record<string, string>) {
|
||||
private construct(sqlCmdVariables: Map<string, string>) {
|
||||
if (!sqlCmdVariables) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
|
||||
if (sqlCmdVariable) {
|
||||
this.sqlcmdVariableTreeItems.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this.relativeProjectUri, this.projectFileUri));
|
||||
}
|
||||
for (const sqlCmdVariable of sqlCmdVariables.keys()) {
|
||||
this.sqlcmdVariableTreeItems.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this.relativeProjectUri, this.projectFileUri));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user