|
ORM C++
|
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.
Database support is split into three layers:
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 == ...).
A backend advertised as supported must pass the common conformance profile for the public behavior it advertises. The core profile includes:
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.
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.
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 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.
The test suite should have three distinct layers:
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.
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.
Backend support is complete when: