2.4. RQL用例

2.4.2. RQL在卡片文档中的使用-ReST

使用一个支持ReST内容的对象类型的CubicWeb实例(例如 Card ),可以将基于RQL查询的内容构建为动态文档。

为此,请使用 rql and rql-table ReST directive, for more information about custom ReST directives head over to the sphinx documentation 它广泛地使用它们。

2.4.3. rql指令

这个 rql 指令将RQL表达式和要应用于结果的视图作为输入。

例如,通过打开创建卡片内容http://cubicweb_example.org/add/Card并添加以下内容作为示例:一个blog条目表(包含用户和日期信息的10个最新blog条目表):

Recent blog entries
-------------------

:rql:`Any B,U,D ORDERBY D DESC LIMIT 10 WHERE B is BlogEntry, B title T, B creation_date D, B created_by U:table`
book/images/example-card-with-rql-directive.png

2.4.4. rql表指令

rql-table 启用更多自定义,使您能够修改列 (header )内容,以及应用于特定列的视图 (colvids

例如,通过打开创建卡片内容http://cubicweb_example.org/add/Card并添加以下内容:

Blog entries with rql-table
-----------------------------

.. rql-table::
   :vid: table
   :headers: Title with link, who wrote it, at what date
   :colvids: 1=sameetypelist

   Any B,U,D ORDERBY D DESC LIMIT 10 WHERE B is BlogEntry, B title T, B creation_date D, B created_by U

除RQL字符串外,所有字段都是可选的。这个 :headers: 选项不能包含空列名。

book/images/example-card-with-rql-table-directive.png

2.4.5. 在python项目和CLI中使用

cwclientlib <https://pypi.org/project/cwclientlib/> 使您能够在python项目中仅使用web请求使用RQL。这个项目还提供了一个远程命令行界面(CLI),您可以使用它来替换服务器端 cubicweb-ctl shell .

2.4.6. 在JavaScript/React组件中使用

cwclientelements <https://forge.extranet.logilab.fr/open-source/cwclientelements> 是一个可重用的React组件库,用于使用cubicweb和RQL构建web应用程序。