database.loadExtension(path[, entryPoint])


  • path <string> 要加载的共享库路径。
  • entryPoint <string> 扩展入口点函数的名称。省略时,SQLite 会从共享库的文件名推导入口点;当推导的名称不匹配时,请显式传入此参数。

将共享库加载到数据库连接中。此方法是 sqlite3_load_extension() 的封装。在构建 DatabaseSync 实例时,需要启用 allowExtension 选项。

🌐 Loads a shared library into the database connection. This method is a wrapper around sqlite3_load_extension(). It is required to enable the allowExtension option when constructing the DatabaseSync instance.

import { DatabaseSync } from 'node:sqlite';
const database = new DatabaseSync(':memory:', { allowExtension: true });

// Load using the entry point derived from the filename.
database.loadExtension('./decimal.dylib');

// Override the entry point when the derived name does not match.
database.loadExtension('./base64.dylib', 'sqlite3_base64_init');const { DatabaseSync } = require('node:sqlite');
const database = new DatabaseSync(':memory:', { allowExtension: true });

// Load using the entry point derived from the filename.
database.loadExtension('./decimal.dylib');

// Override the entry point when the derived name does not match.
database.loadExtension('./base64.dylib', 'sqlite3_base64_init');