Compare commits
2 Commits
79ca9f2e6f
...
6a42e522f9
Author | SHA1 | Date | |
---|---|---|---|
6a42e522f9 | |||
ec55394d79 |
BIN
db/Model.mwb
BIN
db/Model.mwb
Binary file not shown.
@ -29,9 +29,8 @@ def create_new_book(book: Book):
|
|||||||
|
|
||||||
|
|
||||||
def update_book(book: Book):
|
def update_book(book: Book):
|
||||||
session = DatabaseManager.get_session()
|
|
||||||
try:
|
try:
|
||||||
with session:
|
with DatabaseManager.get_session() as session:
|
||||||
logger.debug(f"Updating book {book.title}")
|
logger.debug(f"Updating book {book.title}")
|
||||||
existing_book = session.query(Book).get(book.id)
|
existing_book = session.query(Book).get(book.id)
|
||||||
|
|
||||||
@ -57,10 +56,10 @@ def update_book(book: Book):
|
|||||||
raise DatabaseConnectionError(
|
raise DatabaseConnectionError(
|
||||||
"Connection with database interrupted") from e
|
"Connection with database interrupted") from e
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
logger.error(f"An error occured when saving book: {e}")
|
logger.error(f"An error occurred when saving book: {e}")
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise DatabaseError(
|
raise DatabaseError(
|
||||||
"An error occured when updating the book") from e
|
"An error occurred when updating the book") from e
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["create_new_book", "update_book"]
|
__all__ = ["create_new_book", "update_book"]
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
from typing import List, Dict
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
from xmlschema import XMLSchema
|
from xmlschema import XMLSchema
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from database.manager import DatabaseManager
|
from database.manager import DatabaseManager
|
||||||
from utils.errors.import_error.xsd_scheme_not_found import XsdSchemeNotFoundError
|
from utils.errors.import_error.xsd_scheme_not_found import XsdSchemeNotFoundError
|
||||||
from utils.errors.import_error.invalid_contents_error import InvalidContentsError
|
from utils.errors.import_error.invalid_contents_error import InvalidContentsError
|
||||||
from utils.errors.import_error.import_error import ImportError
|
from utils.errors.import_error.import_error import ImportError
|
||||||
|
from utils.config import UserConfig
|
||||||
from models import Book, Author, BookCategory
|
from models import Book, Author, BookCategory
|
||||||
from sqlalchemy.exc import IntegrityError
|
|
||||||
|
|
||||||
class BookImporter:
|
class BookImporter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -124,6 +129,12 @@ class BookImporter:
|
|||||||
categories=filtered_categories
|
categories=filtered_categories
|
||||||
)
|
)
|
||||||
session.add(book)
|
session.add(book)
|
||||||
|
user_config = UserConfig()
|
||||||
|
|
||||||
|
if user_config.simulate_slowdown:
|
||||||
|
self.logger.info("Simulating slowdown for 10 seconds")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
# Commit all changes
|
# Commit all changes
|
||||||
session.commit()
|
session.commit()
|
||||||
except e:
|
except e:
|
||||||
|
@ -2,6 +2,7 @@ from .author import *
|
|||||||
from .book import *
|
from .book import *
|
||||||
from .book_category import *
|
from .book_category import *
|
||||||
from .book_category_link import *
|
from .book_category_link import *
|
||||||
|
from .book_category_statistics import *
|
||||||
from .book_overview import *
|
from .book_overview import *
|
||||||
from .member import *
|
from .member import *
|
||||||
from .librarian import *
|
from .librarian import *
|
||||||
@ -12,6 +13,7 @@ __all__ = [
|
|||||||
*book.__all__,
|
*book.__all__,
|
||||||
*book_category.__all__,
|
*book_category.__all__,
|
||||||
*book_category_link.__all__,
|
*book_category_link.__all__,
|
||||||
|
*book_category_statistics.__all__,
|
||||||
*book_overview.__all__,
|
*book_overview.__all__,
|
||||||
*member.__all__,
|
*member.__all__,
|
||||||
*librarian.__all__,
|
*librarian.__all__,
|
||||||
|
@ -26,8 +26,9 @@ class Book(Base):
|
|||||||
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
|
|
||||||
author = relationship('Author', back_populates='books')
|
author = relationship('Author', back_populates='books')
|
||||||
categories = relationship('BookCategory',secondary='book_category_link',back_populates='books')
|
categories = relationship('BookCategory',secondary='book_category_link',back_populates='books')
|
||||||
|
book_category_statistics = relationship('BookCategoryStatistics', back_populates='book_category_statistics')
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Book", "BookStatusEnum"]
|
__all__ = ["Book", "BookStatusEnum"]
|
||||||
|
18
src/models/book_category_statistics.py
Normal file
18
src/models/book_category_statistics.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from sqlalchemy import Column, Integer, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
|
|
||||||
|
class BookCategoryStatistics(Base):
|
||||||
|
__tablename__ = 'book_category_statistics'
|
||||||
|
|
||||||
|
book_category_id = Column(Integer, ForeignKey('book_category.id', ondelete="cascade"), primary_key=True)
|
||||||
|
count = Column(Integer(unsigned=True), nullable=False, default=0)
|
||||||
|
|
||||||
|
category = relationship(
|
||||||
|
'BookCategory',
|
||||||
|
back_populates='book_category_statistics'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["BookCategoryStatistics"]
|
Loading…
x
Reference in New Issue
Block a user