DEV Community

loading...

Running the stored procedure from NestJs

BhargavMantha
Coder, Hacker, Open source enthusiast, Inquisitive, and Rule Breaker.
・1 min read
using the repository that was created,
for instance you want to interact with the table users
and say you have the repository UserRepository. 
Enter fullscreen mode Exit fullscreen mode
  1. dependency inject the user repository into the current service
constructor(
@InjectRepository(Users)
private  userRepository:  Repository<UserRepository>
)  {}
Enter fullscreen mode Exit fullscreen mode
  1. now use the created userReposotory to run the command to invoke the stored procedure
this.userRepository.query(`call dev_db.listUsers(${the_input_paramenters_required}`);
Enter fullscreen mode Exit fullscreen mode

--the above query returns a promise with result of stored Procedure or error
So make sure you add await to function having the above line

Discussion (0)