Adapters

MSSQL

Use Microsoft SQL Server through SQLAlchemy where the async driver is available.

Kernia's relational contract can run on SQL Server through SQLAlchemy. Treat this path as a SQLAlchemy deployment choice: validate the async driver, generated column types, identifier lengths, and migration output in a staging database before production.

Installation

uv add kernia kernia-sqlalchemy sqlalchemy alembic

Install the SQL Server async driver and system dependencies required by your platform. Driver selection depends on your deployment target and operating system.

Configuration

auth.py
import os
from sqlalchemy.ext.asyncio import create_async_engine

from kernia import KerniaOptions
from kernia.auth import init
from kernia_sqlalchemy import sqlalchemy_adapter

engine = create_async_engine(os.environ["DATABASE_URL"], pool_pre_ping=True)
adapter = sqlalchemy_adapter(engine)

auth = init(KerniaOptions(
    database=adapter,
    secret=os.environ["KERNIA_SECRET"],
    base_url=os.environ["KERNIA_BASE_URL"],
))

Migrations

Generate migrations from the same auth object your server mounts:

uv run kernia generate --app app.auth:auth --output alembic/versions/0001_kernia.py
alembic upgrade head

Review JSON columns, text columns, boolean defaults, timestamp precision, index names, and identifier length. SQL Server has different type and default-expression behavior than PostgreSQL.

Operational notes

  • Enable connection health checks with pool_pre_ping=True.
  • Keep auth tables in a schema with explicit permissions.
  • Test lock behavior during session revocation and verification token consumption.
  • Watch connection pool exhaustion, deadlocks, and migration locks.

Test coverage

Run the full auth route suite against SQL Server before declaring support in your own app. Password sign-in, OAuth callbacks, verification token consumption, API key lookup, organization membership, and session revocation are the minimum flows to cover.