StepflowStepflow

MSSQL Storage

Enterprise-grade storage adapter for Microsoft SQL Server

MSSQL Storage

The @stepflowjs/storage-mssql adapter provides an enterprise-grade storage backend using Microsoft SQL Server. It uses sp_getapplock for distributed locking and MERGE statements for atomic updates.

Installation

pnpm add @stepflowjs/storage-mssql

Usage

import { Stepflow } from "@stepflowjs/core";
import { MssqlStorageAdapter } from "@stepflowjs/storage-mssql";

const stepflow = new Stepflow({
  storage: new MssqlStorageAdapter({
    server: "localhost",
    database: "StepflowDB",
    user: "sa",
    password: "YourStrongPassword",
    options: {
      encrypt: true,
      trustServerCertificate: true,
    },
  }),
});

Configuration Options

OptionTypeDescription
serverstringSQL Server host
databasestringDatabase name
userstringDatabase user
passwordstringDatabase password
portnumberDatabase port (default: 1433)
schemastringDatabase schema (default: stepflow)
poolSizenumberMaximum number of connections in the pool (default: 20)
options.encryptbooleanUse encryption (default: true)
options.trustServerCertificatebooleanTrust self-signed certificates (default: false)

Features

  • Enterprise Ready: Full support for Microsoft SQL Server features.
  • Distributed Locking: Uses sp_getapplock for reliable leader election.
  • Atomic Updates: Uses MERGE statements to handle upserts and state transitions atomically.
  • Automatic Migrations: Automatically creates schemas, tables, and indexes on startup.

Environment Variables

MSSQL_SERVER=localhost
MSSQL_DATABASE=StepflowDB
MSSQL_USER=sa
MSSQL_PASSWORD=YourStrongPassword

On this page