From 19688b8f23b79f9a7ae4bf27587d39dedb062950 Mon Sep 17 00:00:00 2001
From: ali <ali.sayyah2@gmail.com>
Date: Mon, 24 Jan 2022 15:15:35 +0330
Subject: [PATCH] added dummy model for piccolo orm

---
 .../conditional_files.json                    | 278 +++++++++---------
 .../pyproject.toml                            |   3 +
 .../db_piccolo/dao/__init__.py                |   0
 .../db_piccolo/dao/dummy_dao.py               |  38 +++
 .../db_piccolo/models/__init__.py             |   0
 .../db_piccolo/models/dummy_model.py          |   6 +
 6 files changed, 189 insertions(+), 136 deletions(-)
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/__init__.py
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/dummy_dao.py
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/__init__.py
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py

diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json b/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
index b875a9b..ee4dfca 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
@@ -1,138 +1,144 @@
 {
-    "Redis": {
-        "enabled": "{{cookiecutter.enable_redis}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/web/api/redis",
-            "{{cookiecutter.project_name}}/services/redis",
-            "{{cookiecutter.project_name}}/tests/test_redis.py",
-            "deploy/kube/redis.yml"
-        ]
-    },
-    "Kubernetes": {
-        "enabled": "{{cookiecutter.enable_kube}}",
-        "resources": [
-            "deploy/kube"
-        ]
-    },
-    "Database support": {
-        "enabled": "{{cookiecutter.db_info.name != 'none'}}",
-        "resources": [
-            "aerich.ini",
-            "alembic.ini",
-            "{{cookiecutter.project_name}}/web/api/dummy",
-            "{{cookiecutter.project_name}}/db_sa",
-            "{{cookiecutter.project_name}}/tests/test_dummy.py",
-            "deploy/kube/db.yml"
-        ]
-    },
-    "Postgres and MySQL support": {
-        "enabled": "{{cookiecutter.db_info.name != 'sqlite'}}",
-        "resources": [
-            "deploy/kube/db.yml"
-        ]
-    },
-    "Migrations": {
-        "enabled": "{{cookiecutter.enable_migrations}}",
-        "resources": [
-            "aerich.ini",
-            "alembic.ini",
-            "{{cookiecutter.project_name}}/db_sa/migrations",
-            "{{cookiecutter.project_name}}/db_ormar/migrations",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations"
-        ]
-    },
-    "Alembic migrations": {
-        "enabled": "{{cookiecutter.orm in ['ormar', 'sqlalchemy']}}",
-        "resources": [
-            "alembic.ini"
-        ]
-    },
-    "Gitlab CI": {
-        "enabled": "{{cookiecutter.ci_type == 'gitlab_ci'}}",
-        "resources": [
-            ".gitlab-ci.yml"
-        ]
-    },
-    "Github CI": {
-        "enabled": "{{cookiecutter.ci_type == 'github'}}",
-        "resources": [
-            ".github"
-        ]
-    },
-    "Routers": {
-        "enabled": "{{cookiecutter.enable_routers}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/web/api/echo",
-            "{{cookiecutter.project_name}}/web/api/dummy",
-            "{{cookiecutter.project_name}}/web/api/redis",
-            "{{cookiecutter.project_name}}/tests/test_echo.py",
-            "{{cookiecutter.project_name}}/tests/test_dummy.py",
-            "{{cookiecutter.project_name}}/tests/test_redis.py"
-        ]
-    },
-    "Dummy model": {
-        "enabled": "{{cookiecutter.add_dummy}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/web/api/dummy",
-            "{{cookiecutter.project_name}}/db_sa/dao",
-            "{{cookiecutter.project_name}}/db_sa/models/dummy_model.py",
-            "{{cookiecutter.project_name}}/db_ormar/dao",
-            "{{cookiecutter.project_name}}/db_ormar/models/dummy_model.py",
-            "{{cookiecutter.project_name}}/db_tortoise/dao",
-            "{{cookiecutter.project_name}}/db_tortoise/models/dummy_model.py",
-            "{{cookiecutter.project_name}}/tests/test_dummy.py",
-            "{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
-            "{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
-        ]
-    },
-    "Self-hosted swagger": {
-        "enabled": "{{cookiecutter.self_hosted_swagger}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/web/static",
-            "{{cookiecutter.project_name}}/web/api/docs"
-        ]
-    },
-    "SQLAlchemy ORM": {
-        "enabled": "{{cookiecutter.orm == 'sqlalchemy'}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/db_sa"
-        ]
-    },
-    "Tortoise ORM": {
-        "enabled": "{{cookiecutter.orm == 'tortoise'}}",
-        "resources": [
-            "aerich.ini",
-            "{{cookiecutter.project_name}}/db_tortoise"
-        ]
-    },
-    "Ormar ORM": {
-        "enabled": "{{cookiecutter.orm == 'ormar'}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/db_ormar"
-        ]
-    },
-    "Postgresql DB": {
-        "enabled": "{{cookiecutter.db_info.name == 'postgresql'}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_pg.sql",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql"
-        ]
-    },
-    "MySQL DB": {
-        "enabled": "{{cookiecutter.db_info.name == 'mysql'}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_mysql.sql",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql"
-        ]
-    },
-    "SQLite DB": {
-        "enabled": "{{cookiecutter.db_info.name == 'sqlite'}}",
-        "resources": [
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_sqlite.sql",
-            "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
-        ]
-    }
+  "Redis": {
+    "enabled": "{{cookiecutter.enable_redis}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/web/api/redis",
+      "{{cookiecutter.project_name}}/services/redis",
+      "{{cookiecutter.project_name}}/tests/test_redis.py",
+      "deploy/kube/redis.yml"
+    ]
+  },
+  "Kubernetes": {
+    "enabled": "{{cookiecutter.enable_kube}}",
+    "resources": [
+      "deploy/kube"
+    ]
+  },
+  "Database support": {
+    "enabled": "{{cookiecutter.db_info.name != 'none'}}",
+    "resources": [
+      "aerich.ini",
+      "alembic.ini",
+      "{{cookiecutter.project_name}}/web/api/dummy",
+      "{{cookiecutter.project_name}}/db_sa",
+      "{{cookiecutter.project_name}}/tests/test_dummy.py",
+      "deploy/kube/db.yml"
+    ]
+  },
+  "Postgres and MySQL support": {
+    "enabled": "{{cookiecutter.db_info.name != 'sqlite'}}",
+    "resources": [
+      "deploy/kube/db.yml"
+    ]
+  },
+  "Migrations": {
+    "enabled": "{{cookiecutter.enable_migrations}}",
+    "resources": [
+      "aerich.ini",
+      "alembic.ini",
+      "{{cookiecutter.project_name}}/db_sa/migrations",
+      "{{cookiecutter.project_name}}/db_ormar/migrations",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations"
+    ]
+  },
+  "Alembic migrations": {
+    "enabled": "{{cookiecutter.orm in ['ormar', 'sqlalchemy']}}",
+    "resources": [
+      "alembic.ini"
+    ]
+  },
+  "Gitlab CI": {
+    "enabled": "{{cookiecutter.ci_type == 'gitlab_ci'}}",
+    "resources": [
+      ".gitlab-ci.yml"
+    ]
+  },
+  "Github CI": {
+    "enabled": "{{cookiecutter.ci_type == 'github'}}",
+    "resources": [
+      ".github"
+    ]
+  },
+  "Routers": {
+    "enabled": "{{cookiecutter.enable_routers}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/web/api/echo",
+      "{{cookiecutter.project_name}}/web/api/dummy",
+      "{{cookiecutter.project_name}}/web/api/redis",
+      "{{cookiecutter.project_name}}/tests/test_echo.py",
+      "{{cookiecutter.project_name}}/tests/test_dummy.py",
+      "{{cookiecutter.project_name}}/tests/test_redis.py"
+    ]
+  },
+  "Dummy model": {
+    "enabled": "{{cookiecutter.add_dummy}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/web/api/dummy",
+      "{{cookiecutter.project_name}}/db_sa/dao",
+      "{{cookiecutter.project_name}}/db_sa/models/dummy_model.py",
+      "{{cookiecutter.project_name}}/db_ormar/dao",
+      "{{cookiecutter.project_name}}/db_ormar/models/dummy_model.py",
+      "{{cookiecutter.project_name}}/db_tortoise/dao",
+      "{{cookiecutter.project_name}}/db_tortoise/models/dummy_model.py",
+      "{{cookiecutter.project_name}}/tests/test_dummy.py",
+      "{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
+      "{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
+    ]
+  },
+  "Self-hosted swagger": {
+    "enabled": "{{cookiecutter.self_hosted_swagger}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/web/static",
+      "{{cookiecutter.project_name}}/web/api/docs"
+    ]
+  },
+  "SQLAlchemy ORM": {
+    "enabled": "{{cookiecutter.orm == 'sqlalchemy'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_sa"
+    ]
+  },
+  "Tortoise ORM": {
+    "enabled": "{{cookiecutter.orm == 'tortoise'}}",
+    "resources": [
+      "aerich.ini",
+      "{{cookiecutter.project_name}}/db_tortoise"
+    ]
+  },
+  "Ormar ORM": {
+    "enabled": "{{cookiecutter.orm == 'ormar'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_ormar"
+    ]
+  },
+  "Piccolo ORM": {
+    "enabled": "{{cookiecutter.orm == 'piccolo'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_piccolo"
+    ]
+  },
+  "Postgresql DB": {
+    "enabled": "{{cookiecutter.db_info.name == 'postgresql'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_pg.sql",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql"
+    ]
+  },
+  "MySQL DB": {
+    "enabled": "{{cookiecutter.db_info.name == 'mysql'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_mysql.sql",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql"
+    ]
+  },
+  "SQLite DB": {
+    "enabled": "{{cookiecutter.db_info.name == 'sqlite'}}",
+    "resources": [
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/0_20210928165300_init_sqlite.sql",
+      "{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
+    ]
+  }
 }
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml
index c9edcd8..c1614f0 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml
@@ -51,6 +51,9 @@ ormar = "^0.10.20"
 {%- if cookiecutter.enable_migrations == "True" %}
 alembic = "^1.6.5"
 {%- endif %}
