예제 #1
0
def main():

    # CREATE
    create_items(mock.items())
    create_item('beer', price=3.0, quantity=15)
    # if we try to re-create an object we get an ItemAlreadyStored exception
    # create_item('beer', price=2.0, quantity=10)

    # READ
    print('READ items')
    print(read_items())
    # if we try to read an object not stored we get an ItemNotStored exception
    # print('READ chocolate')
    # print(read_item('chocolate'))
    print('READ bread')
    print(read_item('bread'))

    # UPDATE
    print('UPDATE bread')
    update_item('bread', price=2.0, quantity=30)
    print(read_item('bread'))
    # if we try to update an object not stored we get an ItemNotStored exception
    # print('UPDATE chocolate')
    # update_item('chocolate', price=10.0, quantity=20)

    # DELETE
    print('DELETE beer')
    delete_item('beer')
    # if we try to delete an object not stored we get an ItemNotStored exception
    # print('DELETE chocolate')
    # delete_item('chocolate')

    print('READ items')
    print(read_items())
예제 #2
0
def main():

    conn = connect_to_db()

    table_name = "items"
    create_table(conn, table_name)

    # CREATE
    insert_many(conn, items=mock.items(), table_name=table_name)
    insert_one(conn, "beer", price=2.0, quantity=5, table_name=table_name)
    # if we try to insert an object already stored we get an ItemAlreadyStored
    # exception
    # insert_one(conn, 'beer', 2.0, 5, table_name=table_name)

    # READ
    print("SELECT milk")
    print(select_one(conn, "milk", table_name=table_name))
    print("SELECT all")
    print(select_all(conn, table_name=table_name))
    # if we try to select an object not stored we get an ItemNotStored exception
    # print(select_one(conn, 'pizza', table_name=table_name))

    # UPDATE
    print("UPDATE bread, SELECT bread")
    update_one(conn, "bread", price=1.5, quantity=5, table_name=table_name)
    print(select_one(conn, "bread", table_name=table_name))
    # if we try to update an object not stored we get an ItemNotStored exception
    # print('UPDATE pizza')
    # update_one(conn, 'pizza', 9.5, 5, table_name=table_name)

    # DELETE
    print("DELETE beer, SELECT all")
    delete_one(conn, "beer", table_name=table_name)
    print(select_all(conn, table_name=table_name))
예제 #3
0
def main():

    table_name = "items"
    conn = connect_to_db()  # in-memory database
    # conn = connect_to_db(DB_name)

    create_table(conn, table_name)

    # CREATE
    insert_many(conn, mock.items(), table_name="items")
    insert_one(conn, "beer", price=2.0, quantity=5, table_name="items")
    # if we try to insert an object already stored we get an ItemAlreadyStored
    # exception
    # insert_one(conn, 'milk', price=1.0, quantity=3, table_name='items')

    # READ
    print("SELECT milk")
    print(select_one(conn, "milk", table_name="items"))
    print("SELECT all")
    print(select_all(conn, table_name="items"))
    # if we try to select an object not stored we get an ItemNotStored exception
    # print(select_one(conn, 'pizza', table_name='items'))

    # conn.close()  # the decorator @connect will reopen the connection

    # UPDATE
    print("UPDATE bread, SELECT bread")
    update_one(conn, "bread", price=1.5, quantity=5, table_name="items")
    print(select_one(conn, "bread", table_name="items"))
    # if we try to update an object not stored we get an ItemNotStored exception
    # print('UPDATE pizza')
    # update_one(conn, 'pizza', price=1.5, quantity=5, table_name='items')

    # DELETE
    print("DELETE beer, SELECT all")
    delete_one(conn, "beer", table_name="items")
    print(select_all(conn, table_name="items"))
    # if we try to delete an object not stored we get an ItemNotStored exception
    # print('DELETE fish')
    # delete_one(conn, 'fish', table_name='items')

    # save (commit) the changes
    # conn.commit()

    # close connection
    conn.close()
예제 #4
0
        old_item_type = self.model.item_type
        self.model.item_type = new_item_type
        self.view.display_change_item_type(old_item_type, new_item_type)

    def delete_item(self, name):
        item_type = self.model.item_type
        try:
            self.model.delete_item(name)
            self.view.display_item_deletion(name)
        except mvc_exc.ItemNotStored as e:
            self.view.display_item_not_yet_stored_error(name, item_type, e)


if __name__ == '__main__':

    myitems = mock.items()

    c = Controller(ModelBasic(myitems), View())
    # c = Controller(ModelSQLite(myitems), View())
    # c = Controller(ModelDataset(myitems), View())

    c.show_items()
    c.show_items(bullet_points=True)
    c.show_item('chocolate')
    c.show_item('bread')

    c.insert_item('bread', price=1.0, quantity=5)
    c.insert_item('chocolate', price=2.0, quantity=10)
    c.show_item('chocolate')

    c.update_item('milk', price=1.2, quantity=20)