from db.run_sql import run_sql
from models.book import Book
from models.author import Author
import repositories.book_repository as book_repository
import repositories.author_repository as author_repository


def save(book):
    sql = "INSERT INTO books (title, genre, publisher, author_id) VALUES (%s, %s, %s, %s) RETURNING * "
    values = [book.title, book.genre, book.publisher, book.author.id]
    results = run_sql(sql, values)
    id = results[0]['id']
    book.id = id
    return book


def select(id):
    book = None
    sql = "SELECT * FROM books WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        author = author_repository
        book = Book(result['title'], result['genre'], result['publisher'], result['id'])
    return book
53900dfa55e76a5e5152f1a62d3526225ad90d46
<mask token>

<mask token>


def select(id):
    book = None
    sql = 'SELECT * FROM books WHERE id = %s'
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        author = author_repository
        book = Book(result['title'], result['genre'], result['publisher'],
            result['id'])
    return book

<mask token>


def save(book):
    sql = (
        'INSERT INTO books (title, genre, publisher, author_id) VALUES (%s, %s, %s, %s) RETURNING * '
        )
    values = [book.title, book.genre, book.publisher, book.author.id]
    results = run_sql(sql, values)
    id = results[0]['id']
    book.id = id
    return book


def select(id):
    book = None
    sql = 'SELECT * FROM books WHERE id = %s'
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        author = author_repository
        book = Book(result['title'], result['genre'], result['publisher'],
            result['id'])
    return book

from db.run_sql import run_sql
from models.book import Book
from models.author import Author
import repositories.book_repository as book_repository
import repositories.author_repository as author_repository


def save(book):
    sql = (
        'INSERT INTO books (title, genre, publisher, author_id) VALUES (%s, %s, %s, %s) RETURNING * '
        )
    values = [book.title, book.genre, book.publisher, book.author.id]
    results = run_sql(sql, values)
    id = results[0]['id']
    book.id = id
    return book


def select(id):
    book = None
    sql = 'SELECT * FROM books WHERE id = %s'
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        author = author_repository
        book = Book(result['title'], result['genre'], result['publisher'],
            result['id'])
    return book

from db.run_sql import run_sql
from models.book import Book
from models.author import Author
import repositories.book_repository as book_repository
import repositories.author_repository as author_repository


def save(book):
    sql = "INSERT INTO books (title, genre, publisher, author_id) VALUES (%s, %s, %s, %s) RETURNING * "
    values = [book.title, book.genre, book.publisher, book.author.id]
    results = run_sql(sql, values)
    id = results[0]['id']
    book.id = id
    return book


def select(id):
    book = None
    sql = "SELECT * FROM books WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        author = author_repository
        book = Book(result['title'], result['genre'], result['publisher'], result['id'])
    return book