def get_books_by_read_value(read):
    """ Get a list of books that have been read, or list of books that have not been read.
    :param read True for books that have been read, False for books that have not been read
    :returns all books with the read value.
    """
    query = Book.select().where(Book.read == read)
    return list(query)
def book_search(term):
    """ Searches the store for books whose author or title contain a search term.
    Makes partial matches, so a search for 'Row' will match a book with author='JK Rowling'; a book with title='Rowing For Dummies'
    :param term the search term
    :returns a list of books with author or title that match the search term.
    """
    query = Book.select().where((Book.title.contains(term)) | (Book.author.contains(term)))
    return list(query)
Example #3
0
def book_search(term):
    """ Searches the store for books whose author or title contain a search term. Case insensitive.
    Makes partial matches, so a search for 'row' will match a book with author='JK Rowling' and a book with title='Rowing For Dummies'
    :param term the search term
    :returns a list of books with author or title that match the search term. The list will be empty if there are no matches.
    """

    query = Book.select().where((fn.LOWER(Book.title).contains(term.lower())) |
                                (fn.LOWER(Book.author).contains(term.lower())))
    return list(query)
Example #4
0
    author01 = Author.create(name='H. G. Wells')
    book01 = {'title': 'A Máquina do tempo', 'author': author01}
    book02 = {'title': 'Guerra dos Mundos', 'author': author01}

    author02 = Author.create(name='Julio Verne')
    book03 = {'title': 'Volta ao mundo em 80 dias', 'author': author02}
    book04 = {'title': 'Vinte Mil Leguas Submarinas', 'author': author01}

    books = [book01, book02, book03, book04]

    Book.insert_many(books).execute()

    book = Book.get(Book.title == 'Volta ao mundo em 80 dias')
    print(book.title)

    books = Book.select().join(Author).where(Author.name == 'H. G. Wells')

    print(books.count())

    for book in books:
        print(book.title)

    author = Author.get(Author.name == 'Julio Verne')
    book = Book.get(Book.title == 'Vinte Mil Leguas Submarinas')

    book.author = author
    book.save()

    book = Book.get(Book.title == 'Guerra dos Mundos')
    book.delete_instance()
Example #5
0
def book_count():
    """ :returns the number of books in the store """

    return Book.select().count()
Example #6
0
def get_all_books():
    """ :returns entire book list """

    query = Book.select()
    return list(query)
 def get_all_books(self):
     return DatabaseManager.get_list(
         Book.select().where(Book.is_available == True))
 def search(self, keyword):
     return DatabaseManager.get_list(
         Book.select().where((Book.title.contains(keyword))
                             & (Book.is_available == True)))
def book_count():
    """ Counts the books in store.
    :returns the number of books .
    """
    return Book.select().count()
Example #10
0
 def __search_book(self, keyword: str):
     return Book.select().where((Book.title.contains(keyword))
                                & (Book.is_available == True))
Example #11
0
 def create(self, name, author, year, catalog_id):
     return Book.create(name=name, author=author, year=year, catalog_id=catalog_id, id=Book.select().count() + 1)