Skip to content

feat(orm): add std::optional mapper value conversion #499

Description

@GaspardKirira

Summary

Support std::optional<T> values at the ORM mapper boundary.

Empty optionals should map to SQL NULL, while populated optionals should use normal value conversion.

Current behavior

any_to_dbvalue_or_throw() supports direct scalar values and explicit NULL values.

A mapper returning std::optional<std::string> or std::optional<std::int64_t> is rejected as an unsupported std::any type.

Expected behavior

Common optional scalar types must convert predictably without requiring every mapper to unwrap them manually.

Scope

  • Support optional signed integers.
  • Support optional unsigned integers.
  • Support optional floating-point values.
  • Support optional booleans.
  • Support optional strings.
  • Support optional BLOB values.
  • Map empty optionals to NULL.
  • Add conversion tests.
  • Preserve existing direct values.

Suggested files

  • modules/orm/include/vix/orm/db_compat.hpp
  • modules/orm/tests/optional_conversion_test.cpp
  • modules/orm/docs/...

Acceptance criteria

  • Empty optionals convert to vix::db::null().
  • Populated optionals preserve their value.
  • Unsupported optional inner types fail clearly.
  • Existing conversion behavior remains unchanged.
  • No optional references are accepted.
  • Tests cover every documented optional type.

Non-goals

This issue does not include:

  • automatic row-to-optional conversion;
  • nested optionals;
  • nullable relationship loading;
  • changing DbValue.

Suggested labels

  • scope:orm
  • type:feature
  • tests
  • good first issue
  • status:accepted

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions