Esempio n. 1
0
def book_list():
    query = (
        f"SELECT b.id, b.name as nameBook, w.name FROM {BOOKS.TABLE_NAME} as b, \
            {WRITERS.TABLE_NAME} as w WHERE b.writerId = w.id")
    books = get_data(query)
    pretty_print(books)
    print(Fore.GREEN, " Enter <key> comand ".center(30, "*"), Fore.RESET)
Esempio n. 2
0
def add_book():
    view_writers()
    autor_id = None
    while True:
        autor_id = input("Please enter autor ID: ")
        query = (f"SELECT id FROM {WRITERS.TABLE_NAME} WHERE id = {autor_id}")
        writers = get_data(query)

        if len(autor_id.strip()) > 0 and len(writers) > 0:
            break

    book_name = None
    book_description = None
    while True:
        book_name = input("Please enter book name: ")
        book_description = input("Please enter book description: ")

        if len(book_name.strip()) > 0 and len(book_description.strip()) > 0:
            break

    query = (
        f"INSERT INTO {BOOKS.TABLE_NAME} (name, description, writerId) VALUES ('{book_name}', \
            '{book_description}', {autor_id})")
    execute_command(query)

    print(" Saved ".center(30, "*"))
    print(Fore.GREEN, " Enter <key> comand ".center(30, "*"), Fore.RESET)
Esempio n. 3
0
def get_book_info():
    book_name = None
    while True:
        book_name = input("Enter book name, please: ")
        if len(book_name.strip()) > 0:
            break
    query = ("SELECT {0}.name as book, {0}.description, {1}.name as writer FROM {0}, {1}"
             " WHERE {0}.writerId = {1}.id AND {0}.name = '{2}'".format(BOOK_TABLE, WRITERS_TABLE, book_name))
    book_info = get_data(query)
    pretty_print(book_info)
Esempio n. 4
0
def add_book():
    book_name = None
    book_description = None
    author = None

    while True:
        book_name = input("Enter book name, please: ")
        book_description = input("Enter book description, please: ")
        author = input("Enter author's name, please: ")
        if len(book_name.strip()) > 0 and len(author.strip()) > 0:
            break
    query = ("SELECT id FROM {0} WHERE name = '{1}'".format(WRITERS_TABLE, author))
    author_id = get_data(query)

    if not author_id:
        add_writer(author)
        author_id = get_data(query)
    author_id = author_id[0]['id']

    query = ("INSERT INTO {} (name, description, writerId) VALUES ('{}', '{}', {})"
             .format(BOOK_TABLE, book_name, book_description, author_id))
    execute_command(query)
    print("Saved")
Esempio n. 5
0
def book_info():
    book_list()
    book_id = None

    while True:
        book_id = input("Please enter book ID: ")

        if len(book_id.strip()) > 0:
            break

    query = (
        f"SELECT b.name, b.description, w.name FROM {BOOKS.TABLE_NAME} as b, \
            {WRITERS.TABLE_NAME} as w WHERE b.id = {book_id} and b.writerId = w.id"
    )
    book_description = get_data(query)

    pretty_print(book_description)
    print(" Done ".center(30, "*"))
    print(Fore.GREEN, " Enter <key> comand ".center(30, "*"), Fore.RESET)
Esempio n. 6
0
def books_list():
    query = ("SELECT {0}.id, {0}.name as book, {0}.description,"
             " {1}.name as writer FROM {0}, {1} WHERE {0}.writerId = {1}.id".format(BOOK_TABLE, WRITERS_TABLE))
    books = get_data(query)
    pretty_print(books)
Esempio n. 7
0
def view_writers():
    query = ("SELECT * FROM %s" % TABLE_NAME)
    writers = get_data(query)
    pretty_print(writers)
    print(Fore.GREEN, " Enter <key> comand ".center(30, "*"), Fore.RESET)
Esempio n. 8
0
def view_writers():
    query = ("SELECT * FROM %s" % TABLE_NAME)
    writers = get_data(query)
    return writers
Esempio n. 9
0
def writers_count():
    query = ("SELECT count(*) as count FROM {0}".format(TABLE_NAME))
    writers_count = get_data(query)
    return writers_count[0]
def view_writers():
    query = ("SELECT * FROM %s" % TABLE_NAME)
    writers = get_data(query)
    pretty_print(writers)