statement.setAllowBareNamedParameters(enabled)


  • enabled <boolean> 启用或禁用对不带前缀字符的命名参数的绑定支持。

    ¥enabled <boolean> Enables or disables support for binding named parameters without the prefix character.

SQLite 参数的名称以前缀字符开头。默认情况下,node:sqlite 要求在绑定参数时存在此前缀字符。但是,除了美元符号字符外,这些前缀字符在对象键中使用时也需要额外的引号。

¥The names of SQLite parameters begin with a prefix character. By default, node:sqlite requires that this prefix character is present when binding parameters. However, with the exception of dollar sign character, these prefix characters also require extra quoting when used in object keys.

为了提高人机工程学,此方法还可用于允许裸命名参数,这些参数不需要 JavaScript 代码中的前缀字符。启用裸命名参数时需要注意以下几点:

¥To improve ergonomics, this method can be used to also allow bare named parameters, which do not require the prefix character in JavaScript code. There are several caveats to be aware of when enabling bare named parameters:

  • SQL 中仍然需要前缀字符。

    ¥The prefix character is still required in SQL.

  • JavaScript 中仍然允许使用前缀字符。实际上,带前缀的名称将具有略好的绑定性能。

    ¥The prefix character is still allowed in JavaScript. In fact, prefixed names will have slightly better binding performance.

  • 在同一个准备好的语句中使用模糊命名参数(例如 $k@k)将导致异常,因为无法确定如何绑定裸名称。

    ¥Using ambiguous named parameters, such as $k and @k, in the same prepared statement will result in an exception as it cannot be determined how to bind a bare name.