File size: 1,222 Bytes
58f6928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from data.database import DATABASE_PATH, get_connection, initialize_database
from data.seed_database import seed_books


def list_books() -> None:
    """Veritabanındaki bütün kitapları ekrana yazdırır."""

    with get_connection() as connection:
        books = connection.execute(
            """
            SELECT
                id,
                title,
                author,
                category,
                price,
                stock
            FROM books
            ORDER BY id
            """
        ).fetchall()

    print("\n" + "=" * 90)
    print("KİTAP LİSTESİ")
    print("=" * 90)

    for book in books:
        print(
            f"ID: {book['id']} | "
            f"Kitap: {book['title']} | "
            f"Yazar: {book['author']} | "
            f"Kategori: {book['category']} | "
            f"Fiyat: {book['price']:.2f} TL | "
            f"Stok: {book['stock']}"
        )

    print("=" * 90)
    print(f"Toplam kitap: {len(books)}")


def main() -> None:
    initialize_database()
    seed_books()
    list_books()

    print(f"\nVeritabanı dosyası: {DATABASE_PATH}")
    print("✅ Veritabanı testi başarıyla tamamlandı.")


if __name__ == "__main__":
    main()