test: 测试使用 UpdateWrapper 插入子查询。

This commit is contained in:
Suomm 2024-03-23 12:26:09 +08:00
parent 4e188b5cf6
commit 9fa4ed8633

View File

@ -17,8 +17,11 @@
package com.mybatisflex.test.mapper;
import com.mybatisflex.core.logicdelete.LogicDeleteManager;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.update.UpdateWrapper;
import com.mybatisflex.core.util.UpdateEntity;
import com.mybatisflex.test.model.Account;
import com.mybatisflex.test.model.AccountVO;
import com.mybatisflex.test.model.AccountVO2;
@ -26,6 +29,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.UncategorizedSQLException;
import java.util.Date;
@ -48,6 +52,21 @@ class AccountMapperTest {
@Autowired
private AccountMapper accountMapper;
@Test
void testInsertRaw() {
Account account = UpdateEntity.of(Account.class);
account.setUserName("I'm a joker.");
account.setBirthday(new Date());
UpdateWrapper<Account> wrapper = (UpdateWrapper<Account>) account;
QueryWrapper queryWrapper = QueryWrapper.create()
.select(ACCOUNT.AGE)
.from(ACCOUNT)
.where(ACCOUNT.ID.eq(1));
wrapper.set(ACCOUNT.AGE, queryWrapper);
wrapper.set(ACCOUNT.BIRTHDAY, QueryMethods.now());
Assertions.assertThrows(UncategorizedSQLException.class, () -> accountMapper.insert(account));
}
@Test
void testCount() {
QueryWrapper queryWrapper = QueryWrapper.create()