# Create and Update API

## save

Saves the entity passed as input to the database

```
 DSApi.save(String className, Object entity)
 
 or
 
 DSApi.save(String className, Object entity, String auditMsg)
```

**Parameters**

```
className: the name of class as created using the workbench 
            (correspond to the table)
entity: 
auditMsg:
```

**Sample Code**

```java
String className = "shared.common.product";
Map<String, Object> entity = new HashMap<>();
entity.put("productName", "table");
entity.put("description", "foldable table");
entity.put("prices", 620);
Object res = DSApi.save(className, entity);
```

**Returns**

```
If the object is found then it return a Java Map,
else Result with failed status and message.
```

## saveMany

Saves the list of entities to the database

```
 DSApi.saveMany(String className, Iterable<Object> entities)
 
 or
 
 DSApi.saveMany(String className, Iterable<Object> entities, String auditMsg)
```

**Parameters**

```
className: the name of class as created using the workbench 
            (correspond to the table)
entity: 
```

**Sample Code**

```java
String className = "shared.common.product";
ArrayList<Map<String, Object>> entities = new ArrayList<>();
Map<String, Object> entity = new HashMap<>();
entity.put("productName", "table");
entity.put("description", "foldable table");
entity.put("price", 620);
entities.add(entity);
Object res = DSApi.save(className, entities);
```

**Returns**

```
If the object is found then it return a Java Map,
else Result with failed status and message.
```

## Update&#x20;

Updates the attribute name with the provided value

```
DSApi.update(String className, String id, String attrName, Object value)
 
 or
 
DSApi.update(String className, String id, String attrName, Object value, String auditMsg)
```

**Parameters**

```
className: the name of class as created using the workbench 
            (correspond to the table)
id:
attrName:
value: 
auditMsg:
```

**Sample Code**

```java
String className = "shared.common.product";
String id = "12";
String attrName = "price";
Integer value = 700;
Object res = DSApi.update(className, id, attrName, value);
```

**Returns**

```
```

## UpdateMany&#x20;

Update many records at a time. The class name is provided that indirectly represents a table. ​

```
DSApi.updateMany(String className, List<String> ids, String attrName, Object value)

or

DSApi.updateMany(String className, List<String> ids, String attrName, Object value, String auditMsg)
```

**Parameters**

```
className: the name of class as created using the workbench 
            (correspond to the table)
ids: rows needed to be modified
attrName: the name of the column
value:     the value of inside the column for the specific row
auditMsg: any informational message
```

**Sample Code**

```java
String className = "shared.common.product";
List<String> ids = new ArrayList<>();
ids.add("12");
ids.add("15");
String attrName = "price";
Integer value = 700;
Object res = DSApi.updateMany(className, ids, attrName, value);
```

**Returns**

```
```

## UpdateByQuery

Update by executing a query on the table. ​it takes partial query which is the embellished with *where* clauses.&#x20;

```
DSApi.updateByQuery(String className, String query, Map<String, Object> updateAttrs)

or

DSApi.updateByQuery(String className, String query, Map<String, Object> updateAttrs, String auditMsg)
```

**Parameters**

```
className: the name of class as created using the workbench 
            (correspond to the table)
query:     represents the filtering criteria
updateAttrs:  update map for the attributes
auditMsg:   informational message
```

**Sample Code**

```java
String className = "shared.common.product";
Map<String, Object> updateParam = new HashMap<>();
updateParam.put("deleted", true);
Object res = DSApi.updateByQuery(className, "", updateParam);
```

**Returns**

```
```

## executeSqlWriteStatement

&#x20;Execute a stored procedure or SQL string. The statement is prepared for execution.​ Use this method when you're specifying the full statement.

```
DSApi.executeSqlWriteStatement(String dsName, String sqlStatement,
      Map<String, Object> params)
```

**Parameters**

```
dsName:  the name of the data source
sqlStatement:  SQL String   
params:  parameter values to be replaced inside the string
```

**Returns**&#x20;

```
Success or Failed depending on the execution status of the statement
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trillo.gitbook.io/trillo-workbench-java-sdk/database/create-and-update-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
