[main] Testing in app.py
This commit is contained in:
parent
427cd25853
commit
75550c7f6f
69
src/app.py
69
src/app.py
@ -1,56 +1,39 @@
|
||||
# import sys
|
||||
# from PySide6.QtGui import QGuiApplication
|
||||
# from PySide6.QtQml import QQmlApplicationEngine
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# app = QGuiApplication(sys.argv)
|
||||
# engine = QQmlApplicationEngine()
|
||||
# engine.addImportPath(sys.path[0])
|
||||
# engine.loadFromModule("ui", "Main")
|
||||
# if not engine.rootObjects():
|
||||
# sys.exit(-1)
|
||||
# exit_code = app.exec()
|
||||
# del engine
|
||||
# sys.exit(exit_code)
|
||||
import sys
|
||||
from PySide6 import QtWidgets, QtCore
|
||||
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from ui.dashboard import LibraryDashboard
|
||||
|
||||
from models.book import Book, BookStatusEnum
|
||||
from models.author import Author
|
||||
|
||||
# Replace with your MySQL database credentials
|
||||
DATABASE_URI = 'mysql+mysqlconnector://username:password@localhost:3306/library'
|
||||
if __name__ == "__main__":
|
||||
app = QtWidgets.QApplication([])
|
||||
window = LibraryDashboard()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
|
||||
# Create the engine
|
||||
engine = create_engine(DATABASE_URI, echo=True)
|
||||
# from sqlalchemy import create_engine
|
||||
# from sqlalchemy.orm import sessionmaker
|
||||
|
||||
# Create a configured session class
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
# from models.book import Book, BookStatusEnum
|
||||
# from models.author import Author
|
||||
|
||||
# Create a session instance
|
||||
session = SessionLocal()
|
||||
# # Replace with your MySQL database credentials
|
||||
# DATABASE_URI = 'mysql+mysqlconnector://username:password@localhost:3306/library'
|
||||
|
||||
new_author = Author(first_name="John", last_name="Doe")
|
||||
# # Create the engine
|
||||
# engine = create_engine(DATABASE_URI)
|
||||
|
||||
session.add(new_author)
|
||||
session.commit()
|
||||
# from models.base import Base
|
||||
# Base.metadata.create_all(engine)
|
||||
|
||||
new_book = Book(
|
||||
title="Sample Book",
|
||||
description="A fascinating tale.",
|
||||
year_published="2023",
|
||||
isbn="1234567890123",
|
||||
status='available',
|
||||
author_id=new_author.id
|
||||
)
|
||||
# # Create a configured session class
|
||||
# SessionLocal = sessionmaker(bind=engine)
|
||||
|
||||
session.add(new_book)
|
||||
session.commit()
|
||||
# # Create a session instance
|
||||
# session = SessionLocal()
|
||||
|
||||
books = session.query(Book).all()
|
||||
for book in books:
|
||||
print(book.title, book.author.first_name)
|
||||
# books = session.query(Book).all()
|
||||
# for book in books:
|
||||
# print(book.title, book.author.first_name)
|
||||
|
||||
session.close()
|
||||
# session.close()
|
Loading…
x
Reference in New Issue
Block a user