Skip to content

Commit 496d4b9

Browse files
committed
sql alchemy replacing flask sql alchemy
1 parent 4ce8595 commit 496d4b9

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ def return_error():
5656
flask.abort(500, f"Test")
5757

5858

59+
def get_db_path_from_config():
60+
database_uri = app.config.get("SQLALCHEMY_DATABASE_URI", "")
61+
if database_uri.startswith("sqlite:///"):
62+
return database_uri.replace("sqlite:///", "")
63+
return None
64+
65+
5966
# ''' Main '''
6067
if __name__ == "__main__":
61-
init_database(app)
68+
db_path = get_db_path_from_config()
69+
if db_path:
70+
init_database(db_path)
71+
6272
print(f"Python is running in {FLASK_DEBUG} mode")
6373
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)

src/opengeodeweb_back/app_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
# Third party imports
66
# Local application imports
7-
from opengeodeweb_microservice.database.connection import get_database
87

9-
DATABASE_FILENAME = "project.db"
8+
DATABASE_FILENAME = "project.db" # Should be declared only once.
109

1110

1211
class Config(object):

src/opengeodeweb_back/utils_functions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ def generate_native_viewable_and_light_viewable_from_file(
249249

250250
data = geode_functions.load(geode_object, copied_full_path)
251251

252-
# Remplacer :
253-
# database.session.delete(temp_data_entry)
254-
# database.session.flush()
255-
# Par :
256252
session = get_session()
257253
if session:
258254
session.delete(temp_data_entry)

tests/conftest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def copy_data():
2828
print("Current working directory:", os.getcwd())
2929
print("Directory contents:", os.listdir("."))
3030

31-
init_database(app)
32-
# print(list(app.blueprints.keys()))
33-
# for rule in app.url_map.iter_rules():
34-
# print(f"Route: {rule.rule} -> {rule.endpoint}")
31+
init_database(db_path)
3532

3633

3734
@pytest.fixture

0 commit comments

Comments
 (0)