Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest-api-client): supports the upsert option #3118

Merged
merged 7 commits into from
Jan 8, 2025
Merged

Conversation

chihiro-adachi
Copy link
Contributor

@chihiro-adachi chihiro-adachi commented Jan 6, 2025

Why

The upsert option is now available in the record api.
https://cybozu.dev/ja/kintone/docs/rest-api/records/update-records/

What

The upsert option is now supported.
It can be used with the following methods.

  • updateRecords
  • updateAllRecords

How to test

You can check the operation below.

import { KintoneRestAPIClient } from "./src";

const client = new KintoneRestAPIClient({
  baseUrl: "http://localhosst",
  auth: {
    username: "Administrator",
    password: "cybozu",
  },
});

const main = async () => {
  const resp = await client.record.updateRecords({
    app: 16,
    upsert: true,
    records: [
      {
        //        id: 1,
        updateKey: {
          field: "文字列__1行_",
          value: "123",
        },
        record: {
          文字列__1行__0: {
            value: "***",
          },
        },
      },
    ],
  });
  console.log(resp);
};

main();

Checklist

  • Read CONTRIBUTING.md
  • Updated documentation if it is required.
  • Added tests if it is required.
  • Passed pnpm lint and pnpm test on the root directory.

@chihiro-adachi chihiro-adachi requested a review from a team as a code owner January 6, 2025 23:40
@chihiro-adachi chihiro-adachi requested review from tasshi-me and shabaraba and removed request for a team January 6, 2025 23:40
@github-actions github-actions bot added the pkg: rest-api-client @kintone/rest-api-client label Jan 6, 2025
@chihiro-adachi chihiro-adachi changed the title [WIP] feat(rest-api-client): Supports the upsert option feat(rest-api-client): Supports the upsert option Jan 7, 2025
@chihiro-adachi chihiro-adachi changed the title feat(rest-api-client): Supports the upsert option feat(rest-api-client): supports the upsert option Jan 7, 2025
@@ -299,6 +299,7 @@ If you'd like to update over 100 records, please consider using [updateAllRecord
| Name | Type | Required | Description |
| ------------------------- | :--------------: | :-------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The app ID. |
| upsert | Boolean | No | Whether to execute in UPSERT mode. If trueis specified, it will be executed in UPSERT mode. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trueis -> true isを意図していそう?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hisasami
ありがとうございます!修正しました。
324325f

@@ -332,6 +334,7 @@ For more information, please see [an example of KintoneAllRecordsError](errorHan
| Name | Type | Required | Description |
| ------------------------- | :--------------: | :-------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The app ID. |
| upsert | boolean | No | Whether to execute in UPSERT mode. If trueis specified, it will be executed in UPSERT mode. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tureisこちらも

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hisasami
ありがとうございます!修正しました。
324325f

Copy link
Member

@shabaraba shabaraba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chihiro-adachi
updateRecordに組み込むなら良さそうですが、upsertRecordメソッドが別にいるようです。
中身は複数のAPIの出し分けの実装になっているので、こちらを新しい方式に置き換えるでも良いかなと思いました!

@chihiro-adachi
Copy link
Contributor Author

@shabaraba
確認ありがとうございます!

upsertRecordメソッドは一括更新ではなく単体更新なので、修正の対象外としました。
内部実装置き換えることはできるのですが、性能向上の幅もあまりないので、無理に対応しなくてもよいかなと思いましたがいかがでしょう?

@shabaraba
Copy link
Member

@shabaraba
すみません、単体更新でしたね
であれば今回は不要でいいかなと思いました、ご回答ありがとうございます!
approveしておきます!

@chihiro-adachi
Copy link
Contributor Author

@shabaraba
ご確認ありがとうございます!

@chihiro-adachi chihiro-adachi merged commit 3de0173 into main Jan 8, 2025
18 checks passed
@chihiro-adachi chihiro-adachi deleted the feat-upsert branch January 8, 2025 04:42
This was referenced Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: rest-api-client @kintone/rest-api-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants