# Path: entity/category.py
# class Category:
#     def __init__(self, id=None, name=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/image.py
# class Image:
#     def __init__(self, id=None, recipe_id=None, path=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/synonym.py
# class Synonym:
#     def __init__(self, id=None, recipe_id=None, name=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/tag.py
# class Tag:
#     def __init__(self, id=None, name='', synonym_of=None, synonyms=[]):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def find_synonyms(self, db):
#     def from_row(db, row, find_synonyms=True):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/url.py
# class Url:
#     def __init__(self, id=None, recipe_id=None, name='', url=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/user.py
# class User:
#     def __init__(self, id=None, name=None, pw_hash=None, salt=None, session=None):
#     def __str__(self):
#     def count_all(db):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def from_row(db, row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):


from entity import category as category_entity
from entity import image as image_entity
from entity import synonym as synonym_entity
from entity import tag as tag_entity
from entity import url as url_entity
from entity import user as user_entity
import os
            query = 'SELECT r.description, r.id, r.info, r.ingredients, ' \
                    'r.rating, r.serving_size, r.title, r.user_id ' \
                    'FROM recipes r, recipe_has_category rhc ' \
                    'WHERE rhc.recipe_id = r.id ' \
                    'AND rhc.category_id = ? ' \
                    'ORDER BY title COLLATE NOCASE ASC'
            params = [category.id]
        cursor = db.cursor()
        cursor.execute(query, params)
        result = []
        for row in cursor.fetchall():
            result.append(Recipe.from_row(db, row))
        return result

    @staticmethod
    def find_pk(db, id):
        """ Find entity by primary key aka row id in database. Returns found
        entity or None. """
        query = 'SELECT description, id, info, ingredients, rating, ' \
                'serving_size, title, user_id ' \
                'FROM recipes ' \
                'WHERE id = ?'
        params = [id]
        return Recipe.__generic_find(db, query, params)

    @staticmethod
    def find_random(db, num):
        """ Find random entities in database. Returns list of found
        entities ordered by name ascending."""
        query = 'SELECT description, id, info, ingredients, ' \

# Path: entity/category.py
# class Category:
#     def __init__(self, id=None, name=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/image.py
# class Image:
#     def __init__(self, id=None, recipe_id=None, path=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/synonym.py
# class Synonym:
#     def __init__(self, id=None, recipe_id=None, name=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/tag.py
# class Tag:
#     def __init__(self, id=None, name='', synonym_of=None, synonyms=[]):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def find_synonyms(self, db):
#     def from_row(db, row, find_synonyms=True):
#     def is_new(self):
#     def name_exists(db, name):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/url.py
# class Url:
#     def __init__(self, id=None, recipe_id=None, name='', url=''):
#     def __str__(self):
#     def delete(self, db):
#     def find_all(db):
#     def find_pk(db, id):
#     def find_recipe(db, recipe):
#     def from_row(row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):
# 
# Path: entity/user.py
# class User:
#     def __init__(self, id=None, name=None, pw_hash=None, salt=None, session=None):
#     def __str__(self):
#     def count_all(db):
#     def delete(self, db):
#     def find_all(db):
#     def find_name(db, name):
#     def find_pk(db, id):
#     def from_row(db, row):
#     def is_new(self):
#     def save(self, db):
#     def __generic_find(db, query, params):


# Path: entity/recipe.py
from entity import category as category_entity
from entity import image as image_entity
from entity import synonym as synonym_entity
from entity import tag as tag_entity
from entity import url as url_entity
from entity import user as user_entity
import os

            query = 'SELECT r.description, r.id, r.info, r.ingredients, ' \
                    'r.rating, r.serving_size, r.title, r.user_id ' \
                    'FROM recipes r, recipe_has_category rhc ' \
                    'WHERE rhc.recipe_id = r.id ' \
                    'AND rhc.category_id = ? ' \
                    'ORDER BY title COLLATE NOCASE ASC'
            params = [category.id]
        cursor = db.cursor()
        cursor.execute(query, params)
        result = []
        for row in cursor.fetchall():
            result.append(Recipe.from_row(db, row))
        return result

    @staticmethod
    def find_pk(db, id):
        """ Find entity by primary key aka row id in database. Returns found
        entity or None. """
        query = 'SELECT description, id, info, ingredients, rating, ' \
                'serving_size, title, user_id ' \
                'FROM recipes ' \
                'WHERE id = ?'
        params = [id]
        return Recipe.__generic_find(db, query, params)

    @staticmethod
    def find_random(db, num):
        """ Find random entities in database. Returns list of found
        entities ordered by name ascending."""
        query = 'SELECT description, id, info, ingredients, ' \

                'rating, serving_size, title, user_id ' \