[PROPOSAL] Return json from database directly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PROPOSAL] Return json from database directly

Shi Jinghai-3
Hi there,

While playing openapi with ofbiz, I found it would more convenient to get some view entity results in json format. I tried array-to-json of PostgreSQL, it worked.

A sample use case:
    <view-entity entity-name="VWProductAttribute"
                 package-name="org.langhua.sandflower.luca.product"
                 never-cache="true"
                 title="VWProductAttribute">
        <member-entity entity-alias="PA" entity-name="ProductAttribute"></member-entity>

        <alias entity-alias="PA" name="productId" group-by="true"></alias>
        <alias entity-alias="PA" name="attrNames" field="attrName" function="array-to-json"></alias>
        <alias entity-alias="PA" name="attrValues" field="attrValue" function="array-to-json"></alias>
        <alias entity-alias="PA" name="attrDescriptions" field="attrDescription" function="array-to-json"></alias>
    </view-entity>

And then the result could be sent to front-end(react/vue/angular) directly.

Kind Regards,

Shi Jinghai
grv
Reply | Threaded
Open this post in threaded view
|

Re: [PROPOSAL] Return json from database directly

grv
Hi Shi

I am sorry but I am not following it. By results, did you mean the result
of operations done on the View Entity or the definition of the View
Entities in JSON format? Also, since you mentioned PostgreSQL, would it be
database-agnostic and not limited to PostgreSQL?

An example JSON response will help.

Best Regards,
Girish


On Tue, Jun 30, 2020 at 4:00 PM Shi Jinghai <[hidden email]> wrote:

> Hi there,
>
> While playing openapi with ofbiz, I found it would more convenient to get
> some view entity results in json format. I tried array-to-json of
> PostgreSQL, it worked.
>
> A sample use case:
>     <view-entity entity-name="VWProductAttribute"
>                  package-name="org.langhua.sandflower.luca.product"
>                  never-cache="true"
>                  title="VWProductAttribute">
>         <member-entity entity-alias="PA"
> entity-name="ProductAttribute"></member-entity>
>
>         <alias entity-alias="PA" name="productId" group-by="true"></alias>
>         <alias entity-alias="PA" name="attrNames" field="attrName"
> function="array-to-json"></alias>
>         <alias entity-alias="PA" name="attrValues" field="attrValue"
> function="array-to-json"></alias>
>         <alias entity-alias="PA" name="attrDescriptions"
> field="attrDescription" function="array-to-json"></alias>
>     </view-entity>
>
> And then the result could be sent to front-end(react/vue/angular) directly.
>
> Kind Regards,
>
> Shi Jinghai
>