|
|
@ -8,15 +8,6 @@ logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Database():
|
|
|
|
class Database():
|
|
|
|
|
|
|
|
|
|
|
|
TABLE_BOOKS="books"
|
|
|
|
|
|
|
|
COLUMN_TITLE="title"
|
|
|
|
|
|
|
|
COLUMN_AUTHOR="author_sort"
|
|
|
|
|
|
|
|
COLUMN_PATH="path"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TABLE_AUTHOR="authors"
|
|
|
|
|
|
|
|
COLUMN_NAME="name"
|
|
|
|
|
|
|
|
COLUMN_SORT="sort"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, filename):
|
|
|
|
def __init__(self, filename):
|
|
|
|
self.filename = filename
|
|
|
|
self.filename = filename
|
|
|
|
self.con = None
|
|
|
|
self.con = None
|
|
|
@ -40,24 +31,31 @@ class Database():
|
|
|
|
return result_list
|
|
|
|
return result_list
|
|
|
|
|
|
|
|
|
|
|
|
def select_books_by_title(self, query):
|
|
|
|
def select_books_by_title(self, query):
|
|
|
|
|
|
|
|
query = self.__format_query(query)
|
|
|
|
sql = f"""
|
|
|
|
sql = f"""
|
|
|
|
SELECT title, author_sort, path
|
|
|
|
SELECT title, author_sort, path FROM books
|
|
|
|
FROM books WHERE title LIKE '%{query}%';
|
|
|
|
WHERE title LIKE '{query}';
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return self._execute(sql, res.book_factory)
|
|
|
|
return self._execute(sql, res.book_factory)
|
|
|
|
|
|
|
|
|
|
|
|
def select_books_by_author(self, query):
|
|
|
|
def select_books_by_author(self, query):
|
|
|
|
|
|
|
|
query = self.__format_query(query)
|
|
|
|
sql = f"""
|
|
|
|
sql = f"""
|
|
|
|
SELECT title, author_sort, path FROM books
|
|
|
|
SELECT title, author_sort, path FROM books
|
|
|
|
WHERE books.author_sort LIKE
|
|
|
|
WHERE books.author_sort LIKE '%' ||
|
|
|
|
'%' || (SELECT sort FROM authors
|
|
|
|
(SELECT sort FROM authors
|
|
|
|
WHERE sort = '{query}') || '%';
|
|
|
|
WHERE sort = '{query}') || '%';
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return self._execute(sql, res.book_factory)
|
|
|
|
return self._execute(sql, res.book_factory)
|
|
|
|
|
|
|
|
|
|
|
|
def select_authors(self, query):
|
|
|
|
def select_authors(self, query):
|
|
|
|
|
|
|
|
query = self.__format_query(query)
|
|
|
|
sql = f"""
|
|
|
|
sql = f"""
|
|
|
|
SELECT name, sort FROM authors
|
|
|
|
SELECT name, sort FROM authors
|
|
|
|
WHERE name LIKE '%{query}%';
|
|
|
|
WHERE name LIKE '{query}';
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return self._execute(sql, res.author_factory)
|
|
|
|
return self._execute(sql, res.author_factory)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __format_query(self, query):
|
|
|
|
|
|
|
|
formatted_query = "%" + query.replace(" ", "%") + "%"
|
|
|
|
|
|
|
|
return formatted_query
|
|
|
|