Sindbad~EG File Manager

Current Path : /home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/
Upload File :
Current File : //home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/UserAttachments.py

from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
import json
from .. import engine

#engine = create_engine(app.config['DATABASE_URI'])
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
# engine = create_engine(app.config['DATABASE_URI'],pool_size=20, max_overflow=0)
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,max_overflow=100,pool_pre_ping=True,pool_recycle=3600)
# engine = create_engine(app.config['DATABASE_URI'], poolclass=None,pool_size=5000,max_overflow=100,pool_pre_ping=True,pool_recycle=3600)

class UserAttachments():
	def __init__(self):
		try:
			self.meta               = MetaData()
			self.user_attachments   = Table("user_attachments", self.meta, autoload_with=engine)
		   
		except Exception as e:
			print(e)

	def insert_image(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.user_attachments.insert(), data)
			conn.commit()
			pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
			return pk_id

	def get_image_by_user(self,attach_type_id,user_id):
		with engine.connect() as conn:
			stmt = text("select * from user_attachments where attach_type_id   = "+str(attach_type_id)+" and user_id   = "+str(user_id)+";")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
			

	def delete_image(self,attach_id,attach_type_id):
		with engine.connect() as conn:
			stmt = text("delete from user_attachments WHERE attach_id = "+str(attach_id)+" and attach_type_id ="+str(attach_type_id)+";")
			results = conn.execute(stmt)
			conn.commit()
			if results:
				return 'success'
			else :
				return 'fail'
	
	def get_user_attach(self,attach_id,attach_type_id):
		with engine.connect() as conn:
			stmt = text("select * from user_attachments where attach_id = "+str(attach_id)+" and attach_type_id = " +str(attach_type_id)+";")
			result = conn.execute(stmt).first()
			if result:
				return dict(result._mapping)
			else:
				return None	
			

	def count_ua_user_id(self,user_id):
		with engine.connect() as conn:
			stmt = text("SELECT COUNT(user_id) as user_id FROM user_attachments where user_id="+ str(user_id)  +";")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None
	
	def update_image(self,attach_type_id,data):
		with engine.connect() as conn:
			stmt = self.user_attachments.update().where(self.user_attachments.c.attach_id.in_([attach_type_id])).values(data)
			result = conn.execute(stmt)
			conn.commit()
			if result:
				return 'success'
			else :
				return 'fail'
			
	def check_fellowship_certificate(self,user_id,attach_type_id):
		with engine.connect() as conn:
			stmt = text("select * from user_attachments where user_id=:user_id and attach_type_id=:attach_type_id;")
			result = conn.execute(stmt.bindparams(user_id=user_id,attach_type_id=attach_type_id)).first()
			if result :
				return (dict(result._mapping))
			else:
				return None
				
	def update_confirm_date(self,user_id,attach_type_id):
		with engine.connect() as conn:
			stmt_1= text("set sql_safe_updates=0;")
			conn.execute(stmt_1)
			stmt = text("update  user_attachments set confirm_date=null WHERE user_id = "+str(user_id)+" and attach_type_id ="+str(attach_type_id)+";")
			results = conn.execute(stmt)
			conn.commit()
			if results:
				return 'success'
			else :
				return 'fail'

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists