[Cubicweb] SELECT * in RQL ?
Nicolas Chauvat
nicolas.chauvat at logilab.fr
Thu Sep 26 15:30:31 CEST 2013
Hi Yann,
On Thu, Sep 26, 2013 at 02:45:12PM +0200, Aurélien Campéas wrote:
> On 26/09/2013 14:37, Yann Cointepas wrote:
> >Hi,
> >
> >I cannot figure out how to get all the attributes of an entity in RQL.
> >In other word, I am looking for something like "SELECT * FROM my_table"
> >in SQL.
>
> AFAIK you can't.
But you can:
for item in execute("Any X WHERE X is MyType").entities():
print item.someattribute
since there is no need to explicitly query an attribute in the RQL to
later access it from the object.
or you can:
Look up the schema using the yams API and generate the RQL request
from it. General idea would be:
letters = 'ABCDEFGHIJKLMNOPQRSTUVW'
attrnames = (attr.name for attr in schema('MyType').get_attributes())
rql = "Any X,"+','.join(letters[idx] for idx in xrange(attrnames))
+" WHERE X is MyType, "
+','.join("X %s %s" % (name, letters[idx])
for idx, name in enumerate(attrnames))
execute(rql)
Hope this helps,
--
Nicolas Chauvat
logilab.fr - services en informatique scientifique et gestion de connaissances
More information about the Cubicweb
mailing list