【问题标题】:knex is building an invalid queryknex 正在构建一个无效的查询
【发布时间】:2021-11-11 15:38:42
【问题描述】:

我是 knex 的新手。我在迁移时遇到了困难。插入数据似乎工作得很好。但是,当我尝试在迁移中查询数据时,出现意外错误。

这个查询:

await knex.select().from('account_types').where({ key: t.key }).first()

产生这个错误:

error: select (select *) from "public"."account_types" where "key" = $1 limit $2 - SELECT * with no tables specified is not valid

显然生成的查询是无效的,但我不知道为什么它会随机插入“select *”

【问题讨论】:

    标签: knex.js


    【解决方案1】:

    你不想同时使用firstselect,如果你只想获取一个结果,基本上first应该替换select

    即您的查询应该是

    await knex.from('account_types').where({ key: t.key }).first()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      相关资源
      最近更新 更多