# Insert/Update

Use the `set` and `save` methods to write data to a table in a data source using an ORM entity class.

## Insert

The following example will insert a new record into the `Categories` table with a `CategoryName` of `Custom Category`.  This will automatically be an `INSERT` operation as the primary key field on the table `CategoryId` was not supplied.&#x20;

```javascript
const keys = Categories.set()
   .field(CategoriesField.CategoryName, "Custom Category")
.save();
```

The save method will return an array of new primary key values for inserted records.

## Update

After the line of code above is executed, the keys array will contain the `CategoryId` for the newly added record. &#x20;

The example below updates the `CatgoryName` field for this new record to `My Category`by  including the key field `CatagoryID` in the update with the key value.

```javascript
...

const customCatgoryId = keys[0].CategoryID;

Categories.set()
   .field(CategoriesField.CategoryID, customCatgoryId)
   .field(CategoriesField.CategoryName, "My Category")
.save();
```

To update records in the table without the key value, use the `eq` to set a value based one of the other fields.

The example below changes the `CategoryName` field value to `My Category` where the field `Description` is `This is my description`.

```javascript
Categories.set()
   .field(CategoriesField.CategoryName, "My Category")
   .eq(CategoriesField.Description, "This is my description")
.save();
```
