gpt4 book ai didi

nestjs - NestJs+TypeOrm中如何调用存储过程(后端)

转载 作者:行者123 更新时间:2023-12-04 00:29:37 26 4
gpt4 key购买 nike

我在oracle数据库中有存储过程,我想在NestJs中调用它。
如何在 NestJs 中调用存储过程?

这是我的存储过程

PROCEDURE pipeline_critical (
i_main_company IN NUMBER,
o_value OUT NUMBER
) AS
BEGIN
SELECT COUNT(A.PIPELINE_ID) AS IGNORED_PIPELINE
INTO o_value
FROM T_PIPELINE A
LEFT JOIN T_PIPELINE_PRODUCT P ON P.PIPELINE_ID = A.PIPELINE_ID
WHERE
1 = ( CASE WHEN
i_main_company <> 3
AND A.MAIN_COMPANY_ID = i_main_company
AND TO_CHAR(A.EST_DELIVERY,'YYYY') >= TO_CHAR(SYSDATE,'YYYY') - 1
AND A.PIPELINE_STATUS_ID IN (1,2,3)
AND TO_CHAR(ADD_MONTHS(A.UPDATE_DATE,3),'YYYYMM') < TO_CHAR(SYSDATE,'YYYYMM')
AND P.PAID_DATE IS NULL THEN 1
WHEN
i_main_company = 3
AND TO_CHAR(A.EST_DELIVERY,'YYYY') >= TO_CHAR(SYSDATE,'YYYY') - 1
AND A.PIPELINE_STATUS_ID IN (1,2,3)
AND TO_CHAR(ADD_MONTHS(A.UPDATE_DATE,3),'YYYYMM') < TO_CHAR(SYSDATE,'YYYYMM')
AND P.PAID_DATE IS NULL THEN 1
END
);
END pipeline_critical;

最佳答案

我正在迁移 Javascript/sequealize 后端,我正在测试我的需求。
这是一个对我有用的简单示例:

这是存储过程

CREATE PROCEDURE sp_prueba
@email varchar(100)
AS
BEGIN
SET NOCOUNT ON;
select * from tbusua where emai_usua=@email
END

在 NESTJS 中 - Controller

import { Controller, Get, Param } from '@nestjs/common';
import { UsuariosService } from './usuarios.service';
import { async } from 'rxjs/internal/scheduler/async';
import { Usuario } from './usuarios.entity';


@Controller('Usuarios')
export class UsuariosController {
constructor(private readonly UsuariosService: UsuariosService) { }

@Get('/:email')
async find(@Param('email') email): Promise <Usuario[]>{
return await this.UsuariosService.find(email);
}
}

并在 NESTJS - TypeORM Backend 服务中

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Usuario } from './usuarios.entity';
import { Repository, Db, EntityManager } from 'typeorm';

@Injectable()
export class UsuariosService {
constructor(
@InjectRepository(Usuario)
private readonly usuariosRepository: Repository<Usuario>) { }

async find(email: string): Promise<Usuario[]>{
return await this.usuariosRepository.query("sp_prueba @email='"+email +"'");
}
}

这对我有用

关于nestjs - NestJs+TypeOrm中如何调用存储过程(后端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53407415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com