mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 09:35:37 -05:00
.sqlproj and datasources.json file parsing (#8921)
* Checkpoint * Adding mock contents for tree * added open sqlproj dialog * reading files from directory * Added directory traversal * Adding tree sorting by folder vs file and label * Improved auto-unfolding of tree based on node type * replacing fs with fs.promise alias * PR feedback * added activation event for when workspace contains sqlproj files * Returning after displaying error * Fixing linter errors * Reworked tree * Fixing missing grandchildren * Correcting tree URI construction * Refactoring to isolate tree item responsibilities from data model responsibilities * project file parsing * constructing tree from project files rather than filesystem * Fixing double-initialization * Changing projectEntry to take enum for file type * Correct node type for project item * Parsing datasources.json * Child nodes for sql data source * Localizing strings * Checkpoint * Adding mock contents for tree * added open sqlproj dialog * reading files from directory * Added directory traversal * Adding tree sorting by folder vs file and label * Improved auto-unfolding of tree based on node type * replacing fs with fs.promise alias * PR feedback * added activation event for when workspace contains sqlproj files * Returning after displaying error * Fixing linter errors * Reworked tree * Fixing missing grandchildren * Correcting tree URI construction * Refactoring to isolate tree item responsibilities from data model responsibilities * project file parsing * constructing tree from project files rather than filesystem * Fixing double-initialization * Changing projectEntry to take enum for file type * Correct node type for project item * Parsing datasources.json * Child nodes for sql data source * Localizing strings * missed file in merge * changed extension method to helper * cleanup * Adding docstrings
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DataSource } from './dataSources';
|
||||
import * as constants from '../../common/constants';
|
||||
|
||||
/**
|
||||
* Contains information about a SQL connection string data source`
|
||||
*/
|
||||
export class SqlConnectionDataSource extends DataSource {
|
||||
readonly connectionString: string;
|
||||
readonly connectionStringComponents: { [id: string]: string } = {};
|
||||
|
||||
public static get type() {
|
||||
return 'sql_connection_string';
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return SqlConnectionDataSource.type;
|
||||
}
|
||||
|
||||
public get friendlyName(): string {
|
||||
return constants.sqlConnectionStringFriendly;
|
||||
}
|
||||
|
||||
constructor(name: string, connectionString: string) {
|
||||
super(name);
|
||||
|
||||
// TODO: do we have a common construct for connection strings?
|
||||
this.connectionString = connectionString;
|
||||
|
||||
for (const component of this.connectionString.split(';')) {
|
||||
const split = component.split('=');
|
||||
|
||||
if (split.length !== 2) {
|
||||
throw new Error(constants.invalidSqlConnectionString);
|
||||
}
|
||||
|
||||
this.connectionStringComponents[split[0]] = split[1];
|
||||
}
|
||||
}
|
||||
|
||||
public static fromJson(json: DataSourceJson): SqlConnectionDataSource {
|
||||
return new SqlConnectionDataSource(json.name, (json.data as unknown as SqlConnectionDataSourceJson).connectionString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON structure for a SQL connection string data source
|
||||
*/
|
||||
interface SqlConnectionDataSourceJson {
|
||||
connectionString: string;
|
||||
}
|
||||
Reference in New Issue
Block a user