Server-Side Scripting/SQL Databases/Python (FastAPI)

routers/lesson9.py
"       return result

def country_exists(country): with sqlite3.connect(DATABASE) as connection: cursor = connection.cursor sql = """           SELECT EXISTS(                SELECT * FROM Countries                WHERE Country = ?) AS Count;        """ parameters = (country,) cursor.execute(sql, parameters) result = cursor.fetchone[0] return result

def insert_country(country, temperature): with sqlite3.connect(DATABASE) as connection: cursor = connection.cursor sql = """           INSERT INTO Countries (Country, Temperature)            VALUES(?, ?);        """ parameters = (country, temperature) cursor.execute(sql, parameters) connection.commit

def update_country(country, temperature): with sqlite3.connect(DATABASE) as connection: cursor = connection.cursor sql = """           UPDATE Countries            SET Temperature = ?            WHERE Country = ?;        """ parameters = (temperature, country) cursor.execute(sql, parameters) connection.commit

def delete_country(country): with sqlite3.connect(DATABASE) as connection: cursor = connection.cursor sql = """           DELETE FROM Countries            WHERE Country = ?;        """ parameters = (country, ) cursor.execute(sql, parameters) connection.commit

Try It
See ../../Routes and Templates/Python (FastAPI) to create a test environment.