NSS-Day-Cohort-58 / rare-python-server-striking-dragons

rare-python-server-striking-dragons created by GitHub Classroom
0 stars 0 forks source link

Created `create_category` function in category_requests.py #80

Open jsa-codes opened 2 years ago

jsa-codes commented 2 years ago

Created the following code:

def create_category(new_category):
    with sqlite3.connect("./db.sqlite3") as conn:

        conn.row_factory = sqlite3.Row
        db_cursor = conn.cursor()

        db_cursor.execute(
            """
        INSERT INTO CATEGORIES
          (label)
        VALUES
          ( ? );
          """,
            (new_category["label"]),
        )

        id = db_cursor.lastrowid

        new_category["id"] = id

    return new_category