【问题标题】:how to use json-sql with postgresql?如何将 json-sql 与 postgresql 一起使用?
【发布时间】:2018-04-28 00:23:17
【问题描述】:

我正在尝试将 json-sql npm 模块与 postgres 一起使用。 但我什至无法选择。

我认为,问题在于来自 json-sql 的查询包含 $p1 而不是 $1。 我需要调整什么才能从 json-sql 获得类似 postgres 的查询?

我尝试使用 { dialect : 'postgresql' } 配置选项,但仍然有问题。

以下代码的结果:

let userCompSql = jsonSql.build({
    type: 'select',
    fields: ['id'],
    table: 'user_computers',
    condition: {
        'os_name' : params.osName,
        'os_minor' : params.osVersionMinor
   }})

我得到一个字符串 userCompSql: "select "id" from "user_computers" where "os_name" = $p1 and "os_minor" = 0;" 但我想为我的 postgresql DB 使用 $1 而不是 $p1。

【问题讨论】:

    标签: json node.js postgresql


    【解决方案1】:

    这太容易了。只需配置 { namedValues: false }...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2017-10-19
      • 1970-01-01
      • 2022-08-17
      • 2021-04-13
      • 1970-01-01
      相关资源
      最近更新 更多