Home > database >  How to hundle update many or some value of SQL Statement from WSO2 DataService?
How to hundle update many or some value of SQL Statement from WSO2 DataService?

Time:11-01

I have a SQL Statement like this :

UPDATE students 
SET name = :name, school = :school, grade = :grade 
WHERE id = :id AND school = :school

I would like to expose this SQL as an API update using the WSO2 Dataservice.

It worked for me but i have to set all the value in the JSON payload like this :

{
  "_putupdateprofile": {
                 "name":"oussama",
                 "school": "AL-ZOUHOUR",
                 "grade": "A1",
                 "id": 123
                       }
}

where my objectif is to be able to update only one value like this :

{
  "_putupdateprofile": {
                 "name":"oussama",
                 "id": 123
                       }
}

So does WSO2 DataService support this?

CodePudding user response:

I tried this and it worked for me but i still have problem to put where parameters optional

<param name="school" paramType="SCALAR" sqlType="STRING" optional="true" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" optional="true" />

CodePudding user response:

Seems your requirement is to make some parameters optional. To make parameters optional you can add a default value as shown below.

<param name="school" paramType="SCALAR" sqlType="STRING" defaultValue="#{NULL}" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" defaultValue="#{NULL}" />

Note: You may have to change the default value based on the DB type.

Having said the above, If you don't want to update your record with the default values you may have to update your query to omit the fields you don't want to update in your query.

  • Related