database.function(name[, options], function)


  • name <string> 要创建的 SQLite 函数的名称。
  • options <Object> 该函数的可选配置设置。支持以下属性:
    • deterministic <boolean> 如果 true,则在创建的函数上设置 SQLITE_DETERMINISTIC 标志。默认值: false
    • directOnly <boolean> 如果 true,则在创建的函数上设置 SQLITE_DIRECTONLY 标志。默认值: false
    • useBigIntArguments <boolean> 如果 true,传递给 function 的整数参数会被转换为 BigInt。如果 false,整数参数将作为 JavaScript 数字传递。默认值: false
    • varargs <boolean> 如果 truefunction 可以用任意数量的参数调用(介于零到 SQLITE_MAX_FUNCTION_ARG 之间)。如果 falsefunction 必须使用准确的 function.length 个参数调用。默认值: false
  • function <Function> 当调用 SQLite 函数时要调用的 JavaScript 函数。此函数的返回值应为有效的 SQLite 数据类型:参见 JavaScript 和 SQLite 之间的类型转换。如果返回值为 undefined,则结果默认为 NULL

此方法用于创建 SQLite 用户自定义函数。此方法是 sqlite3_create_function_v2() 的一个封装。

🌐 This method is used to create SQLite user-defined functions. This method is a wrapper around sqlite3_create_function_v2().