Compare commits
2 Commits
4bec0dd32c
...
8b8462fd58
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b8462fd58 | |||
| 36bede42d9 |
@@ -1,4 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
import pandas as pd
|
||||||
|
import traceback
|
||||||
|
import json
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask import Flask, jsonify, request
|
from flask import Flask, jsonify, request
|
||||||
@@ -19,10 +22,6 @@ from server.auth import AuthManager
|
|||||||
from server.datasets import DatasetManager
|
from server.datasets import DatasetManager
|
||||||
from server.utils import get_request_filters
|
from server.utils import get_request_filters
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
import traceback
|
|
||||||
import json
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Env Variables
|
# Env Variables
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import pandas as pd
|
|||||||
from server.db.database import PostgresConnector
|
from server.db.database import PostgresConnector
|
||||||
from psycopg2.extras import Json
|
from psycopg2.extras import Json
|
||||||
from server.exceptions import NotAuthorisedException
|
from server.exceptions import NotAuthorisedException
|
||||||
from flask_jwt_extended import get_jwt_identity
|
|
||||||
|
|
||||||
class DatasetManager:
|
class DatasetManager:
|
||||||
def __init__(self, db: PostgresConnector):
|
def __init__(self, db: PostgresConnector):
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import pandas as pd
|
|
||||||
from psycopg2.extras import RealDictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
from psycopg2.extras import execute_batch, Json
|
from psycopg2.extras import execute_batch
|
||||||
|
|
||||||
|
from server.exceptions import DatabaseNotConfiguredException
|
||||||
|
|
||||||
|
|
||||||
class PostgresConnector:
|
class PostgresConnector:
|
||||||
@@ -11,13 +12,18 @@ class PostgresConnector:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.connection = psycopg2.connect(
|
|
||||||
host=os.getenv("POSTGRES_HOST", "localhost"),
|
try:
|
||||||
port=os.getenv("POSTGRES_PORT", 5432),
|
self.connection = psycopg2.connect(
|
||||||
user=os.getenv("POSTGRES_USER", "postgres"),
|
host=os.getenv("POSTGRES_HOST", "localhost"),
|
||||||
password=os.getenv("POSTGRES_PASSWORD", "postgres"),
|
port=os.getenv("POSTGRES_PORT", 5432),
|
||||||
database=os.getenv("POSTGRES_DB", "postgres"),
|
user=os.getenv("POSTGRES_USER", "postgres"),
|
||||||
)
|
password=os.getenv("POSTGRES_PASSWORD", "postgres"),
|
||||||
|
database=os.getenv("POSTGRES_DB", "postgres"),
|
||||||
|
)
|
||||||
|
except psycopg2.OperationalError as e:
|
||||||
|
raise DatabaseNotConfiguredException(f"Ensure database is up and running: {e}")
|
||||||
|
|
||||||
self.connection.autocommit = False
|
self.connection.autocommit = False
|
||||||
|
|
||||||
def execute(self, query, params=None, fetch=False) -> list:
|
def execute(self, query, params=None, fetch=False) -> list:
|
||||||
|
|||||||
@@ -2,4 +2,7 @@ class NotAuthorisedException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class NotExistentDatasetException(Exception):
|
class NotExistentDatasetException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class DatabaseNotConfiguredException(Exception):
|
||||||
pass
|
pass
|
||||||
Reference in New Issue
Block a user