def ufile_create(db, page_id, file): cond = "WHERE Id == '{}'".format(page_id) obj = {'UFile': file} halt.update(db, 'Pages', obj, cond) obj['Pages'] = json.dumps([page_id]) halt.insert(db, 'UFiles', obj, mash=False)
def test_update_columns(self): data = {'Name': 'bob', 'Password': '******', 'random': 15} insert(self.db, 'Test', data, mash=True) new_data = {'Name': 'tom', 'random2': 15} update(self.db, 'Test', new_data, mash=False, cond="where Name == 'bob'") assert [('tom', 'pass', '{"random": 15}')] == get_all_data(self.db)
def page_update(db, profile, book, program, specific, loose): rowid = page_rowid_get(db, profile, book, program, specific, loose) if rowid: to_update = _page_save(profile, book, program, specific, loose) cond = "WHERE Id == {}".format(rowid) halt.update(db, 'Pages', to_update, cond=cond, mash=False) return True return False
def hotkey_update(db, profile, book, hotkey): assert type(hotkey) == list if hotkey in hotkey_get_all(db, profile): to_update = {'Profile': profile, 'Book': book, 'Hotkey': hotkey} cond = "WHERE Profile=='{}' AND Book=='{}'".format(profile, book) halt.update(db, 'Hotkeys', to_update, cond=cond) return True return False
def profile_set_active(db, profile): '''Sets the given profile as being active''' # Remove the previous active cond = "where Active == 1" halt.update(db, 'Profiles', {'Active': False}, cond) # Update the new cond = "where Name == '{0}'".format(profile) halt.update(db, 'Profiles', {'Active': True}, cond)
def book_update(db, book, profile, to_update): ''' Required a dict that will update columns or mash return False if book doesn't exist return True if update succesful ''' if not book_get(db, profile, book): return False cond = "where Book == '{0}' and Profile == '{1}'".format(book, profile) halt.update(db, 'Books', to_update, cond, mash=True) return True
def profile_update(db, profile, data): ''' Required a dict that will update columns or mash return False if profile doesn't exist return True if update succesful ''' if not profile_get(db, profile): return False cond = "WHERE Name == '{}'".format(profile) halt.update(db, 'Profiles', data, cond=cond, mash=True) return True
def page_update_from_id(db, rowid, data): ''' Required a dict that will update columns or mash return False if page doesn't exist return True if update succesful ''' if not page_get(db, rowid): return False update = _update(dict(data)) cond = "WHERE Id == {}".format(rowid) halt.update(db, 'Pages', update, cond=cond, mash=True) return True
def test_update_with_mash_and_columns(self): # First test when NOTHING in the MashConfig column data = {'Name': 'bob', 'Password': '******'} insert(self.db, 'Test', data, mash=False) new_data = {'Name': 'tom', 'r': 1, 'r2': 2} update(self.db, 'Test', new_data, mash=True, cond="where Name == 'bob'") results = get_all_data(self.db) assert results[0][:2] == ('tom', 'pass') dict_cmp({"r": 1, "r2": 2}, objectify(results[0][2])) # Now test with something existing in the mashconfig column new_data = {'Name': 'peter', 'r': 10, 'r3': 30} update(self.db, 'Test', new_data, mash=True, cond="where Name == 'tom'") results = get_all_data(self.db) assert results[0][:2] == ('peter', 'pass') dict_cmp({"r": 10, "r2": 2, "r3": 30}, objectify(results[0][2]))