@@ -7,8 +7,9 @@ import { AppComponent } from '../app/app.component';
77import { ConnectRequest , ConnectResponse , ErrorResponse , GetAllDatabasesResponse , GetAllSchemasResponse , GetStoredProceduresResponse , GetTablesResponse } from '../../services/mssql/mssql.model' ;
88import { MssqlScaffolderService } from './mssql-scaffolder.service' ;
99import { Meta } from '@angular/platform-browser' ;
10- import { GetColumnsResponse , GetSPParametersResponse , GetSPReturnColumnsResponse } from './mssql-scaffolder.model' ;
10+ import { GetColumnsResponse , GetSPReturnColumnsResponse , SPDefinition , SPParam } from './mssql-scaffolder.model' ;
1111import { RouterLink } from '@angular/router' ;
12+ import { forkJoin } from 'rxjs' ;
1213
1314@Component ( {
1415 selector : 'app-mssql-scaffolder' ,
@@ -216,24 +217,38 @@ ${res.map((p) => `\tpublic ${MssqlScaffolderComponent.convertDataType(p.DataType
216217
217218 private scaffoldSP ( ) {
218219 const sc = this . scaffoldForm . getRawValue ( ) ;
219- this . scaffolder . getSPParameters ( this . connectionID , sc . database , sc . schema , sc . sp ) . subscribe ( ps => {
220- ps = ps as GetSPParametersResponse [ ] ;
221- this . scaffolder . getSPReturnColumns ( this . connectionID , sc . database , sc . schema , sc . sp ) . subscribe ( rs => {
222- rs = rs as GetSPReturnColumnsResponse [ ] ;
223-
224- const psc = ps . map ( ( p ) => `\tpublic ${ MssqlScaffolderComponent . convertDataType ( p . Type ) } ${ p . Nullable ? '?' : '' } ${ p . Parameter_name } { get; set; }` ) ;
225- const rsc = rs . map ( ( p ) => `\tpublic ${ MssqlScaffolderComponent . convertDataType ( p . system_type_name ) } ${ p . Nullable ? '?' : '' } ${ p . column } { get; set; }` ) ;
226220
227- this . csCode =
228- `${ psc . length > 0 ? `public class ${ sc . sp } Params {` :'' }
221+ forkJoin ( {
222+ params : this . scaffolder . getSPDefinition ( this . connectionID , sc . database , sc . schema , sc . sp ) ,
223+ result : this . scaffolder . getSPReturnColumns ( this . connectionID , sc . database , sc . schema , sc . sp )
224+ } ) . subscribe ( vals => {
225+ const spDef = ( vals . params as SPDefinition [ ] ) [ 0 ] . definition ;
226+ const spUpper = spDef . toUpperCase ( ) ;
227+
228+ const ps = [ ...( spDef . substring ( spUpper . indexOf ( "CREATE PROCEDURE" ) , spUpper . indexOf ( "AS" ) )
229+ . matchAll ( / @ (?< name > \w + ) + (?< type > \w + ( \( .* \) ) { 0 , 1 } ) * = * * (?< nul > ( N U L L ) { 0 , 1 } ) / gmi) ) ] . map ( match => {
230+ if ( match . groups )
231+ return {
232+ Parameter_name : match . groups [ 'name' ] ,
233+ Type : match . groups [ 'type' ] ,
234+ Nullable : match . groups [ 'nul' ] && match . groups [ 'nul' ] . length > 0 ? true : false
235+ } as SPParam ;
236+ return undefined ;
237+ } ) . filter ( v => v ) as SPParam [ ] ;
238+ const rs = vals . result as GetSPReturnColumnsResponse [ ] ;
239+
240+ const psc = ps . map ( ( p ) => `\tpublic ${ MssqlScaffolderComponent . convertDataType ( p . Type ) } ${ p . Nullable ? '?' : '' } ${ p . Parameter_name } { get; set; }` ) ;
241+ const rsc = rs . map ( ( p ) => `\tpublic ${ MssqlScaffolderComponent . convertDataType ( p . system_type_name ) } ${ p . Nullable ? '?' : '' } ${ p . column } { get; set; }` ) ;
242+
243+ this . csCode =
244+ `${ psc . length > 0 ? `public class ${ sc . sp } Params {` : '' }
229245${ psc . join ( "\n" ) }
230- ${ psc . length > 0 ? '}' : '' }
246+ ${ psc . length > 0 ? '}' : '' }
231247
232- ${ rsc . length > 0 ? `public class ${ sc . sp } Result {` : '' }
248+ ${ rsc . length > 0 ? `public class ${ sc . sp } Result {` : '' }
233249${ rsc . join ( "\n" ) }
234- ${ rsc . length > 0 ? '}' :'' } `;
235- this . codeFlip = ! this . codeFlip ;
236- } ) ;
250+ ${ rsc . length > 0 ? '}' : '' } `;
251+ this . codeFlip = ! this . codeFlip ;
237252 } ) ;
238253 }
239254
0 commit comments