Ejemplo n.º 1
0
    except peewee.OperationalError:
        print('Book table already exists')

    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()
 def get_book(self, book_id):
     return Book.get((Book.book_id == book_id)
                     & (Book.is_available == True))
 def get_book_by_rfid(self, rfid):
     return Book.get((Book.rfid == rfid) & (Book.is_available == True))
Ejemplo n.º 4
0
}

book_4 = {
    'title': 'Vinte Mil Leguas Submarinas',
    'author': author_2,
}

books = [book_1, book_2, book_3, book_4]

#Book.create()
# Inserimos os quatro livros na tabela 'Book'
Book.insert_many(books).execute()

#####################################################################
# Consultando dados no banco
book = Book.get(Book.title == "Volta ao Mundo em 80 Dias").get()
print "btitle:", book.title

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

# Exibe a quantidade de registros que corresponde a nossa pesquisa
print books.count()

for book in books:
    print "btitle:", book.title

####################################################################
# Alterando dados no banco
new_author = Author.get(Author.name == 'Julio Verne')
book = Book.get(Book.title=="Vinte Mil Leguas Submarinas")