3

从例子:

>>> from htsql import HTSQL
>>> htsql = HTSQL("pgsql:///htsql_demo")
>>> rows = htsql.produce("/school{name, count(department)}")

如何将行转换为 JSON?使用 JSON 格式化程序会爆炸:

>>> rows = htsql.produce("/school{name, count(department)}/:json")
UnsupportedActionError: unsupported action
While processing:
    /school{name, count(department)}/:json
                                      ^^^^

我正在使用 HTSQL 2.3.3

4

1 回答 1

3

它必须通过内部 API 完成:

from htsql import HTSQL
demo = HTSQL('pgsql:///htsql_demo')
rows = demo.produce('/school{name, count(department)}')

from htsql.core.fmt.emit import emit
with demo:
    text = ''.join(emit('x-htsql/json', rows))

print text

归功于 HTSQL 用户组的 Kirill Simonov。

于 2014-07-23T18:18:59.957 回答