statement.setAllowBareNamedParameters(enabled)
enabled<boolean> 启用或禁用对绑定命名参数而不使用前缀字符的支持。
SQLite 参数的名称以一个前缀字符开头。不过,除了美元符号之外,这些前缀字符在用作对象键时还需要额外的引号。
🌐 The names of SQLite parameters begin with a prefix character. However, with the exception of the dollar sign character, these prefix characters also require extra quoting when used in object keys.
为了提高人体工学,node:sqlite 默认允许使用裸命名参数,这些参数在 JavaScript 代码中不需要前缀字符。可以使用这种方法来禁用该行为,在绑定时需要前缀字符。当允许使用裸命名参数时,需要注意几个注意事项:
🌐 To improve ergonomics, node:sqlite allows bare named parameters, which do not
require the prefix character in JavaScript code, by default. This method can be
used to disable that behavior, requiring the prefix character when binding.
There are several caveats to be aware of when bare named parameters are
allowed:
- 在 SQL 中仍然需要前缀字符。
- 在 JavaScript 中仍然允许使用前缀字符。事实上,带前缀的名称绑定性能会略好一些。
- 在同一准备语句中使用模糊命名参数,如
$k和@k,将导致异常,因为无法确定如何绑定一个裸名称。