Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
import json
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_fk = create_engine(app.config['DATABASE_URI_FK'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class FoodSessionModel():
def __init__(self):
try:
self.meta = MetaData()
self.fc_sessions = Table("fc_sessions", self.meta, autoload_with=engine_fk)
self.fc_users = Table("fc_users", self.meta, autoload_with=engine_fk)
except Exception as e:
print(e)
def getfcConf(self,conf_id,conf_key,current_dt) :
with engine.connect() as conn:
stmt = text("select * from conference where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' and '"+current_dt+"' between conf_start_time and conf_end_time ;")
# stmt = text("select * from conference where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' ;")
result = conn.execute(stmt)
result = result.fetchone()
return dict(result._mapping) if result else None
# get conf data start
def getFcConfData(self,conf_id,conf_key) :
with engine.connect() as conn:
stmt = text("select * from conference where conf_id ="+str(conf_id)+" and conf_key = '"+conf_key+"';")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# get conf data end
def insert_fcbodata_and_getdata(self,data,conf_id,conf_key):
with engine_fk.connect() as conn:
result = conn.execute(self.fc_sessions.insert(), data)
conn.commit()
stmt = text("SELECT f.session_id,f.session_name,f.session_key,f.start_time,f.end_time,f.is_active from fc_sessions f where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def getFCBOSessionData(self,conf_id,conf_key):
with engine_fk.connect() as conn:
stmt = text("SELECT f.session_id,f.session_name,f.session_key,f.start_time,f.end_time,f.is_active from fc_sessions f where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def edit_fcbo(self,conf_id,session_id):
with engine_fk.connect() as conn:
stmt = text("select * from fc_sessions where conf_id = "+str(conf_id)+" and session_id = "+session_id+" ;")
result = conn.execute(stmt)
result = result.fetchone()
return dict(result._mapping) if result else None
def update_fcbo_and_getdata(self,data_for_update,session_id,conf_id,conf_key):
with engine_fk.connect() as conn:
stmt = self.fc_sessions.update().where(self.fc_sessions.c.session_id.in_([session_id])).values(data_for_update)
conn.execute(stmt)
conn.commit()
stmt_2 = text("SELECT f.session_id,f.session_name,f.session_key,f.start_time,f.end_time,f.is_active from fc_sessions f where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' ;")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def delete_fcbo_session_index(self,session_id):
with engine_fk.connect() as conn:
stmt = self.fc_sessions.delete().where(self.fc_sessions.c.session_id.in_([session_id]))
conn.execute(stmt)
conn.commit()
stmt_2 = text("SELECT f.session_id,f.session_name,f.session_key,f.start_time,f.end_time,f.is_active from fc_sessions f ;")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def getDataByUsername(self,user_name):
with engine_fk.connect() as conn:
stmt = text("select * from fc_users where user_name = '"+user_name+"' ;")
result = conn.execute(stmt)
result = result.fetchone()
return dict(result._mapping) if result else None
def updateFCLoginTime(self,fc_user_id,current_dt):
with engine_fk.connect() as conn:
stmt = text("update fc_users set login_at = '"+current_dt+"' where fc_user_id = "+str(fc_user_id)+" ;")
result = conn.execute(stmt)
conn.commit()
return "login time updated."
def getFcsessionData(self,conf_id,conf_key) :
with engine_fk.connect() as conn:
stmt = text("select * from fc_sessions where conf_id ="+str(conf_id)+" and conf_key = '"+conf_key+"' ;")
result_2 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result_2] if result_2 else None
if results :
return results
else:
return None
def insert_food_session(self,session_insert_stmt):
with engine_fk.connect() as conn:
stmt = text(session_insert_stmt)
result = conn.execute(stmt)
conn.commit()
return result
# Delete function in Food session
# get conf data end
def delete_fcbodata_and_getdata(self,conf_id,session_id):
with engine_fk.connect() as conn:
stmt_1 = text("delete from fc_sessions where conf_id = "+str(conf_id)+" and session_id= "+str(session_id)+";")
result = conn.execute(stmt_1)
conn.commit()
stmt = text("select * from fc_sessions where conf_id = "+str(conf_id)+" and deleted_at is null ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists