From ad3d4c82f4378d91f2db7fe9c23f1eeffb7eba66 Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Sat, 7 Jan 2023 20:26:11 +0000 Subject: [PATCH] add REAL type (#44) * add REAL type * lint * fix test (ran locally) --- omymodels/models/sqlalchemy/types.py | 1 + .../generator/test_sqlalchemy_core.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/omymodels/models/sqlalchemy/types.py b/omymodels/models/sqlalchemy/types.py index c21db47..47bfeaf 100644 --- a/omymodels/models/sqlalchemy/types.py +++ b/omymodels/models/sqlalchemy/types.py @@ -32,6 +32,7 @@ "smallint": "sa.SmallInteger", "jsonb": "JSONB", "uuid": "UUID", + "real": "sa.REAL", } types_mapping.update(direct_types) diff --git a/tests/functional/generator/test_sqlalchemy_core.py b/tests/functional/generator/test_sqlalchemy_core.py index 1cdd06e..68a5381 100644 --- a/tests/functional/generator/test_sqlalchemy_core.py +++ b/tests/functional/generator/test_sqlalchemy_core.py @@ -137,3 +137,31 @@ class Products(Base): """ result = create_models(ddl, models_type="sqlalchemy")["code"] assert result == expected + + +def test_real(): + expected = """import sqlalchemy as sa +from sqlalchemy.ext.declarative import declarative_base + + +Base = declarative_base() + + +class Measurements(Base): + + __tablename__ = 'measurements' + + id = sa.Column(sa.String(32), primary_key=True) + date = sa.Column(sa.TIMESTAMP()) + value = sa.Column(sa.REAL()) +""" + + ddl = """ + CREATE TABLE "measurements" ( + "id" char(32) PRIMARY KEY NOT NULL, + "date" timestamp, + "value" real, + );""" + + result = create_models(ddl, models_type="sqlalchemy")["code"] + assert result == expected