@google-cloud/spannerlib-node-linux-x64

中文文档
0.2.0发布于 2026/08/20Apache-2.0TypeScriptESM + CJS近 30 天下载 7133

Internal Node-API wrapper for Cloud Spanner spannerlib. This is an internal package intended for Google Cloud Spanner Node drivers and may introduce breaking changes without prior notice.

原始使用文档
文档目录6 节
  1. Prerequisites
  2. Installation & Building
  3. Usage
  4. Architecture
  5. Component Interaction
  6. Component Interaction & Memory Management

Node-API Wrapper for Spanner Shared Library

NOTICE: This is an internal library intended for use by Google Cloud Spanner driver packages (such as the high-level Node.js Spanner driver). It is not intended for direct use by end customers and can introduce breaking changes without prior notice.

Prerequisites

  • Node.js >= 20.0.0
  • Go compiler (to build the underlying shared library, if not pre-built)
  • C++ toolchain (GCC/Clang or MSVC)

Installation & Building

To build the native addon and compile the driver for development, run:

npm install

For a comprehensive architectural breakdown of the 3-layer compilation pipeline (Go Link, C++ node-gyp bridge, and Dual-publishing ESM/CJS), refer to the BUILD_AND_RELEASE.md documentation.

Usage

const { Pool, Connection } = require('spannerlib-node');

async function run() {
    const pool = await Pool.create(connectionString);
    
    const conn = await pool.createConnection();
    const rows = await conn.executeSql('SELECT 1');
    
    while (await rows.next()) {
        // process rows
    }
    
    await rows.close();
    await conn.close();
    await pool.close();
}

Architecture

The wrapper consists of:

  1. src/cpp/addon.cc: C++ Node-API bridge that handles thread boundaries and type conversions between V8 and C.
  2. src/ffi/utils.ts: Helper functions to invoke native methods asynchronously using Promises.
  3. src/lib/: JavaScript classes (Pool, Connection, Rows) that provide a clean object-oriented interface.

Component Interaction

The wrapper operates by executing calls through the low-level native bridge (addon.cc). The user-facing classes (Pool, Connection, Rows) in the lib folder map execution requests into Protobuf payloads and pass them to the bridge via the asynchronous dispatcher in utils.ts. Each successful execution returns memory ID handles that are tracked inside the singleton state registry (spannerlib.ts) to link native garbage collection triggers.

Component Interaction & Memory Management

When a JavaScript object (like a Pool or Connection) is created, it holds an ID referencing a pinned Go object in memory. The spannerLib singleton maintains a FinalizationRegistry. This registry allows Node.js to listen for when the JavaScript object is garbage collected. When GC occurs, the registry automatically triggers a cleanup call to the native layer to release the corresponding Go object, preventing native memory leaks even if the developer forgets to call .close() explicitly.

版本与发布记录

@google-cloud/spannerlib-node-linux-x64 共发布 2 个版本,首次发布于 2026/08/19;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.0latest2026/08/202 个月前
0.1.02026/08/192 个月前

关于 @google-cloud/spannerlib-node-linux-x64 的常见问题

@google-cloud/spannerlib-node-linux-x64 是什么?

Internal Node-API wrapper for Cloud Spanner spannerlib. This is an internal package intended for Google Cloud Spanner Node drivers and may introduce breaking changes without prior notice.

如何安装 @google-cloud/spannerlib-node-linux-x64?

在项目目录运行 npm install @google-cloud/spannerlib-node-linux-x64,或使用 pnpm add / yarn add / bun add。

@google-cloud/spannerlib-node-linux-x64 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@google-cloud/spannerlib-node-linux-x64 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@google-cloud/spannerlib-node-linux-x64 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@google-cloud/spannerlib-node-linux-x64 可以商用吗?

@google-cloud/spannerlib-node-linux-x64 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google-cloud/spannerlib-node-linux-x64 的下载量有多少?

根据 npm 官方下载统计,@google-cloud/spannerlib-node-linux-x64 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,133 次,日均约 238 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@google-cloud/spannerlib-node-linux-x64 还在维护吗?

最新版本 0.2.0 发布于 2026/08/20(2 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。