【问题标题】:prisma $queryRaw doesn't work with single quotes in the stringprisma $queryRaw 不适用于字符串中的单引号
【发布时间】:2022-04-06 03:12:56
【问题描述】:

我有一个查询

select count(id), status,  "createdAt"::date from "ProjectLog" where "projectId" = (select id from "Project" where slug = ${id}) and "createdAt" > current_date - interval '${interval} day' group by "createdAt"::date, status;

我也尝试过用户 Prisma.sql 传递引号内的值,但它一直抛出错误,它期望 1 个参数但找到 2 个。

prisma 2.20.1 没有这个问题 这个问题只发生在版本3.3.0

Query: select count(id) as count, status,  "createdAt"::date from "ProjectLog" where "projectId" = (select id from "Project" where slug = $1) and "createdAt" >  current_date - interval '$2 day' and key notnull group by "createdAt"::date, status
Param: ["main","30"]
PrismaClientKnownRequestError:
Invalid `prisma.queryRaw()` invocation:


  Your raw query had an incorrect number of parameters. Expected: `1`, actual: `2`.
  code: 'P1016',
  clientVersion: '3.3.0',
  meta: { expected: 1, actual: 2 }
}

有什么建议吗? 我不确定这是否是一个错误。

【问题讨论】:

标签: postgresql orm prisma pg


【解决方案1】:

在 prism 文档中没有找到优雅的解决方案,我什至找不到,但是有一种方法可以工作...你可以试试这个${'variable'}

【讨论】:

    猜你喜欢
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2021-04-24
    • 2011-11-28
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多