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> 如果为 true,则 function 可以用任意数量的参数(在零到 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().】