# Path: sesql/shortquery.py
# @log_time
# def shortquery(query, order=None, limit=50, historize=False, fields = ()):
#     """
#     Perform a short query and return a lazy Django result set
# 
#     If fields are specified, will fetch those fields from the index
#     """
#     query = SeSQLQuery(query, order, fields)
#     results = query.shortquery(limit)
# 
#     if historize: #suggest feature hook
#         results.historize(query)
# 
#     return results


from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.db import connection, transaction
from django.db.models import Q
from sesql.shortquery import shortquery
import settings
import sys
# (at your option) any later version.

# SeSQL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# ashort with SeSQL.  If not, see <http://www.gnu.org/licenses/>.

"""
This will preform a SeSQL short query and displays the results
It's mostly useful to check your SeSQL installation
"""


class Command(BaseCommand):
    help = "Perform a SeSQL short query"
    
    def handle(self, *apps, **options):
        """
        Handle the command
        """
        if not 1 <= len(apps) <= 2:
            print "Syntax : sesqlshortquery <query> [<order>]"
            sys.exit(1)

        query = eval(apps[0])
        order = len(apps) == 2 and eval(apps[1]) or None
        

# Path: sesql/shortquery.py
# @log_time
# def shortquery(query, order=None, limit=50, historize=False, fields = ()):
#     """
#     Perform a short query and return a lazy Django result set
# 
#     If fields are specified, will fetch those fields from the index
#     """
#     query = SeSQLQuery(query, order, fields)
#     results = query.shortquery(limit)
# 
#     if historize: #suggest feature hook
#         results.historize(query)
# 
#     return results


# Path: sesql/management/commands/sesqlshortquery.py
from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.db import connection, transaction
from django.db.models import Q
from sesql.shortquery import shortquery
import settings
import sys

# (at your option) any later version.

# SeSQL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# ashort with SeSQL.  If not, see <http://www.gnu.org/licenses/>.

"""
This will preform a SeSQL short query and displays the results
It's mostly useful to check your SeSQL installation
"""


class Command(BaseCommand):
    help = "Perform a SeSQL short query"
    
    def handle(self, *apps, **options):
        """
        Handle the command
        """
        if not 1 <= len(apps) <= 2:
            print "Syntax : sesqlshortquery <query> [<order>]"
            sys.exit(1)

        query = eval(apps[0])
        order = len(apps) == 2 and eval(apps[1]) or None
        

        print shortquery(query, order).objs