Skip to content

Commit 8aa4748

Browse files
committed
gitgnore added
requirements.in added config added app.config and conftest added temporarily connection to database model of database pyproject.toml READEME.md added requirements.txt added
1 parent 36ad0a7 commit 8aa4748

15 files changed

Lines changed: 210 additions & 22 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.pytest_cache
2+
venv
3+
__pycache__
4+
node_modules
5+
.mypy_cache
6+
*.egg-info

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
## Introduction
2121

22-
OpenGeodeWeb-Microservice is a dedicated service that manages the database logic extracted from the OpenGeodeWeb-Back (OGWB) project. It provides a REST API for managing geological data and associated metadata.
22+
Database model and ORM layer for the OpenGeodeWeb ecosystem.
2323

2424
## Changelog
2525

pyproject.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,21 @@ name = "OpenGeodeWeb-Microservice"
77
version = "1.0.0"
88
dynamic = ["dependencies"]
99
authors = [{ name = "Geode-solutions", email = "team-web@geode-solutions.com" }]
10-
description = "Microservice Python pour la gestion des données et de la base de données de l'écosystème OpenGeodeWeb"
10+
description = "Database model and ORM layer for OpenGeodeWeb ecosystem"
1111
readme = "README.md"
1212
requires-python = ">=3.9, <3.13"
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
1515
"License :: OSI Approved :: MIT License",
1616
"Operating System :: OS Independent",
17-
"Framework :: Flask",
18-
"Topic :: Database",
19-
"Topic :: Scientific/Engineering",
2017
]
2118

2219
[project.urls]
2320
"Homepage" = "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice"
2421
"Bug Tracker" = "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice/issues"
25-
"Repository" = "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice.git"
2622

2723
[tool.setuptools.dynamic]
2824
dependencies = { file = ["requirements.txt"] }
2925

3026
[tool.setuptools.packages.find]
3127
where = ["src"]
32-
33-
[tool.setuptools.package-data]
34-
"ogwm" = ["*.json"]
35-
"ogwm.routes" = ["*.json"]
36-
"ogwm.models" = ["*.json"]

requirements.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
# Flask et extensions
2-
Flask[async]==3.0.3
3-
Flask-Cors==6.0.1
4-
Flask-SQLAlchemy==3.1.1
5-
werkzeug==3.0.3
6-
7-
# Base de données et validation
8-
fastjsonschema==2.16.2
9-
10-
# Utilitaires
11-
python-dotenv==1.0.0
1+
SQLAlchemy>=2.0.0
2+
Flask-SQLAlchemy>=3.1.1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# # Standard library imports
2+
# import os
3+
# import time
4+
5+
# # Third party imports
6+
# # Local application imports
7+
# from .database import DATABASE_FILENAME
8+
9+
10+
# class Config(object):
11+
# FLASK_DEBUG = os.environ.get("FLASK_DEBUG", default=False)
12+
# DEFAULT_HOST = "localhost"
13+
# DEFAULT_PORT = "5000"
14+
# CORS_HEADERS = "Content-Type"
15+
# UPLOAD_FOLDER = "./uploads"
16+
# REQUEST_COUNTER = 0
17+
# LAST_REQUEST_TIME = time.time()
18+
# LAST_PING_TIME = time.time()
19+
# SQLALCHEMY_TRACK_MODIFICATIONS = False
20+
21+
22+
# class ProdConfig(Config):
23+
# DATA_FOLDER_PATH = "/data"
24+
# SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.abspath(
25+
# os.path.join(DATA_FOLDER_PATH, DATABASE_FILENAME)
26+
# )}"
27+
28+
29+
# class DevConfig(Config):
30+
# SSL = None
31+
# ORIGINS = "*"
32+
# MINUTES_BEFORE_TIMEOUT = "1"
33+
# SECONDS_BETWEEN_SHUTDOWNS = "10"
34+
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
35+
# DATA_FOLDER_PATH = os.path.join(BASE_DIR, "data")
36+
# SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.join(
37+
# BASE_DIR, DATA_FOLDER_PATH, DATABASE_FILENAME
38+
# )}"

requirements.in renamed to src/opengeodeweb_microservice/database/__init__.py

File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Database connection management"""
2+
3+
from typing import Optional
4+
from flask import Flask
5+
from flask_sqlalchemy import SQLAlchemy
6+
7+
from src.opengeodeweb_microservice.microservice.base import Base
8+
9+
10+
class DatabaseConnection:
11+
12+
def __init__(self, database_filename: str = "project.db"):
13+
self.database_filename = database_filename
14+
self.database: Optional[SQLAlchemy] = None
15+
16+
def init_app(self, app: Flask) -> SQLAlchemy:
17+
if self.database is None:
18+
self.database = SQLAlchemy(model_class=Base)
19+
20+
self.database.init_app(app)
21+
22+
with app.app_context():
23+
self.database.create_all()
24+
25+
return self.database
26+
27+
def get_database(self) -> Optional[SQLAlchemy]:
28+
return self.database
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Optional
2+
from flask import Flask
3+
from flask_sqlalchemy import SQLAlchemy
4+
5+
from src.opengeodeweb_microservice.database.connection import DatabaseConnection
6+
7+
# Global database instance
8+
_database_connection = DatabaseConnection()
9+
10+
11+
def init_database(app: Flask, database_filename: str = "project.db") -> SQLAlchemy:
12+
global _database_connection
13+
_database_connection.database_filename = database_filename
14+
return _database_connection.init_app(app)
15+
16+
17+
def get_session() -> Optional[SQLAlchemy]:
18+
return _database_connection.get_database()
19+
20+
21+
def get_database_connection() -> DatabaseConnection:
22+
return _database_connection

src/opengeodeweb_microservice/microservice/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)