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

Add duplicateKeys property to Insert, BatchInsert, and MultiInsert annotations #1150

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

nakamura-to
Copy link
Member

@nakamura-to nakamura-to commented Aug 3, 2024

This pull request allows specifying the keys to be used for duplicate checks:

@Dao
public interface EmployeeDao {

  @Insert(duplicateKeyType = DuplicateKeyType.UPDATE, duplicateKeys = {"employeeNo"})
  int insert(Employee employee);

  @BatchInsert(duplicateKeyType = DuplicateKeyType.UPDATE, duplicateKeys = {"employeeNo"})
  int[] insertBatch(List<Employee> employees);

  @MultiInsert(duplicateKeyType = DuplicateKeyType.UPDATE, duplicateKeys = {"employeeNo"})
  int insertMulti(List<Employee> employees);
}

When using PostgreSQL, the following SQL will be generated:

insert into EMPLOYEE as target (EMPLYEE_ID, EMPLYEE_NO, EMPLYEE_NAME, VERSION) values (?, ?, ?, ?) on conflict (EMPLYEE_NO) do update set EMPLYEE_NAME = excluded.EMPLYEE_NAME, VERSION = excluded.VERSION

The specified keys are used in the ON CONFLICT clause.

For DBMSs like MySQL, where specifying a key isn't supported, the duplicateKeys property will be disregarded.

@nakamura-to nakamura-to changed the title Add 'duplicateKeys' property to 'Insert', 'BatchInsert', and 'MultiInsert' annotations Add duplicateKeys property to Insert, BatchInsert, and MultiInsert annotations Aug 3, 2024
@nakamura-to
Copy link
Member Author

@momosetkn @orekyuu We thought this feature might catch your interest. If you have any questions or concerns, feel free to leave a comment.

@nakamura-to nakamura-to merged commit 8c2b0d7 into master Aug 7, 2024
11 checks passed
@nakamura-to nakamura-to deleted the feat/improve-multi-row-insert branch August 7, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant