From d4988a19f661d64296b0c0401afbc2a3dc6b6334 Mon Sep 17 00:00:00 2001
From: ali <ali.sayyah2@gmail.com>
Date: Tue, 25 Jan 2022 23:08:32 +0330
Subject: [PATCH] added dao app

---
 .../conditional_files.json                       |  3 ++-
 .../db_piccolo/{models => }/__init__.py          |  0
 .../db_piccolo/dao/migrations/__init__.py        |  0
 .../db_piccolo/dao/piccolo_app.py                | 16 ++++++++++++++++
 .../{models/dummy_model.py => dao/tables.py}     |  0
 .../piccolo_conf.py                              |  6 ++++--
 6 files changed, 22 insertions(+), 3 deletions(-)
 rename fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/{models => }/__init__.py (100%)
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/migrations/__init__.py
 create mode 100644 fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/piccolo_app.py
 rename fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/{models/dummy_model.py => dao/tables.py} (100%)

diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json b/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
index ee4dfca..3dfef3b 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json
@@ -38,7 +38,8 @@
       "alembic.ini",
       "{{cookiecutter.project_name}}/db_sa/migrations",
       "{{cookiecutter.project_name}}/db_ormar/migrations",
-      "{{cookiecutter.project_name}}/db_tortoise/migrations"
+      "{{cookiecutter.project_name}}/db_tortoise/migrations",
+      "{{cookiecutter.project_name}}/db_piccolo/migrations"
     ]
   },
   "Alembic migrations": {
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/__init__.py
similarity index 100%
rename from fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/__init__.py
rename to fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/__init__.py
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/migrations/__init__.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/piccolo_app.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/piccolo_app.py
new file mode 100644
index 0000000..14feaaf
--- /dev/null
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/piccolo_app.py
@@ -0,0 +1,16 @@
+import os
+from piccolo.conf.apps import table_finder
+
+from piccolo.conf.apps import AppConfig
+
+CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
+
+APP_CONFIG = AppConfig(
+    app_name='dao',
+    migrations_folder_path=os.path.join(CURRENT_DIRECTORY, 'migrations'),
+    table_classes=table_finder(
+        modules=['{{cookiecutter.project_name}}.db_piccolo.dao.tables']
+    ),
+    migration_dependencies=[],
+    commands=[]
+)
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/dao/tables.py
similarity index 100%
rename from fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py
rename to fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_piccolo/dao/tables.py
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/piccolo_conf.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/piccolo_conf.py
index d4471d3..0383085 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/piccolo_conf.py
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/piccolo_conf.py
@@ -18,5 +18,7 @@ DB = SQLiteEngine(path=settings.db_file)
 {%- endif %}
 
 # A list of paths to piccolo apps
-# e.g. ['blog.piccolo_app']
-APP_REGISTRY = AppRegistry(apps=[])
+# e.g. ['sample_project.db_piccolo.dao.piccolo_app']
+APP_REGISTRY = AppRegistry(
+    apps=['{{cookiecutter.project_name}}.db_piccolo.dao.piccolo_app']
+)
-- 
GitLab