def delete_customer(delete_name): '''delete a customer by id.''' try: with DB.atomic(): Customer.delete().where(Customer.name == delete_name).execute() result = f'Succesfully deleted {delete_name}' except IntegrityError: result = f'{delete_name} does not exist' return result
def test_bulk_add_customers_good(): # Clear database Customer.delete().where(Customer.customer_id) bulk_add_customers('data.csv') custs = Customer.select() assert custs.count() > 0
def del_all_records(): """ Deletes all records. Used only for testing purposes. :return: An empty customer table """ delete_alles = Customer.delete().where(Customer.name >= '') delete_alles.execute()
def delete_customer(customer_id): """Delete the customer""" # db.connect() # db.execute_sql('PRAGMA foreign_keys = ON;') LOGGER.info(f"Deleting the customer {customer_id}") query = Customer.delete().where(Customer.customer_id == customer_id) query.execute()
def delete_all_customers(): ''' This function will delete all customers from the sqlite3 database. ''' d_cust = Customer.delete() d_cust.execute(DATABASE) LOGGER.info(f'We will delete all customers...')
def delete_customer(customer_id): """ This function will delete a customer uisng the id field """ nrows = Customer.delete().where( Customer.customer_id == customer_id).execute() logger.info('%d row(s) deleted.', nrows)
def delete_customer(customer_id): '''delete a customer by id.''' try: with DB.atomic(): delete_query = Customer.delete().where(Customer.customer_id == customer_id) delete_query.execute() except IntegrityError: LOGGER.warning("Customer ID %s not found.", customer_id)
def setUp(self): """Defines starting test database used for function testing.""" self.starting_db = [(1, 'Bob', 'Bobbo', '12 Green St', '1112223344', '*****@*****.**', False, 85000), (2, 'Jane', 'Janeo', '1550 Red Rd', '1118675309', '*****@*****.**', True, 150000), (5, 'Wilson', 'Volleyball', '1 Castaway Island', '0000000000', '*****@*****.**', True, 0) ] database.init(TEST_DATABASE) database.connect() database.execute_sql('PRAGMA foreign_keys = ON') database.create_tables([Customer]) with database.transaction(): Customer.delete().execute() Customer.insert_many(self.starting_db, fields=[Customer.customer_id, Customer.name, Customer.lastname, Customer.home_address, Customer.phone_number, Customer.email_address, Customer.active_status, Customer.credit_limit ]).execute() database.close()
def delete_customer(customer_id): """ Deletes an existing customer from the database. A warning message is printed if the customer does not exist in the database. """ logging.debug('Attempting to delete customer: %s', customer_id) query = Customer.delete().where(Customer.customer_id == customer_id).execute() if query == 0: warnings.warn(f'User with customer_id={customer_id} does not exist in the database.' , UserWarning) else: logging.info('Customer: %s, successfully deleted from the database.', customer_id)
def tearDown(self): Customer.delete().execute() DB.close()
def tearDown(self): Customer.delete().execute() database.close()