Compare commits

..

3 Commits

10 changed files with 83 additions and 37 deletions

Binary file not shown.

View File

View File

@ -1,14 +1,56 @@
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)
# 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()

View File

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

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
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)
id = Column(Integer, primary_key=True, autoincrement=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, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
author = relationship('Author', backref='books')

View File

@ -1,5 +1,4 @@
from .book import Book
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -10,10 +9,10 @@ class BookCategory(Base):
__tablename__ = 'book_category'
__table_args__ = (UniqueConstraint('name'),)
id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, autoincrement=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, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
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
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
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)
id = Column(Integer, primary_key=True, autoincrement=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, default='CURRENT_TIMESTAMP()')
hire_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
status = Column(Enum(LibrarianStatusEnum), nullable=False, default=LibrarianStatusEnum.active)
role = Column(Enum(LibrarianRoleEnum), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())

View File

@ -1,6 +1,6 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
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)
id = Column(Integer, primary_key=True, autoincrement=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, default='CURRENT_TIMESTAMP()')
loan_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
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, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
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
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
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)
id = Column(Integer, primary_key=True, autoincrement=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, default='CURRENT_TIMESTAMP()')
register_date = Column(TIMESTAMP, nullable=True, server_default=func.now())
status = Column(Enum(MemberStatusEnum), nullable=True, default=MemberStatusEnum.active)
last_updated = Column(TIMESTAMP, nullable=True)