ORM C++
Loading...
Searching...
No Matches
Backend portability

orm-cxx treats SQLite, PostgreSQL, MySQL and MariaDB as equal adapters. All backend selections are explicit and default to disabled. Its portability layer requires live behavior verification instead of treating an enum value or a generated SQL string as proof of backend support.

This document defines the portability boundary. See Backends for the support status visible to users and Backend extension contract for the contributor-facing implementation requirements.

Portability layers

Database support is split into three layers:

  1. Public ORM behavior covers connection lifecycle, schema operations, binding and hydration, CRUD, affected-row reporting, transactions, queries, and relations. Reusable backend conformance tests define this layer.
  2. Backend adapter splits into a dialect for database-specific SQL and a runtime for session behavior. Identifier quoting, pagination syntax, generated-key DDL, and idempotent relation mutations belong to the dialect; session initialization, catalog access, limits, and driver errors belong to the runtime.
  3. SOCI transport opens the driver session and exchanges prepared statement values. SOCI is transport infrastructure; using a SOCI backend does not by itself make the ORM behavior portable or supported.

Backend selection, capabilities, and limits must be resolved before an ORM operation generates SQL. Core code must not accumulate scattered checks such as if (backend == ...).

Portable behavior

A backend advertised as supported must pass the common conformance profile for the public behavior it advertises. The core profile includes:

  • connecting, disconnecting, and reconnecting with deterministic errors;
  • table creation and removal for supported model shapes;
  • prepared binding and hydration of supported scalar and nullable values;
  • insert, full-model and projection select, filtered update, and filtered remove;
  • exact affected-row counts where the public API returns a count;
  • commit and rollback behavior;
  • deterministic ordering and pagination;
  • primary keys, composite keys, mapped names, and supported relations;
  • consistent error categories independent of vendor message text.

Tests that compare rows positionally must request an explicit order. Generated keys are tested for uniqueness and usability, not for a vendor-specific starting value. Backend-specific SQL snapshots are dialect tests rather than conformance tests.

Capabilities and dialect differences

A capability describes user-visible behavior that a backend may genuinely be unable to provide. A dialect difference describes how an advertised behavior is implemented.

Capability or limit Dialect detail
Database-generated integer keys Generated-column syntax
Full-model grouping semantics GROUP BY rendering or an equivalent query
Collection-relation support Junction DDL and idempotent link syntax
Enforced foreign keys Session setup such as SQLite pragmas
Native date, time, or UUID types Concrete SQL type name
Maximum bind-parameter count How placeholders are written
Maximum lossless numeric exchange value Driver representation used for binding

Capabilities and numeric limits are reported centrally by the selected backend. If an optional feature is unavailable, the ORM must reject it predictably before issuing SQL. Syntax differences such as quoting, IF EXISTS, upsert forms, or offset-without-limit are responsibilities of the dialect and should not require application feature checks.

Binding and SOCI

The ORM defines the C++ values and null semantics accepted by its public API. Each backend must prove through conformance tests that its SOCI driver can bind and hydrate those values without silent narrowing or null loss. A backend may adapt SQL types or exchange representations internally, but those details must not leak into model or query code.

The native date/time and UUID types are optional capabilities: PostgreSQL and MariaDB support all five, MySQL the four temporal types, and SQLite none. UUID fields can opt into Binary16 or Text36 on MySQL and SQLite independently of their C++ type. Text exchanged with native columns is an internal transport representation, not a text-column fallback. Values retain their logical type until adapter encoding. Native results explicitly receive text through SOCI, preserving microseconds without its std::tm path or SQL formatting casts. This preserves DISTINCT, grouping and native ordering semantics. Binary16 uses a session-bound binary exchange and Text36 canonical text; SQLite also verifies the actual storage class.

Temporal precision is fixed at six digits. Static bounds and negotiated connection-specific bounds both apply to inputs and results. Local datetimes and UTC instants remain distinct. ISO output, UTC sessions and explicit timestamp defaults are adapter invariants, restored after reconnect and protected by migration guards. UUID equality and keys are shared; typed UUID ordering, range predicates and MIN/MAX are excluded.

Connection-string parsing, session initialization, affected-row normalization, and driver exception translation are also backend responsibilities. Connection strings and credentials must not be copied into public error messages.

Raw SQL

Raw predicates and raw ordering are intentional backend-specific escape hatches. Their fragments are passed to the selected database dialect; they are not rewritten or promised to work on another backend. Explicit values still use prepared SOCI bind parameters, so changing backend does not permit interpolation of untrusted values.

Portable application code should prefer the typed query API. Documentation and tests must label raw SQL examples with the backend whose syntax they use.

Verification model

The test suite should have three distinct layers:

  • unit and dialect tests may inspect generated SQL and binding payloads;
  • common conformance tests use only public ORM APIs;
  • backend-specific integration tests may inspect driver setup, catalogs, and vendor-specific behavior.

Every backend runs the same conformance sources through its own test harness. The harness supplies its connection, declared capabilities and limits, isolated schema, and cleanup. An unsupported optional capability is tested by asserting a stable unsupported-feature error, not by silently skipping all coverage.

Minimum CI matrix

The minimum project matrix is deliberately smaller than the Cartesian product of every compiler and every database:

Job Environment Required checks
Core GCC 15, Clang 18–20 and MSVC without database clients Unit, compile contracts and core consumer
All adapters GCC 15 and Clang 18–20 with real services; MSVC compile/link Equal conformance profiles and all 16 consumer subsets
Quality and docs Clang 18 with every selected client Formatting, static analysis for every adapter, documentation validation
Coverage Clang 18, core plus four independent adapters Merge every report; require 100% lines
Packages Conan/vcpkg, Linux/Windows, all 16 subsets Positive and disabled-provider compile contracts; live CRUD and migrations on Linux

A backend receives additional operating-system or compiler jobs only when those combinations are publicly supported. A claimed server-version range must be represented at its boundaries in CI; otherwise documentation must name only the version actually verified.

Definition of Done

Backend support is complete when:

  • every advertised adapter passes the same reusable public conformance tests;
  • common conformance sources contain no vendor catalog queries, pragmas, exact SQL snapshots, or private access to a SOCI session;
  • capabilities and limits are obtained from one backend contract rather than scattered backend enum branches;
  • command generation, binding, session setup, affected rows, and errors have documented backend responsibilities;
  • adding a backend requires its adapter, dependency target, test harness, registry entry, and documentation entry, without copying common tests or changing public ORM semantics;
  • CI verifies each advertised backend against a real database implementation;
  • Backends accurately distinguishes supported, experimental, and planned implementations.