Creating a new database project, project items

* can create, open, and close sqlproj files
* can add sql objects to projects
This commit is contained in:
Benjin Dubishar
2020-04-17 14:09:59 -07:00
committed by GitHub
parent 05526bbaca
commit b3492e3f57
34 changed files with 1782 additions and 94 deletions

View File

@@ -13,13 +13,21 @@ import { SqlConnectionDataSource } from './sqlConnectionStringSource';
export abstract class DataSource {
public name: string;
public abstract get type(): string;
public abstract get friendlyName(): string;
public abstract get typeFriendlyName(): string;
constructor(name: string) {
this.name = name;
}
}
export class NoDataSourcesFileError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
this.name = NoDataSourcesFileError.name;
}
}
/**
* parses the specified file to load DataSource objects
*/
@@ -30,7 +38,8 @@ export async function load(dataSourcesFilePath: string): Promise<DataSource[]> {
fileContents = await fs.readFile(dataSourcesFilePath);
}
catch (err) {
throw new Error(constants.noDataSourcesFile);
// TODO: differentiate between file not existing and other types of failures; need to know whether to prompt to create new
throw new NoDataSourcesFileError(constants.noDataSourcesFile);
}
const rawJsonContents = JSON.parse(fileContents.toString());

View File

@@ -21,7 +21,7 @@ export class SqlConnectionDataSource extends DataSource {
return SqlConnectionDataSource.type;
}
public get friendlyName(): string {
public get typeFriendlyName(): string {
return constants.sqlConnectionStringFriendly;
}
@@ -42,6 +42,10 @@ export class SqlConnectionDataSource extends DataSource {
}
}
public getSetting(settingName: string): string {
return this.connectionStringComponents[settingName];
}
public static fromJson(json: DataSourceJson): SqlConnectionDataSource {
return new SqlConnectionDataSource(json.name, (json.data as unknown as SqlConnectionDataSourceJson).connectionString);
}