Skip to content

Commit

Permalink
docs: example for custom id when mysql update (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedayLiu authored and popomore committed Mar 26, 2018
1 parent 10327e1 commit a86334c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/source/en/tutorials/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ const result = await this.app.mysql.update('posts', row); // update records in '

=> UPDATE `posts` SET `name` = 'fengmk2', `modifiedAt` = NOW() WHERE id = 123 ;

// check if update is success or failure
const updateSuccess = result.affectedRows === 1;

// if primary key is your custom id,such as custom_id,you should config it in `where`
const row = {
name: 'fengmk2',
otherField: 'other field value', // any other fields u want to update
modifiedAt: this.app.mysql.literals.now, // `now()` on db server
};

const options = {
where: {
custom_id: 456
}
};
const result = await this.app.mysql.update('posts', row, options); // update records in 'posts'

=> UPDATE `posts` SET `name` = 'fengmk2', `modifiedAt` = NOW() WHERE custom_id = 456 ;

// check if update is success or failure
const updateSuccess = result.affectedRows === 1;
```
Expand Down
19 changes: 19 additions & 0 deletions docs/source/zh-cn/tutorials/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,25 @@ const result = await this.app.mysql.update('posts', row); // 更新 posts 表中

=> UPDATE `posts` SET `name` = 'fengmk2', `modifiedAt` = NOW() WHERE id = 123 ;

// 判断更新成功
const updateSuccess = result.affectedRows === 1;

// 如果主键是自定义的 ID 名称,如 custom_id,则需要在 `where` 里面配置
const row = {
name: 'fengmk2',
otherField: 'other field value', // any other fields u want to update
modifiedAt: this.app.mysql.literals.now, // `now()` on db server
};

const options = {
where: {
custom_id: 456
}
};
const result = await this.app.mysql.update('posts', row, options); // 更新 posts 表中的记录

=> UPDATE `posts` SET `name` = 'fengmk2', `modifiedAt` = NOW() WHERE custom_id = 456 ;

// 判断更新成功
const updateSuccess = result.affectedRows === 1;
```
Expand Down

0 comments on commit a86334c

Please sign in to comment.