数据库查询语言(django网关)
HTSQL-DJANGO的Python项目详细描述
htsql是一种关系型的综合导航查询语言。 数据库。这个包包含一个django应用程序,它提供 htsql服务的网关。
这是一个实验包。用法、api和安全性 在未来的版本中,假设可能会发生变化。
有关htsql的更多信息,请参见:
- http://htsql.org/
- The HTSQL homepage
- http://pypi.python.org/pypi/HTSQL/
- The source package for HTSQL
安装和使用
这个包允许您在django项目中使用htsql。到 安装,运行:
# pip install HTSQL-DJANGO
这个命令安装htsql本身和django网关。从中 框中,htsql与sqlite数据库一起工作。运行htsql 数据库服务器,安装其他数据库后端:
# pip install HTSQL-PGSQL # pip install HTSQL-MYSQL
要在django项目中使用htsql,请打开settings.py并添加 'htsql_django'到已安装的应用程序列表:
INSTALLED_APPS = ( # ... 'htsql_django', )
在django项目中使用时,htsql服务将自动 配置为在默认django数据库上服务。你可以提供 使用参数HTSQL_CONFIG的其他配置选项。 例如,合理的配置可以是:
HTSQL_CONFIG = { # Set query timeout in seconds (currently, PostgreSQL only). 'tweak.timeout': { 'timeout': 600 }, # Set the maximum number of output rows. 'tweak.autolimit': { 'limit': 10000 }, # Enable the web-based query editor. 'tweak.shell.default': {}, # Enable meta-data queries. 'tweak.meta': {}, }
接下来,将网关添加到url分派器。打开urls.py并 添加以下行:
urlpatterns = patterns('', # ... url(r'^htsql/', include('htsql_django.urls')), )
这将把从/htsql/开始的http请求转发到htsql 服务。网关仅对经过身份验证的用户可用。
您还可以从python代码进行htsql查询。例如,到 在django教程中计算每次投票的总票数 项目,运行:
>>> from htsql_django import produce >>> >>> query = "/polls_poll{question, total:=sum(polls_choice.votes)}" >>> for row in produce(query): ... print "%s: %s" % (row.question, row.total) ... What's up?: 6