Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

rhosocial-activerecord-sqlserver ($\rho_{\mathbf{AR}\text{-sqlserver}}$)

PyPI version Python Tests Coverage Status Apache 2.0 License Powered by vistart

rhosocial ActiveRecord Logo

SQL Server Backend for rhosocial-activerecord

T-SQL Support · Enterprise Features · Sync & Async

Note: This is a backend implementation for rhosocial-activerecord. It cannot be used standalone.

Why This Backend?

1. SQL Server-Specific Optimizations

Feature This Backend Generic Solutions
RETURNING/OUTPUT Native OUTPUT clause Manual SELECT-after-write
Temporal Tables FOR SYSTEM_TIME Application-level audit logs
Partitioning PARTITION schemes/functions Manual sharding
Sequences Native CREATE SEQUENCE Identity/application counters

2. True Sync-Async Parity

Same API surface for both sync and async operations:

# Sync
users = User.query().where(User.c.age >= 18).all()

# Async - just add await
users = await User.query().where(User.c.age >= 18).all()

3. Built for Production

  • Connection pooling with configurable pool sizes
  • Transaction support with proper isolation levels
  • Error mapping from SQL Server error codes to Python exceptions
  • Type adapters for SQL Server-specific data types

Quick Start

Installation

pip install rhosocial-activerecord-sqlserver

Basic Usage

from rhosocial.activerecord.model import ActiveRecord
from rhosocial.activerecord.backend.impl.sqlserver import SQLServerBackend
from rhosocial.activerecord.backend.impl.sqlserver.config import SQLServerConnectionConfig
from typing import Optional

class User(ActiveRecord):
    __table_name__ = "users"
    id: Optional[int] = None
    name: str
    email: str

# Configure
config = SQLServerConnectionConfig(
    host="localhost",
    port=1433,
    database="myapp",
    username="sa",
    password="YourStrong!Passw0rd"
)
User.configure(config, SQLServerBackend)

# Use
user = User(name="Alice", email="alice@example.com")
user.save()

# Query with parameter binding
results = User.query().where("email = ?", ("alice@example.com",)).all()

💡 AI Prompt: "How do I configure connection pooling for SQL Server?"

SQL Server-Specific Features

OUTPUT / RETURNING

Retrieve inserted or updated rows with the OUTPUT clause:

# INSERT with OUTPUT
user = User(name="Alice", email="alice@example.com")
user.save()
print(user.id)  # Populated automatically via OUTPUT

Temporal Tables

Query historical state with FOR SYSTEM_TIME:

# As of a specific time
User.query().where(
    "user_id = ? FOR SYSTEM_TIME AS OF ?",
    (1, "2026-06-30T12:00:00"),
).all()

Partitioned Tables

SQL Server partition schemes and functions:

# Partitioned table DDL support
class Orders(ActiveRecord):
    __table_name__ = "orders"
    __partition__ = {
        "column": "order_date",
        "scheme": "ps_order_date",
    }
    order_id: int
    order_date: datetime

Sequences

Native sequence support:

# Use a sequence-backed column
class Ticket(ActiveRecord):
    __table_name__ = "tickets"
    ticket_no: int  # NEXT VALUE FOR ticket_seq

Requirements

  • Python: 3.9+ (including 3.13t/3.14t free-threaded builds)
  • Core: rhosocial-activerecord>=1.0.0
  • Driver: pyodbc>=5.0.0 (with ODBC Driver 17+ for SQL Server)

SQL Server Version Compatibility

Feature Min Version Notes
Basic operations 2017+ Core functionality
Temporal tables 2016+ FOR SYSTEM_TIME
Sequences 2012+ CREATE SEQUENCE
Partitioning 2008+ Partition functions/schemes
Columnstore indexes 2014+ Analytics acceleration
Memory-optimized tables 2014+ In-memory OLTP
PIVOT/UNPIVOT 2005+ Row-to-column transforms
OUTPUT clause 2005+ RETURNING equivalent
JSON functions 2016+ JSON_VALUE, JSON_QUERY
STRING_AGG 2017+ String aggregation
UTF-8 collation 2019+ _UTF8 collations

Recommended: SQL Server 2019+ for optimal feature support.

Get Started with AI Code Agents

This project supports AI-assisted development. Clone and open in your preferred tool:

git clone https://github.com/rhosocial/python-activerecord-sqlserver.git
cd python-activerecord-sqlserver

Example AI Prompts

  • "How do I configure connection pooling for SQL Server?"
  • "Show me how to use temporal tables"
  • "How do I use the OUTPUT clause with INSERT?"
  • "Create a model with a partitioned table"

For Any LLM

Feed the documentation files in docs/ to your preferred LLM for context-aware assistance.

Testing

⚠️ CRITICAL: Tests MUST run serially. Do NOT use pytest -n auto or parallel execution.

# Run all tests
PYTHONPATH=src pytest tests/

# Run specific feature tests
PYTHONPATH=src pytest tests/rhosocial/activerecord_sqlserver_test/feature/basic/
PYTHONPATH=src pytest tests/rhosocial/activerecord_sqlserver_test/feature/query/

See the Testing Documentation for details.

Documentation

Comparison with Other Backends

Feature SQL Server PostgreSQL SQLite
RETURNING ✅ OUTPUT ✅ RETURNING ✅ RETURNING
Temporal Tables ✅ ❌ ❌
Sequences ✅ Native ✅ Native ⚠️ Emulated
Arrays ❌ ✅ Native ❌
JSON Type ⚠️ Functions only ✅ JSONB ⚠️ JSON1 extension

💡 AI Prompt: "When should I choose SQL Server over PostgreSQL for my project?"

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

License

Apache License 2.0 — Copyright © 2026 vistart


Built with ❤️ by the rhosocial team

GitHub · Documentation · PyPI

Metadata

Release files for rhosocial-activerecord-sqlserver 1.0.0.dev2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rhosocial-activerecord-sqlserver 1.0.0.dev2
File Size Uploaded
rhosocial_activerecord_sqlserver-1.0.0.dev2.tar.gz 124.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rhosocial-activerecord-sqlserver 1.0.0.dev2
File Interpreter ABI Platform
rhosocial_activerecord_sqlserver-1.0.0.dev2-py3-none-any.whl Python 3 none any Details

Total release size: 302.3 kB

Release files / rhosocial_activerecord_sqlserver-1.0.0.dev2.tar.gz

Download URL rhosocial_activerecord_sqlserver-1.0.0.dev2.tar.gz
Size 124.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2d5d40398418d5cafa024e871626aa925003539fdd932f2fdbaab644c90b8b1
BLAKE2b-256 checksum
How to use checksums
7ddd38060717f63979a8c1236dd5097b9a71ccdf4eeff09f9158220131382509
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 15, 2026.

Transparency log

Release files / rhosocial_activerecord_sqlserver-1.0.0.dev2-py3-none-any.whl

Download URL rhosocial_activerecord_sqlserver-1.0.0.dev2-py3-none-any.whl
Size 177.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5977841850396bddd85feeb3e42c917e8225e9e0e9df174c0f341437df2d459
BLAKE2b-256 checksum
How to use checksums
5c8c45b6ff509bcc1a38a8254fffd389c1aa4e352d0f7939038d5dd635c0c7f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0.dev2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page