# Create and Update API

## save

Saves the entity passed as input to the database

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

**Parameters**

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

**Sample Code**

```python
className = "shared.common.product"
entity = {"productName" : "table", "description" : "foldable table", "prices" : 620}

res = DSApi.save(className, entity)
```

**Returns**

```
A Result object indicating the success or failure of the save operation.
```

## saveMany

Saves the list of entities to the database

```
 DSApi.saveMany(className, entities)
 
 or
 
 DSApi.saveMany(className, entities, auditMsg)
```

**Parameters**

```
className: the str name of class as created using the workbench 
            (correspond to the table)
entity: Iterable<Object>
```

**Sample Code**

```python
className = 'shared.common.product'

entities = []

entity = {"productName" : "table", "description" : "foldable table", "prices" : 620}

entities.append(entity)

res = DSApi.save(className, entities)
```

**Returns**

```
A Result object indicating the success or failure of the save operation.
```

## Update&#x20;

Updates the attribute name with the provided value

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

**Parameters**

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

**Sample Code**

```python
className = "shared.common.product"
id = "12"
attrName = "price"
value = 700

res = DSApi.update(className, id, attrName, value)
```

**Returns**

```
A Result object indicating the success or failure of the update operation.
```

## UpdateMany&#x20;

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

```
DSApi.updateMany(className, ids, attrName, value)

or

DSApi.updateMany(className, ids, attrName, value, auditMsg)
```

**Parameters**

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

**Sample Code**

```python
className = "shared.common.product"
ids = ["12", "15"]
attrName = "price"
value = 700

res = DSApi.updateMany(className, ids, attrName, value)
```

**Returns**

```
A Result object indicating the success or failure of the update operation.
```

## UpdateByQuery

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

```
DSApi.updateByQuery(className, query, updateAttrs)

or

DSApi.updateByQuery(className, query, updateAttrs, auditMsg)
```

**Parameters**

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

**Sample Code**

```python
className = "shared.common.product"
updateParam = {"deleted": True}

res = DSApi.updateByQuery(className, "", updateParam)
```

**Returns**

```
A Result object indicating the success or failure of the update operation.
```

## 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(dsName, sqlStatement, params)
```

**Parameters**

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

**Returns**&#x20;

```
 A Result object containing the execution result.
```


---

# 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-python-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.
