Repository: jdkandersson/OpenAlchemy

Issue:
Support byte
As a user I want to define a byte format so that I can store and retrieve base64 encoded values from the database.

Support byte as indicated by the appropriate format directive of a string.

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0e38c7e..e44f4266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
 ## Version _next_
 
+- Add support for _byte_
 - Add support for _date_
 - Move SQLAlchemy relationship construction behind facade
 - Move schema calculations into separate files
diff --git a/README.md b/README.md
index d92da4f9..4684c692 100644
--- a/README.md
+++ b/README.md
@@ -100,6 +100,7 @@ An example API has been defined using connexion and Flask here:
 - `number` (float only),
 - `boolean`,
 - `string`,
+- `byte`,
 - `date`,
 - `date-time`,
 - `$ref` references for columns and models,
diff --git a/docs/source/technical_details/type_mapping.rst b/docs/source/technical_details/type_mapping.rst
index 201d7faf..077313ac 100644
--- a/docs/source/technical_details/type_mapping.rst
+++ b/docs/source/technical_details/type_mapping.rst
@@ -19,6 +19,8 @@ following mappings:
 +--------------+----------------+-----------------+
 | string       | *undefined*    | String          |
 +--------------+----------------+-----------------+
+|              | byte           | String          |
++--------------+----------------+-----------------+
 |              | date           | Date            |
 +--------------+----------------+-----------------+
 |              | date-time      | DateTime        |
diff --git a/open_alchemy/column_factory/column.py b/open_alchemy/column_factory/column.py
index 76987e22..7a2874aa 100644
--- a/open_alchemy/column_factory/column.py
+++ b/open_alchemy/column_factory/column.py
@@ -272,7 +272,7 @@ def _handle_string(*, artifacts: types.ColumnArtifacts) -> sqlalchemy.String:
         raise exceptions.MalformedSchemaError(
             "The string type does not support autoincrement."
         )
-    if artifacts.format is None:
+    if artifacts.format in {None, "byte"}:
         if artifacts.max_length is None:
             return sqlalchemy.String
         return sqlalchemy.String(length=artifacts.max_length)


Test patch:
diff --git a/tests/open_alchemy/column_factory/test_column.py b/tests/open_alchemy/column_factory/test_column.py
index 96309c35..d2a11fe6 100644
--- a/tests/open_alchemy/column_factory/test_column.py
+++ b/tests/open_alchemy/column_factory/test_column.py
@@ -521,8 +521,9 @@ def test_handle_string_invalid_format():
         (None, sqlalchemy.String),
         ("date", sqlalchemy.Date),
         ("date-time", sqlalchemy.DateTime),
+        ("byte", sqlalchemy.String),
     ],
-    ids=["None", "date", "date-time"],
+    ids=["None", "date", "date-time", "byte"],
 )
 @pytest.mark.column
 def test_handle_string(format_, expected_type):