Skip to content

Runtime Support

The @tsdrivers/mssql package includes FFI adapters for all three supported runtimes. The correct adapter is selected automatically — no configuration needed.

How It Works

When you first call createPool() or connect(), the package:

  1. Detects the runtime (Deno, Bun, or Node.js)
  2. Loads the correct FFI adapter (Deno.dlopen or koffi)
  3. Resolves the native library using the standard search order
  4. Caches the result — subsequent calls reuse the same FFI singleton

Deno

FFI initialization starts eagerly at module evaluation time. Since Deno's dlopen is synchronous, the FFI is typically ready before your code calls createPool() or connect().

Node.js

Uses koffi for FFI binding with nonblocking async calls via worker threads. Install alongside the package:

sh
npm install @tsdrivers/mssql koffi

Bun

Also uses koffi for nonblocking async FFI support (Bun's built-in bun:ffi does not support async calls). Install alongside the package:

sh
bun add @tsdrivers/mssql koffi

Low-Level FFI Access

The package exports getFfi() and loadLibrary() for advanced use cases:

ts
import { getFfi, loadLibrary } from "@tsdrivers/mssql";

// Get the FFI singleton (resolved lazily, or eagerly on Deno)
const ffi = await getFfi();

// Or load from an explicit path
const ffi = await loadLibrary("/path/to/mssqlts-linux-x86_64.so");

// Check FILESTREAM availability (Windows only)
if (ffi.filestreamAvailable()) {
  console.log("FILESTREAM is available");
}