Advertisement
Danila_lipatov

reqauest_db

May 6th, 2024
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. def get_last_change(table: str, executor=None) -> pd.DataFrame():       #TODO  add condition to check if table_audit exist
  2.     if executor is None:
  3.         executor: Executor = st.session_state['executor']
  4.     # query = f"SELECT * FROM _defaults._global_audit ORDER BY STAMP DESC LIMIT 5"
  5.     query_test = f"""SELECT EXISTS (
  6.    SELECT FROM
  7.        pg_tables
  8.    WHERE
  9.        schemaname = '{schema}' AND
  10.        tablename  = '{table}_audit'
  11.    );"""
  12.     if executor.execute(query_test)[0][0] == True:
  13.         sql = SqlCreatorAlpha(table=f'{table}_audit', schema=schema)
  14.         sql.select().order_by('STAMP', how='DESC').limit(5)
  15.         # df = pd.read_sql(query, conn)
  16.         df = executor.execute(sql).as_dataframe
  17.         return df
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement