this repo has no description

.

+24 -2
+1 -1
db.py
··· 74 74 table = self.tables[table_name] 75 75 table.rows = (*table.rows, *rows) 76 76 77 - def UPDATE(self, table, set, pred): 77 + def UPDATE(self, table, set, pred=lambda _: True): 78 78 return Table( 79 79 table.name, [{**row, **set} if pred(row) else row for row in table.rows] 80 80 )
+23 -1
db_tests.py
··· 123 123 result = db.WHERE(table, lambda row: row["a"] % 2 == 0) 124 124 self.assertEqual(result.rows, ({"a": 2}, {"a": 4})) 125 125 126 - def test_update_returns_updated_table(self): 126 + def test_update_returns_updated_table_with_all_rows_modified(self): 127 + db = Database() 128 + rows = ( 129 + {"id": 1, "name": "Josh", "department_id": 1, "salary": 50000}, 130 + {"id": 2, "name": "Ruth", "department_id": 2, "salary": 60000}, 131 + {"id": 3, "name": "Greg", "department_id": 5, "salary": 70000}, 132 + {"id": 4, "name": "Pat", "department_id": 1, "salary": 80000}, 133 + ) 134 + table = Table("employee", rows) 135 + result = db.UPDATE(table, {"salary": 10}) 136 + self.assertEqual(result.name, table.name) 137 + self.assertEqual( 138 + result.rows, 139 + ( 140 + {"id": 1, "name": "Josh", "department_id": 1, "salary": 10}, 141 + {"id": 2, "name": "Ruth", "department_id": 2, "salary": 10}, 142 + {"id": 3, "name": "Greg", "department_id": 5, "salary": 10}, 143 + {"id": 4, "name": "Pat", "department_id": 1, "salary": 10}, 144 + ), 145 + ) 146 + self.assertEqual(table.rows[0]["salary"], 50000) 147 + 148 + def test_update_returns_updated_table_with_pred(self): 127 149 db = Database() 128 150 rows = ( 129 151 {"id": 1, "name": "Josh", "department_id": 1, "salary": 50000},