Domain-Driven Design, part 7 — Alternative Relational Database Mapping

Product Name Story

Use cases

LangValue Extraction

Relational Database Storage

Serialization

Example of serialized object

{
"cs-CZ": "Televize",
"en-GB": "Television",
"es-ES": "televisión",
"ru-RU": "телевидение"
}

LangValue Doctrine Mapping

Registration

\Doctrine\DBAL\Types\Type::addType(LangValueType::LANG_VALUE, LangValueType::class);/** @var Doctrine\DBAL\Connection */
$connection = ...;
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping(LangValueType::LANG_VALUE, LangValueType::LANG_VALUE);

Mapping

Database Search in JSON

PostgreSQL

SELECT * FROM Product where name->>'cs-CZ' LIKE '%query%';

MySQL

SELECT * FROM Product where name->'$.cs-CZ' LIKE '%query%';

TL;DR

References

Contact

Developer interested in Domain-Driven Design & Modeling