# Databases

import sqlite3

# Let's create a database and table for our weather data

# 1. Connect to the database
# Will create a database file if it doesn't exist,
# or open one if it does exist
con = sqlite3.connect('weather.db')
# we will store multiple tables of different 
# weather information in weather.db

# 2. Make a 'cursor'. This is what we use as our link to
# the database so we can execute SQL query statements.
cur = con.cursor()

# 3. Do your work on the database below.

# Here we can execute SQL database queries
# The first thing we have to do is create a database table
# to hold our precipitation data.

# We create a new table using the 'CREATE TABLE' SQL statement

# every query must be written out and then 'executed'
# We can only create one table named precipitation in weather.db
# so it will give an error if we run this query more than once
cur.execute(
    """CREATE TABLE precipitation (
    city TEXT,
    snow REAL,
    total INTEGER,
    days INTEGER)""")

# Since we want to be careful that we don't run queries like
# this when we don't need to, we should put this all in
# a function and call it when needed
# Let's do that in another file

# 4. when done executing queries...
# 'Commit' your changes to the database through the connection,
# no the cursor
con.commit()

# Close the cursor
cur.close()
# Close the connection
con.close()
