utils.py 945 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright © 2023 Ingram Micro Inc. All rights reserved.
  2. import time
  3. REPLICA_BASIC_TABLE = 'dj_replica_basicfieldsmodelref'
  4. REPLICA_EVENT_TABLE = 'dj_replica_event'
  5. REPLICA_TABLES = (REPLICA_BASIC_TABLE, REPLICA_EVENT_TABLE)
  6. def count_replica_rows(cursor, table):
  7. cursor.execute('SELECT COUNT(*) FROM {0};'.format(table))
  8. return cursor.fetchone()[0]
  9. def get_replica_all(cursor, table, columns=None, order_asc_by=None):
  10. select = ','.join(columns) if columns else '*'
  11. sql = 'SELECT {0} FROM {1}'.format(select, table)
  12. if order_asc_by:
  13. sql = '{0} ORDER BY {1} ASC;'.format(sql, order_asc_by)
  14. cursor.execute(sql)
  15. return cursor.fetchall()
  16. def get_replica_first(cursor, table, columns=None):
  17. select = ','.join(columns) if columns else '*'
  18. cursor.execute('SELECT {0} FROM {1} LIMIT 1;'.format(select, table))
  19. return cursor.fetchone()
  20. def transport_delay(delay=1):
  21. time.sleep(delay)