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
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_pre_ping=True)
class CommitteeModel():
def __init__(self):
try:
self.meta = MetaData()
self.committee_member = Table("committee_member", self.meta,autoload_with=engine)
self.m_committee = Table("m_committee", self.meta,autoload_with=engine)
self.committee_communication = Table("committee_communication", self.meta,autoload_with=engine)
except Exception as e:
print(e)
def get_committee_members(self,society_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_committe_members",[society_id])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def get_particular_committee_id(self,society_id,committee_id):
with engine.connect() as conn:
stmt = text("select * FROM committee_member cm inner join users u on cm.user_id=u.user_id where u.society_id=:society_id and cm.committee_id=:committee_id ;")
result = conn.execute(stmt.bindparams(committee_id=committee_id,society_id=society_id)).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
return results
def get_committee_name(self,committee_id):
with engine.connect() as conn:
stmt = text("select * FROM m_committee where committee_id =:committee_id;")
result = conn.execute(stmt.bindparams(committee_id=committee_id)).first()
conn.close()
return result
def insert_communication(self,data):
with engine.connect() as conn:
result = conn.execute(self.committee_communication.insert(), data)
conn.commit()
pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
conn.close()
return pk_id
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists