-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add upsert mode to update records #70
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for the UPSERT mode feature introduced in the kintone API update (January 12, 2025) for the Update Records API. The UPSERT mode allows updating existing records or creating new ones in a single API call.
Key changes:
- Added
upsertfield toUpdateRecordsRequestfor enabling UPSERT mode - Introduced
RecordOperationTypeenum (UPDATE/INSERT) andRecordUpdateResultclass to handle operation type information - Changed the return type of
RecordClient.updateRecords()fromList<RecordRevision>toList<RecordUpdateResult>(breaking change)
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| UpdateRecordsRequest.java | Added optional upsert field to enable UPSERT mode |
| RecordOperationType.java | New enum defining UPDATE and INSERT operation types |
| RecordUpdateResult.java | New class containing record ID, revision, and operation type |
| UpdateRecordsResponseBody.java | Changed to use RecordUpdateResult instead of RecordRevision |
| RecordClient.java | Updated return type of updateRecords() method to use RecordUpdateResult |
| RecordClientTest.java | Updated test to verify the new RecordUpdateResult return type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @return a list of record update results. See {@link RecordUpdateResult} | ||
| */ | ||
| public List<RecordRevision> updateRecords(long app, List<RecordForUpdate> records) { | ||
| public List<RecordUpdateResult> updateRecords(long app, List<RecordForUpdate> records) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsertRecords(app, records)があってもよさそう
public List<RecordUpdateResult> upsertRecords(long app, List<RecordForUpdate> records) {
UpdateRecordsRequest req = new UpdateRecordsRequest();
req.setApp(app);
req.setUpsert(true);
req.setRecords(records);
return updateRecords(req).getRecords();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f2e22da で対応
|
|
||
| import lombok.Value; | ||
|
|
||
| /** A value that contains the record ID, revision, and operation, returned by Update Records API. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RecordRevisionにreturned by Update Records APIの記述が残ってそう
https://github.com/kintone/kintone-java-client/blob/master/src/main/java/com/kintone/client/model/record/RecordRevision.java#L6-L7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b7a495f で対応
b7a495f to
293aa73
Compare
Why
kintone API の 2025年1月12日のアップデートで、Update Records API に UPSERT mode
が追加されました。この機能により、指定されたレコードが存在する場合は更新、存在しない場合は新規作成を一度のAPI呼び出しで実行できるようになります。Java
Clientでもこの新機能をサポートする必要があります。
ref: https://cybozu.dev/ja/kintone/news/api-updates/2025-01/
What
REST APIとしてはUpdate Records APIのオプション(upsertパラメーター)として実装されていますが、リクエスト・レスポンスともにパラメーターが追加されているため、JavaクライアントとしてはupdateRecordsとは独立したインターフェースとして実装しました。これにより、既存のupdateRecordsメソッドへの破壊的変更を防止しています。
How to test
Checklist