Compare commits

..

No commits in common. "d242e4ff6860ebc05666157b5f6d17deebada8b1" and "98d39bba2e726e6ad3be21f91d3505dc7b8407d1" have entirely different histories.

10 changed files with 37 additions and 83 deletions

Binary file not shown.

0
src/__init__.py Normal file
View File

View File

@ -1,56 +1,14 @@
# import sys
# from PySide6.QtGui import QGuiApplication
# from PySide6.QtQml import QQmlApplicationEngine
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)
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
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'
# Create the engine
engine = create_engine(DATABASE_URI, echo=True)
# Create a configured session class
SessionLocal = sessionmaker(bind=engine)
# Create a session instance
session = SessionLocal()
new_author = Author(first_name="John", last_name="Doe")
session.add(new_author)
session.commit()
new_book = Book(
title="Sample Book",
description="A fascinating tale.",
year_published="2023",
isbn="1234567890123",
status='available',
author_id=new_author.id
)
session.add(new_book)
session.commit()
books = session.query(Book).all()
for book in books:
print(book.title, book.author.first_name)
session.close()
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)

View File

@ -1,7 +0,0 @@
from .author import Author
from .book_category import BookCategory
from .book import Book
from .book_category_link import BookCategoryLink
from .member import Member
from .librarian import Librarian
from .loan import Loan

View File

@ -1,7 +1,9 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint, func
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .book import Book
Base = declarative_base()
@ -9,7 +11,7 @@ class Author(Base):
__tablename__ = 'author'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -19,14 +19,14 @@ class Book(Base):
__tablename__ = 'book'
__table_args__ = (UniqueConstraint('isbn'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey('author.id'), nullable=False)
title = Column(String(100), nullable=False)
description = Column(Text, nullable=False)
year_published = Column(String(4), nullable=False)
isbn = Column(String(13), nullable=False, unique=True)
status = Column(Enum(BookStatusEnum), nullable=False, default=BookStatusEnum.available)
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
created_at = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
author = relationship('Author', backref='books')

View File

@ -1,4 +1,5 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
from .book import Book
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -9,10 +10,10 @@ class BookCategory(Base):
__tablename__ = 'book_category'
__table_args__ = (UniqueConstraint('name'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
parent_category_id = Column(Integer, ForeignKey('book_category.id'), nullable=True)
name = Column(String(100), nullable=False)
mature_content = Column(Integer, nullable=False, default=0)
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
parent_category = relationship('BookCategory', remote_side=[id])

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -21,12 +21,12 @@ class Librarian(Base):
__tablename__ = 'librarian'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
email = Column(String(100), nullable=False, unique=True)
phone = Column(String(20), nullable=False)
hire_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
hire_date = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
status = Column(Enum(LibrarianStatusEnum), nullable=False, default=LibrarianStatusEnum.active)
role = Column(Enum(LibrarianRoleEnum), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -22,16 +22,16 @@ class Loan(Base):
__tablename__ = 'loan'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
book_id = Column(Integer, ForeignKey('book.id'), nullable=False)
member_id = Column(Integer, ForeignKey('member.id'), nullable=False)
librarian_id = Column(Integer, ForeignKey('librarian.id'), nullable=False)
loan_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
loan_date = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
due_date = Column(TIMESTAMP, nullable=False)
return_date = Column(TIMESTAMP, nullable=True)
status = Column(Enum(LoanStatusEnum), nullable=False, default=LoanStatusEnum.borrowed)
overdue_fee = Column(Float, nullable=True)
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
book = relationship('Book', backref='loans')
member = relationship('Member', backref='loans')

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -14,11 +14,11 @@ class Member(Base):
__tablename__ = 'member'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
email = Column(String(100), nullable=False, unique=True)
phone = Column(String(20), nullable=True)
register_date = Column(TIMESTAMP, nullable=True, server_default=func.now())
register_date = Column(TIMESTAMP, nullable=True, default='CURRENT_TIMESTAMP()')
status = Column(Enum(MemberStatusEnum), nullable=True, default=MemberStatusEnum.active)
last_updated = Column(TIMESTAMP, nullable=True)