the beginning of the idiots
This commit is contained in:
		
							
								
								
									
										23
									
								
								qwen/python/merchants_of_hope/database.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								qwen/python/merchants_of_hope/database.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
"""
 | 
			
		||||
Database initialization and session management
 | 
			
		||||
"""
 | 
			
		||||
from sqlalchemy import create_engine
 | 
			
		||||
from sqlalchemy.ext.declarative import declarative_base
 | 
			
		||||
from sqlalchemy.orm import sessionmaker
 | 
			
		||||
from .config.settings import settings
 | 
			
		||||
 | 
			
		||||
# Create database engine
 | 
			
		||||
engine = create_engine(
 | 
			
		||||
    settings.DATABASE_URL,
 | 
			
		||||
    connect_args={"check_same_thread": False} if settings.DATABASE_URL.startswith("sqlite") else {}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Create session factory
 | 
			
		||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
 | 
			
		||||
 | 
			
		||||
# Base class for models
 | 
			
		||||
Base = declarative_base()
 | 
			
		||||
 | 
			
		||||
def init_db():
 | 
			
		||||
    """Initialize the database with all tables"""
 | 
			
		||||
    Base.metadata.create_all(bind=engine)
 | 
			
		||||
		Reference in New Issue
	
	Block a user