+{%- if cookiecutter.orm == "piccolo" %}
+piccolo = "^0.66.0"
+{%- endif %}
 {%- if cookiecutter.db_info.name == "postgresql" %}
 asyncpg = "^0.24.0"
 psycopg2-binary = "^2.9.1"
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/__init__.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/dummy_dao.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/dummy_dao.py
new file mode 100644
index 0000000..917701a
--- /dev/null
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/dummy_dao.py
@@ -0,0 +1,38 @@
+from {{cookiecutter.project_name}}.db.models.dummy_model import DummyModel
+from typing import List, Optional
+
+
+class DummyDAO:
+    """Class for accessing dummy table."""
+
+    async def create_dummy_model(self, name: str) -> None:
+        """
+        Add single dummy to session.
+
+        :param name: name of a dummy.
+        """
+        await DummyModel.insert(DummyModel(name=name)).run()
+
+    async def get_all_dummies(self, limit: int, offset: int) -> List[DummyModel]:
+        """
+        Get all dummy models with limit/offset pagination.
+
+        :param limit: limit of dummies.
+        :param offset: offset of dummies.
+        :return: stream of dummies.
+        """
+        return (
+            await DummyModel.select().offset(offset).limit(limit).run()
+        )
+
+    async def filter(self, name: Optional[str] = None) -> List[DummyModel]:
+        """
+        Get specific dummy model.
+
+        :param name: name of dummy instance.
+        :return: dummy models.
+        """
+        query = DummyModel.select()
+        if name:
+            query = query.where(DummyModel.name == name)
+        return await query.run()
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/__init__.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py
new file mode 100644
index 0000000..40ecdaf
--- /dev/null
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py
@@ -0,0 +1,6 @@
+from piccolo.columns import Varchar
+from piccolo.table import Table
+
+
+class DummyModel(Table):
+    name = Varchar(length=200)
-- 
GitLab