move checking if a file contains a create table statement to utils (#20512)

This commit is contained in:
Kim Santiago
2022-08-31 10:21:30 -07:00
committed by GitHub
parent 010fe91921
commit 83043dadcc
2 changed files with 23 additions and 12 deletions

View File

@@ -689,3 +689,25 @@ export function throwIfNotConnected(connectionResult: azdataType.ConnectionResul
throw new Error(`${connectionResult.errorMessage} (${connectionResult.errorCode})`);
}
}
/**
* Checks whether or not the provided file contains a create table statement
* @param fullPath full path to file to check
* @param projectTargetVersion target version of sql project containing this file
* @returns true if file includes a create table statement, false if it doesn't
*/
export async function fileContainsCreateTableStatement(fullPath: string, projectTargetVersion: string): Promise<boolean> {
let containsCreateTableStatement = false;
if (getAzdataApi() && await exists(fullPath)) {
const dacFxService = await getDacFxService() as mssql.IDacFxService;
try {
const result = await dacFxService.parseTSqlScript(fullPath, projectTargetVersion);
containsCreateTableStatement = result.containsCreateTableStatement;
} catch (e) {
console.error(getErrorMessage(e));
}
}
return containsCreateTableStatement;
}