db_functions.py
def insert(data):
    """ Connect to the PostgreSQL database server """
    conn = None
    cards = data["cards"]

    try:
        # read connection parameters
        params = config()

        # connect to the PostgreSQL server
        logger.info('Connecting to the PostgreSQL database...')
        conn = psycopg2.connect(**params)
        # create a cursor
        cur = conn.cursor()
        logger.info("updating cards in database...")
        for card in cards:
            sku_value = card["sku_value"]
            card_name = card["card_name"]
            available = card["available"]
            sql = """INSERT INTO gpus(sku_value,card_name,available)
            VALUES(%s,%s,%s)  ON CONFLICT (sku_value) DO UPDATE SET available = EXCLUDED.available"""
            # execute a statement
            logger.info("inserting card: %s in to database", str(card_name))
            cur.execute(sql, (sku_value, card_name, available))
            conn.commit()
        # close communication with the database
        cur.close()
        logger.info("cards updated in database")
    except (Exception, psycopg2.DatabaseError) as error:
        logger.error(error)
        raise HTTPException(status_code=500, detail=DATABASE_EXCEPTION)
    finally:
        if conn is not None:
            conn.close()
            logger.info('Database connection closed.')
 Connect to the PostgreSQL database server 
Connect to the PostgreSQL database server
Connect to the PostgreSQL database server
def insert(data):
    conn = None
    cards = data["cards"]
    try:
        params = config()
        logger.info('Connecting to the PostgreSQL database...')
        conn = psycopg2.connect(**params)
        cur = conn.cursor()
        logger.info("updating cards in database...")
        for card in cards:
            sku_value = card["sku_value"]
            card_name = card["card_name"]
            available = card["available"]
            sql = """INSERT INTO gpus(sku_value,card_name,available)
            VALUES(%s,%s,%s)  ON CONFLICT (sku_value) DO UPDATE SET available = EXCLUDED.available"""
            logger.info("inserting card: %s in to database", str(card_name))
            cur.execute(sql, (sku_value, card_name, available))
            conn.commit()
        cur.close()
        logger.info("cards updated in database")
    except (Exception, psycopg2.DatabaseError) as error:
        logger.error(error)
        raise HTTPException(status_code=500, detail=DATABASE_EXCEPTION)
    finally:
        if conn is not None:
            conn.close()
            logger.info('Database connection closed.')
def insert ( data ) : conn = None cards = data [ "cards" ] try : params = config ( ) logger . info ( 'Connecting to the PostgreSQL database...' ) conn = psycopg2 . connect ( ** params ) cur = conn . cursor ( ) logger . info ( "updating cards in database..." ) for card in cards : sku_value = card [ "sku_value" ] card_name = card [ "card_name" ] available = card [ "available" ] sql = """INSERT INTO gpus(sku_value,card_name,available)
            VALUES(%s,%s,%s)  ON CONFLICT (sku_value) DO UPDATE SET available = EXCLUDED.available""" logger . info ( "inserting card: %s in to database" , str ( card_name ) ) cur . execute ( sql , ( sku_value , card_name , available ) ) conn . commit ( ) cur . close ( ) logger . info ( "cards updated in database" ) except ( Exception , psycopg2 . DatabaseError ) as error : logger . error ( error ) raise HTTPException ( status_code = 500 , detail = DATABASE_EXCEPTION ) finally : if conn is not None : conn . close ( ) logger . info ( 'Database connection closed.' )
Connect to the PostgreSQL database server
Connect to the PostgreSQL database server
""" Connect to the PostgreSQL database server """ # read connection parameters # connect to the PostgreSQL server # create a cursor # execute a statement # close communication with the database
data