22 lines
		
	
	
	
		
			722 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
	
		
			722 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os
 | |
| from flask_sqlalchemy import SQLAlchemy
 | |
| from dotenv import load_dotenv
 | |
| from urllib.parse import quote_plus
 | |
| 
 | |
| load_dotenv()
 | |
| 
 | |
| PG_USER = quote_plus(os.getenv("PG_USER", "postgres"))
 | |
| PG_PASSWORD = quote_plus(os.getenv("PG_PASSWORD", "postgres"))
 | |
| PG_HOST = os.getenv("PG_HOST", "localhost")
 | |
| PG_PORT = os.getenv("PG_PORT", "5432")
 | |
| PG_DATABASE = os.getenv("PG_DATABASE", "rideaware")
 | |
| 
 | |
| DATABASE_URI = f"postgresql+psycopg2://{PG_USER}:{PG_PASSWORD}@{PG_HOST}:{PG_PORT}/{PG_DATABASE}"
 | |
| 
 | |
| db = SQLAlchemy()
 | |
| 
 | |
| def init_db(app):
 | |
|     """Initialize the SQLAlchemy app with the configuration."""
 | |
|     app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
 | |
|     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
 | |
|     db.init_app(app)
 | 
