def test_create_index(): Students_index = create_students_table(db) assert db.num_tables() == 1 assert db.get_tables_names() == ['Students_index'] students = db.get_table('Students_index') add_student(students, 111, Birthday="ry") add_student(students, 123, Birthday="ry") add_student(students, 145, Birthday="h") add_student(students, 1435, Birthday="tr") assert students.count() == 4 add_student(students, 151, Birthday="ry") students.delete_record(1_000_111) assert students.count() == 4 with pytest.raises(ValueError): students.delete_record(key=1_000_111) students.create_index('Birthday') add_student(students, 142, Birthday="ry") students.delete_record(key=1000142) students.update_record(key=1000151, values={"Birthday": "update2"}) results = students.query_table([SelectionCriteria('Birthday', '=', 'ry')]) assert len(results) == 1 students.update_record(key=1000145, values={"Birthday": "update1"}) add_student(students, 121, Birthday="ry") students.update_record(1_000_123, dict(First='Jane', Last='Doe')) results = students.query_table([SelectionCriteria('Birthday', '=', 'ry')]) assert len(results) == 2 assert results[0]['Birthday'] == 'ry' with pytest.raises(ValueError): students.update_record(key=1000333, values={"Birthday": "update2"}) students.delete_records([SelectionCriteria('Birthday', '=', 'ry')])
def test_50_students(new_db: DataBase) -> None: students = create_students_table(new_db, num_students=50) assert students.count() == 50 students.delete_record(1_000_001) students.delete_records([SelectionCriteria('ID', '=', 1_000_020)]) students.delete_records([SelectionCriteria('ID', '<', 1_000_003)]) students.delete_records([SelectionCriteria('ID', '>', 1_000_033)]) students.delete_records([ SelectionCriteria('ID', '>', 1_000_020), SelectionCriteria('ID', '<', 1_000_023) ]) assert students.count() == 28 students.update_record(1_000_009, dict(First='Jane', Last='Doe')) results = students.query_table([SelectionCriteria('First', '=', 'Jane')])
def test_simple() -> None: db = DataBase() assert db.num_tables() == 0 db.create_table('Students', [DBField('ID', int), DBField('First', str), DBField('Last', str), DBField('Birthday', dt.datetime) ], 'ID') assert db.num_tables() == 1 students = db.get_table('Students') for i in range(50): students.insert_record(dict( ID=1_000_000 + i, First=f'John{i}', Last=f'Doe{i}', Birthday=dt.datetime(2000, 2, 1) + dt.timedelta(days=i) )) students.delete_record(1_000_001) students.delete_records([SelectionCriteria('ID', '=', 1_000_020)]) students.delete_records([SelectionCriteria('ID', '<', 1_000_003)]) students.delete_records([SelectionCriteria('ID', '>', 1_000_033)]) students.delete_records([ SelectionCriteria('ID', '>', 1_000_020), SelectionCriteria('ID', '<', 1_000_023) ]) students.update_record(1_000_009, dict(First='Jane', Last='Doe')) assert students.count() == 28 results = students.query_table([SelectionCriteria('First', '=', 'Jane')]) assert len(results) == 1 assert results[0]['First'] == 'Jane' with pytest.raises(ValueError): # record already exists students.insert_record(dict( ID=1_000_010, First='John', Last='Doe', Birthday=dt.datetime(2000, 2, 1) + dt.timedelta(days=i) )) with pytest.raises(ValueError): students.delete_record(key=1_000_000)
}) library.insert_record({ 'name': 'MMOOOOOOOOOOOOOOOOONN', 'books': ['kkk', 'jiiiil'], 'address': 'eeedcdsv' }) library.insert_record({ 'name': 'bboooooooooooooooob', 'books': ['kkk', 'jiiiil'], 'address': 'eeedcdsv' }) library.insert_record({ 'name': 'pppppppppppppppppppppppokkkkkkk', 'books': ['kkk', 'jiiiil'], 'address': 'eeedcdsv' }) book = db.get_table('book') book.insert_record({ 'id': 56, 'name': 'oooo', 'writer': 'hjjjjjjjj', 'pages': 300 }) book.insert_record({'id': 44, 'name': 'ttt', 'writer': 'ggg', 'pages': 300}) book.insert_record({'id': 10, 'name': 'ttt', 'writer': 'ggg', 'pages': 138}) library.delete_record('MMNN') print(book.query_table([SelectionCriteria('pages', '=', 300)])) book.delete_records([SelectionCriteria('pages', '=', 300)]) #print(library.query_table([SelectionCriteria('books', '=', ['kkk', 'jiiiil']), SelectionCriteria('address', '=', 'eeedcdsv')]))