master
campi 3 years ago
parent dfb5ee5432
commit 1680444583

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

Loading…
Cancel
Save