Compare commits
No commits in common. "6a42e522f9eadacc1646d111a32d202b96d15341" and "79ca9f2e6f9873f2003636e059ed274c53fe1b28" have entirely different histories.
6a42e522f9
...
79ca9f2e6f
BIN
db/Model.mwb
BIN
db/Model.mwb
Binary file not shown.
@ -29,8 +29,9 @@ def create_new_book(book: Book):
|
|||||||
|
|
||||||
|
|
||||||
def update_book(book: Book):
|
def update_book(book: Book):
|
||||||
|
session = DatabaseManager.get_session()
|
||||||
try:
|
try:
|
||||||
with DatabaseManager.get_session() as session:
|
with 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)
|
||||||
|
|
||||||
@ -56,10 +57,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 occurred when saving book: {e}")
|
logger.error(f"An error occured when saving book: {e}")
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise DatabaseError(
|
raise DatabaseError(
|
||||||
"An error occurred when updating the book") from e
|
"An error occured when updating the book") from e
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["create_new_book", "update_book"]
|
__all__ = ["create_new_book", "update_book"]
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
|
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):
|
||||||
@ -129,12 +124,6 @@ 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,7 +2,6 @@ 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 *
|
||||||
@ -13,7 +12,6 @@ __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__,
|
||||||
|
@ -28,7 +28,6 @@ class Book(Base):
|
|||||||
|
|
||||||
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"]
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
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