def get_previous_snapshot()

in purchase-function/src/inventory.py [0:0]


    def get_previous_snapshot(self, index=0):
        conn = self._get_db_connection()
        try:
          cursor = conn.cursor()
          cursor.execute('''
              SELECT timestamp, items, related_order_id FROM snapshots 
              ORDER BY id DESC LIMIT 1 OFFSET {}
          '''.format(index))
          result = cursor.fetchone()
          conn.close()
          return {
              'timestamp': result[0],
              'items': json.loads(result[1]),
              'related_order_id': result[2],
          }
          
        except sqlite3.Error as e:
         logger.info("conn is closed due to db exception")
         conn.close()