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


  • name <string> 要创建的 SQLite 函数的名称。

    ¥name <string> The name of the SQLite function to create.

  • options <Object> 函数的可选配置设置。支持以下属性:

    ¥options <Object> Optional configuration settings for the function. The following properties are supported:

    • deterministic <boolean> 如果是 true,则在创建的函数上设置 SQLITE_DETERMINISTIC 标志。默认值:false

      ¥deterministic <boolean> If true, the SQLITE_DETERMINISTIC flag is set on the created function. Default: false.

    • directOnly <boolean> 如果是 true,则在创建的函数上设置 SQLITE_DIRECTONLY 标志。默认值:false

      ¥directOnly <boolean> If true, the SQLITE_DIRECTONLY flag is set on the created function. Default: false.

    • useBigIntArguments <boolean> 如果 true,则 function 的整数参数将转换为 BigInt。如果 false,则整数参数作为 JavaScript 数字传递。默认值:false

      ¥useBigIntArguments <boolean> If true, integer arguments to function are converted to BigInts. If false, integer arguments are passed as JavaScript numbers. Default: false.

    • varargs <boolean> 如果 true,则可以使用任意数量的参数(零到 SQLITE_MAX_FUNCTION_ARG 之间)调用 function。如果 falsefunction 必须使用恰好 function.length 个参数调用。默认值:false

      ¥varargs <boolean> If true, function may be invoked with any number of arguments (between zero and SQLITE_MAX_FUNCTION_ARG). If false, function must be invoked with exactly function.length arguments. Default: false.

  • function <Function> 调用 SQLite 函数时要调用的 JavaScript 函数。此函数的返回值应为有效的 SQLite 数据类型:见 JavaScript 和 SQLite 之间的类型转换。如果返回值为 undefined,则结果默认为 NULL

    ¥function <Function> The JavaScript function to call when the SQLite function is invoked. The return value of this function should be a valid SQLite data type: see Type conversion between JavaScript and SQLite. The result defaults to NULL if the return value is undefined.

此方法用于创建 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().