Skip to content

Commit

Permalink
Merge branch 'main' into 31-animation-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
IPdotSetAF authored Nov 26, 2024
2 parents df725a4 + b41736e commit b6ac79b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
38 changes: 27 additions & 11 deletions Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { AppComponent } from '../app/app.component';
import { ConnectRequest, ConnectResponse, ErrorResponse, GetAllDatabasesResponse, GetAllSchemasResponse, GetStoredProceduresResponse, GetTablesResponse } from '../../services/mssql/mssql.model';
import { MssqlScaffolderService } from './mssql-scaffolder.service';
import { Meta } from '@angular/platform-browser';
import { GetColumnsResponse, GetSPParametersResponse, GetSPReturnColumnsResponse } from './mssql-scaffolder.model';
import { GetColumnsResponse, GetSPReturnColumnsResponse, SPDefinition, SPParam } from './mssql-scaffolder.model';
import { RouterLink } from '@angular/router';
import { valueChangeAnim } from '../../animations/common-animations';
import { forkJoin } from 'rxjs';

@Component({
selector: 'app-mssql-scaffolder',
Expand Down Expand Up @@ -207,24 +208,39 @@ ${res.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.DataType

private scaffoldSP() {
const sc = this.scaffoldForm.getRawValue();
this.scaffolder.getSPParameters(this.connectionID, sc.database, sc.schema, sc.sp).subscribe(ps => {
ps = ps as GetSPParametersResponse[];
this.scaffolder.getSPReturnColumns(this.connectionID, sc.database, sc.schema, sc.sp).subscribe(rs => {
rs = rs as GetSPReturnColumnsResponse[];

const psc = ps.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.Type)}${p.Nullable ? '?' : ''} ${p.Parameter_name} { get; set; }`);
const rsc = rs.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.system_type_name)}${p.Nullable ? '?' : ''} ${p.column} { get; set; }`);
forkJoin({
params: this.scaffolder.getSPDefinition(this.connectionID, sc.database, sc.schema, sc.sp),
result: this.scaffolder.getSPReturnColumns(this.connectionID, sc.database, sc.schema, sc.sp)
}).subscribe(vals => {
const spDef = (vals.params as SPDefinition[])[0].definition;
const spUpper = spDef.toUpperCase();

this.csCode =
`${psc.length > 0 ? `public class ${sc.sp}Params {` : ''}
const ps = [...(spDef.substring(spUpper.indexOf("CREATE PROCEDURE"), spUpper.indexOf("AS"))
.matchAll(/@(?<name>\w+) +(?<type>\w+(\(.*\)){0,1}) *=* *(?<nul>(NULL){0,1})/gmi))].map(match => {
if (match.groups)
return {
Parameter_name: match.groups['name'],
Type: match.groups['type'],
Nullable: match.groups['nul'] && match.groups['nul'].length > 0 ? true : false
} as SPParam;
return undefined;
}).filter(v => v) as SPParam[];
const rs = vals.result as GetSPReturnColumnsResponse[];

const psc = ps.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.Type)}${p.Nullable ? '?' : ''} ${p.Parameter_name} { get; set; }`);
const rsc = rs.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.system_type_name)}${p.Nullable ? '?' : ''} ${p.column} { get; set; }`);

this.csCode =
`${psc.length > 0 ? `public class ${sc.sp}Params {` : ''}
${psc.join("\n")}
${psc.length > 0 ? '}' : ''}
${rsc.length > 0 ? `public class ${sc.sp}Result {` : ''}
${rsc.join("\n")}
${rsc.length > 0 ? '}' : ''}`;
this.codeFlip = !this.codeFlip;
});

this.codeFlip = !this.codeFlip;
});
}

Expand Down
10 changes: 10 additions & 0 deletions Frontend/src/app/mssql-scaffolder/mssql-scaffolder.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ export interface GetColumnsResponse {
column: string;
system_type_name: string;
Nullable: boolean;
}

export interface SPDefinition{
definition: string;
}

export interface SPParam{
Parameter_name: string;
Type: string;
Nullable: boolean;
}
10 changes: 8 additions & 2 deletions Frontend/src/app/mssql-scaffolder/mssql-scaffolder.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { MssqlService } from '../../services/mssql/mssql.service';
import { map, Observable } from 'rxjs';
import { GetColumnsResponse, GetSPParametersResponse, GetSPReturnColumnsResponse } from './mssql-scaffolder.model';
import { GetColumnsResponse, GetSPParametersResponse, GetSPReturnColumnsResponse, SPDefinition } from './mssql-scaffolder.model';
import { ErrorResponse } from '../../services/mssql/mssql.model';

@Injectable({
Expand Down Expand Up @@ -60,7 +60,13 @@ export class MssqlScaffolderService {
);
}

// 7. Get all return columns and their types from an SP
// 7. Get SP definition lines
getSPDefinition(connection_id: string, dbName: string, schemaName: string, spName: string): Observable<SPDefinition[] | ErrorResponse>{
const query = `SELECT object_definition(object_id('${schemaName}.${spName}')) AS definition;`;
return this.mssql.executeQuery<SPDefinition>(connection_id, query, dbName);
}

// 8. Get all return columns and their types from an SP
getSPReturnColumns(connection_id: string, dbName: string, schemaName: string, spName: string): Observable<GetSPReturnColumnsResponse[] | ErrorResponse> {
const query = `
SELECT name AS 'column', system_type_name, is_nullable as 'Nullable'
Expand Down

0 comments on commit b6ac79b

Please sign in to comment.