# Path: data/search_rows.py
# def search_rows(select_clause, where_clause, order_by_clause, **kwargs):
#     """Fetch rows.
# 
#     Parameters
#     ----------
#     order_by_clause
#     select_clause
#     where_clause
# 
#     Returns
#     -------
#     row_list
#     """
#     try:
#         row_list = select_clause.where(where_clause).order_by(
#             order_by_clause).dicts()
#     except:
#         raise
# 
#     return row_list
# 
# Path: logic/reserved/reserved.py
# class Reserved(BaseModel):
#     """ORM for a reserved name."""
#     import datetime
#     id = pwe.PrimaryKeyField()
#     name = pwe.CharField(default=u'', index=True, unique=True)
#     primary_package = pwe.CharField(default=u'')
#     created_timestamp = pwe.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         db_table = 'reserved'
# 
#     @validate('Reserved', 'name')
#     def validate_name(self):
#         if not self.name:
#             raise AssertionError('Name must be given.')


import re
import peewee as pwe
from data.search_rows import search_rows
from logic.reserved.reserved import Reserved




def search_reserveds(search_text, **kwargs):
    """Search the Reserved table."""
    is_first = True
    where_clause = None
    if search_text:
        search_values = re.sub('[~`%&-+=]', '', search_text).split()
        for s in search_values:
            s_ = u'%'+s+u'%'
            if is_first:
                where_clause = (Reserved.name ** s_)
                is_first = False
            else:
                where_clause = where_clause & \
                    (Reserved.name ** s_)
    if is_first:

# Path: data/search_rows.py
# def search_rows(select_clause, where_clause, order_by_clause, **kwargs):
#     """Fetch rows.
# 
#     Parameters
#     ----------
#     order_by_clause
#     select_clause
#     where_clause
# 
#     Returns
#     -------
#     row_list
#     """
#     try:
#         row_list = select_clause.where(where_clause).order_by(
#             order_by_clause).dicts()
#     except:
#         raise
# 
#     return row_list
# 
# Path: logic/reserved/reserved.py
# class Reserved(BaseModel):
#     """ORM for a reserved name."""
#     import datetime
#     id = pwe.PrimaryKeyField()
#     name = pwe.CharField(default=u'', index=True, unique=True)
#     primary_package = pwe.CharField(default=u'')
#     created_timestamp = pwe.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         db_table = 'reserved'
# 
#     @validate('Reserved', 'name')
#     def validate_name(self):
#         if not self.name:
#             raise AssertionError('Name must be given.')


# Path: logic/reserved/search_rows.py
import re
import peewee as pwe
from data.search_rows import search_rows
from logic.reserved.reserved import Reserved





def search_reserveds(search_text, **kwargs):
    """Search the Reserved table."""
    is_first = True
    where_clause = None
    if search_text:
        search_values = re.sub('[~`%&-+=]', '', search_text).split()
        for s in search_values:
            s_ = u'%'+s+u'%'
            if is_first:
                where_clause = (Reserved.name ** s_)
                is_first = False
            else:
                where_clause = where_clause & \
                    (Reserved.name ** s_)
    if is_first:

        where_clause = (~(Reserved.id >> None))