Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing Stored Procedures from MSSQL using loopback 4 #5101

Closed
neha2683 opened this issue Apr 13, 2020 · 8 comments
Closed

Exposing Stored Procedures from MSSQL using loopback 4 #5101

neha2683 opened this issue Apr 13, 2020 · 8 comments
Assignees

Comments

@neha2683
Copy link

Hello

Able to access the DB tables from MS SQL using loopback 4 .

Looking for options to expose only the Stored Procedures from the table , and expose them as Rest APIs . Kindly help. Thanks.

@dhmlau
Copy link
Member

dhmlau commented Apr 14, 2020

Cross posting from #3798 (comment).

You can call DataSource.execute(), something like below:

  @get('/test', {
    responses: {
      '200': {
        description: 'test for executing query',
      },
    },
  })
  async test(): Promise<any> {
    return this.customerRepository.dataSource.execute('SELECT * FROM CUSTOMER');
  }

@dhmlau dhmlau added question and removed feature labels Apr 14, 2020
@neha2683
Copy link
Author

Thanks Diana .
But what I want is to call 2000+ stored procedures via REST API through loopback.
Is there a way to do that ? Thanks in advance .

@dhmlau
Copy link
Member

dhmlau commented Apr 14, 2020

@neha2683, do you mean you want one REST API that calls 2000+ stored procedures, or 2000+ endpoints that each call one stored procedure?

@neha2683
Copy link
Author

neha2683 commented Apr 14, 2020 via email

@neha2683
Copy link
Author

hello
i need to create APIs like this ( as available in dreamfactory ) . How to do with loopback.

GET /_proc/{procedure_name}
Call a stored procedure.

POST /_proc/{procedure_name}
Call a stored procedure.

@dhmlau
Copy link
Member

dhmlau commented Apr 17, 2020

@neha2683, it would be something similar to what I posted in #5101 (comment). Controllers are used to expose REST APIs, so add those functions in the controller.

@deepakrkris
Copy link
Contributor

@neha2683 please take a look at #3459

constructor(
    @repository(MyRepository)
    public myRepo: MyRepository,
  ) {
    this.user_Profile = userProfile;
  }
 async testData(
  ): Promise<any> {
    return await this.myRepo.dataSource.execute(`EXEC Get_Customer(?)`, ['CUSTID01']);
  }

and

https://loopback.io/doc/en/lb4/apidocs.repository.connector.execute.html

@dhmlau
Copy link
Member

dhmlau commented Aug 24, 2020

Closing as resolved.

@dhmlau dhmlau closed this as completed Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants