From 5b694508d5e4972b97fae7c294914e3d914f29fc Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sun, 29 Oct 2023 21:21:42 +0000 Subject: [PATCH] Address suggestions --- robyn/scaffold/postgres/requirements.txt | 3 ++- robyn/scaffold/sqlalchemy/__init__.py | 0 robyn/scaffold/sqlalchemy/app.py | 17 ++--------------- robyn/scaffold/sqlalchemy/models.py | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 robyn/scaffold/sqlalchemy/__init__.py create mode 100644 robyn/scaffold/sqlalchemy/models.py diff --git a/robyn/scaffold/postgres/requirements.txt b/robyn/scaffold/postgres/requirements.txt index 0bb990a81..522145719 100644 --- a/robyn/scaffold/postgres/requirements.txt +++ b/robyn/scaffold/postgres/requirements.txt @@ -1,2 +1,3 @@ robyn -psycopg2 +psycopg2; platform_system=="Windows" +psycopg2-binary; platform_system!="Windows" diff --git a/robyn/scaffold/sqlalchemy/__init__.py b/robyn/scaffold/sqlalchemy/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/robyn/scaffold/sqlalchemy/app.py b/robyn/scaffold/sqlalchemy/app.py index 07bc38760..0e9d1b31a 100644 --- a/robyn/scaffold/sqlalchemy/app.py +++ b/robyn/scaffold/sqlalchemy/app.py @@ -1,6 +1,6 @@ from robyn import Robyn -from sqlalchemy import create_engine, Column, Integer, String, Boolean -from sqlalchemy.orm import declarative_base, sessionmaker +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker engine = create_engine("sqlite+pysqlite:///:memory:", echo=True) @@ -16,17 +16,4 @@ def index(): if __name__ == "__main__": # create a configured "Session" class - Base = declarative_base() - - class User(Base): - __tablename__ = "users" - - id = Column(Integer, primary_key=True, index=True) - username = Column(String, unique=True, index=True) - hashed_password = Column(String) - is_active = Column(Boolean, default=True) - is_superuser = Column(Boolean, default=False) - - Base.metadata.create_all(bind=engine) - app.start(host="0.0.0.0", port=8080) diff --git a/robyn/scaffold/sqlalchemy/models.py b/robyn/scaffold/sqlalchemy/models.py new file mode 100644 index 000000000..e36336655 --- /dev/null +++ b/robyn/scaffold/sqlalchemy/models.py @@ -0,0 +1,18 @@ +from sqlalchemy.orm import declarative_base +from sqlalchem.orm import Column, Integer, String, Boolean + +Base = declarative_base() + + +class User(Base): + __tablename__ = "users" + + id = Column(Integer, primary_key=True, index=True) + username = Column(String, unique=True, index=True) + hashed_password = Column(String) + is_active = Column(Boolean, default=True) + is_superuser = Column(Boolean, default=False) + + +if __name__ == "__main__": + Base.metadata.create_all(bind=engine)