1. PostgreSQL copy of all MySQL created and tested.\n 2. Purchase Orders and Sales Orders and stock level management added to MySQL, PostgreSQL, and server and front end code.
This commit is contained in:
BIN
helpers/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
helpers/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
helpers/__pycache__/helper_db_mysql.cpython-312.pyc
Normal file
BIN
helpers/__pycache__/helper_db_mysql.cpython-312.pyc
Normal file
Binary file not shown.
35
helpers/helper_db_mysql.py
Normal file
35
helpers/helper_db_mysql.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Helpers
|
||||
Feature: MySQL Database Helper
|
||||
|
||||
Notes: This architecture does not work with Flask-SQLAlchemy - db connection must be initialised with Flask app initialisation
|
||||
"""
|
||||
|
||||
# internal
|
||||
|
||||
# external
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
|
||||
class Helper_DB_MySQL(BaseModel):
|
||||
app: Flask
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
|
||||
def __init__(self, app):
|
||||
super().__init__(app=app)
|
||||
# self.app = app
|
||||
|
||||
def get_db_connection(self):
|
||||
db = SQLAlchemy()
|
||||
db.init_app(self.app)
|
||||
with self.app.app_context():
|
||||
db.create_all()
|
||||
db.engine.url = self.app.config.SQLALCHEMY_DATABASE_URI
|
||||
return db
|
||||
34
helpers/helper_db_postgresql.py
Normal file
34
helpers/helper_db_postgresql.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Helpers
|
||||
Feature: PostgreSQL Database Helper
|
||||
"""
|
||||
|
||||
# internal
|
||||
|
||||
# external
|
||||
import psycopg2
|
||||
# from psycopg2 import sql
|
||||
from pydantic import BaseModel
|
||||
from flask import Flask
|
||||
|
||||
class Helper_DB_PostgreSQL(BaseModel):
|
||||
|
||||
|
||||
app: Flask
|
||||
|
||||
def __init__(self, app):
|
||||
super().__init__(app=app)
|
||||
# self.app = app
|
||||
|
||||
def get_db_connection(self):
|
||||
return psycopg2.connect(
|
||||
dbname = self.app.config['DB_NAME'],
|
||||
user = self.app.config['DB_USER'],
|
||||
password = self.app.config['DB_PASSWORD'],
|
||||
host = self.app.config['DB_HOST'],
|
||||
port = self.app.config['DB_PORT']
|
||||
)
|
||||
Reference in New Issue
Block a user