查询cassandra对象映射器

时间:2019-04-11 15:29:24

标签: python cassandra orm

我试图弄清楚如何用Object Mapper替换这两个查询,因为这是必需的,但是我无法解决这个问题。

有人能指出我正确的方向吗?

查询的内容粘贴在下面

我已经尝试过filter(),但是它不起作用

rows = session.execute('SELECT gocd, serverdependencies, jenkins, nodes FROM application WHERE name=%s',{apps})

rows = session.execute('SELECT toJson(address) FROM service WHERE servicename=%s', [service])
    for row in rows:
        result.append(row)

1 个答案:

答案 0 :(得分:0)

只需遵循documentation。我刚刚检查了驱动程序的最新版本,并且filter正常工作:

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model
from cassandra.cqlengine import connection

class Application(Model):
     name = columns.Text(primary_key=True)
     gocd = columns.List(value_type=columns.Text)
     jenkins = columns.List(value_type=columns.Text)
     serverdependencies = columns.List(value_type=columns.Text)

connection.setup(['127.0.0.1'], "test", protocol_version=3)
q = Application.objects.filter(name='test')
q[:]

,它输出以下内容:

[Application(name='test', gocd=[u'test'], jenkins=[], serverdependencies=[])]

获取以下数据:

cqlsh:test> SELECT * from application ;

 name | gocd     | jenkins | nodes | serverdependencies
------+----------+---------+-------+--------------------
 test | ['test'] |    null |  null |               null