mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
add query methods
This commit is contained in:
parent
147281606e
commit
cbba354c96
@ -17,6 +17,7 @@ package com.mybatisflex.core.row;
|
||||
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.transaction.TransactionContext;
|
||||
import com.mybatisflex.core.transaction.TransactionalManager;
|
||||
@ -159,6 +160,17 @@ public class Db {
|
||||
return invoker().deleteByMap(tableName, whereColumns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 条件删除数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件内容
|
||||
*/
|
||||
public static int deleteByCondition(String tableName, QueryCondition condition) {
|
||||
return invoker().deleteByCondition(tableName, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 query 构建的条件来删除数据
|
||||
*
|
||||
@ -202,6 +214,17 @@ public class Db {
|
||||
return invoker().updateByMap(tableName, data, whereColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 condition 来更新数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param data 数据
|
||||
* @param condition 条件
|
||||
*/
|
||||
public static int updateByCondition(String tableName, Row data, QueryCondition condition) {
|
||||
return invoker().updateByCondition(tableName, data, condition);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 query 构建的条件来更新数据
|
||||
@ -270,6 +293,16 @@ public class Db {
|
||||
return invoker().selectOneByMap(tableName, whereColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
*/
|
||||
public static Row selectOneByCondition(String tableName, QueryCondition condition) {
|
||||
return invoker().selectOneByCondition(tableName, condition);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来查询 1 条数据
|
||||
@ -303,6 +336,39 @@ public class Db {
|
||||
return invoker().selectListByMap(tableName, whereColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 map 构建的条件来查询数据列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param whereColumns 条件
|
||||
* @param count 数据量
|
||||
*/
|
||||
public static List<Row> selectListByMap(String tableName, Map<String, Object> whereColumns, int count) {
|
||||
return invoker().selectListByMap(tableName, whereColumns, count);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过 condition 条件来查询数据列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition where 条件
|
||||
*/
|
||||
public static List<Row> selectListByCondition(String tableName, QueryCondition condition) {
|
||||
return invoker().selectListByCondition(tableName, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 condition 条件来查询数据列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
* @param count 数据量
|
||||
*/
|
||||
public static List<Row> selectListByCondition(String tableName, QueryCondition condition, int count) {
|
||||
return invoker().selectListByCondition(tableName, condition, count);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过 query 来查询数据列表
|
||||
@ -357,6 +423,17 @@ public class Db {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 条件来查询数量
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
*/
|
||||
public static long selectCountByCondition(String tableName, QueryCondition condition) {
|
||||
return invoker().selectCountByCondition(tableName, condition);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 query 构建的条件来查询数据量
|
||||
*
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.provider.RowSqlProvider;
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
@ -47,7 +48,6 @@ public interface RowMapper {
|
||||
int insert(@Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.ROW) Row row);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 执行 insert sql 语句
|
||||
*
|
||||
@ -141,6 +141,18 @@ public interface RowMapper {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 来删除数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 数据
|
||||
* @return 执行影响的行数
|
||||
*/
|
||||
default int deleteByCondition(String tableName, QueryCondition condition) {
|
||||
return deleteByQuery(tableName, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 构建 where 条件来删除数据
|
||||
*
|
||||
@ -191,6 +203,19 @@ public interface RowMapper {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 来更新数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param data 要更新的数据
|
||||
* @param condition 更新条件
|
||||
* @return 执行影响的行数
|
||||
*/
|
||||
default int updateByCondition(String tableName, Row data, QueryCondition condition) {
|
||||
return updateByQuery(tableName, data, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来构建 where 条件更新数据
|
||||
*
|
||||
@ -269,13 +294,23 @@ public interface RowMapper {
|
||||
*
|
||||
* @param tableName
|
||||
* @param whereConditions
|
||||
* @return
|
||||
*/
|
||||
default Row selectOneByMap(String tableName, Map whereConditions) {
|
||||
return selectOneByQuery(tableName, new QueryWrapper().where(whereConditions));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件内容
|
||||
*/
|
||||
default Row selectOneByCondition(String tableName, QueryCondition condition) {
|
||||
return selectOneByQuery(tableName, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来查询 1 条数据
|
||||
*
|
||||
@ -314,6 +349,42 @@ public interface RowMapper {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(whereConditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 map 来查询一个 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param whereConditions 条件
|
||||
* @param count 数据量
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByMap(String tableName, Map<String, Object> whereConditions, int count) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(whereConditions).limit(count));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByCondition(String tableName, QueryCondition condition) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
* @param count 数据量
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByCondition(String tableName, QueryCondition condition, int count) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(condition).limit(count));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来查询一个 row 列表
|
||||
@ -379,7 +450,18 @@ public interface RowMapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来查询数据
|
||||
* 根据 condition 条件来查询数据量
|
||||
*
|
||||
* @param tableName
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
default long selectCountByCondition(String tableName, QueryCondition condition) {
|
||||
return selectCountByQuery(tableName, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 queryWrapper 来查询数量
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param queryWrapper queryWrapper
|
||||
@ -405,6 +487,53 @@ public interface RowMapper {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询某张表的数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param pageNumber 当前页码
|
||||
* @param pageSize 每页的数据量
|
||||
* @param condition 条件
|
||||
* @return
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, int pageNumber, int pageSize, QueryCondition condition) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize);
|
||||
return paginate(tableName, page, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询某张表的数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param pageNumber 当前页码
|
||||
* @param pageSize 每页的数据量
|
||||
* @param totalRow 数据总量
|
||||
* @param queryWrapper 条件封装
|
||||
* @return 一页数据
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryWrapper queryWrapper) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize, totalRow);
|
||||
return paginate(tableName, page, queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询某张表的数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param pageNumber 当前页码
|
||||
* @param pageSize 每页的数据量
|
||||
* @param totalRow 数据总量
|
||||
* @param condition 条件
|
||||
* @return
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryCondition condition) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize, totalRow);
|
||||
return paginate(tableName, page, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询数据
|
||||
*
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package com.mybatisflex.core.row;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.apache.ibatis.executor.BatchResult;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
@ -115,6 +116,10 @@ public class RowMapperInvoker {
|
||||
return execute(mapper -> mapper.deleteByMap(tableName, whereColumns));
|
||||
}
|
||||
|
||||
public int deleteByCondition(String tableName, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.deleteByCondition(tableName, condition));
|
||||
}
|
||||
|
||||
public int deleteByQuery(String tableName, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.deleteByQuery(tableName, queryWrapper));
|
||||
}
|
||||
@ -131,6 +136,10 @@ public class RowMapperInvoker {
|
||||
return execute(mapper -> mapper.updateByMap(tableName, data, whereColumns));
|
||||
}
|
||||
|
||||
public int updateByCondition(String tableName, Row data, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.updateByCondition(tableName, data, condition));
|
||||
}
|
||||
|
||||
public int updateByQuery(String tableName, Row data, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.updateByQuery(tableName, data, queryWrapper));
|
||||
}
|
||||
@ -155,6 +164,10 @@ public class RowMapperInvoker {
|
||||
return execute(mapper -> mapper.selectOneByMap(tableName, whereColumns));
|
||||
}
|
||||
|
||||
public Row selectOneByCondition(String tableName, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.selectOneByCondition(tableName, condition));
|
||||
}
|
||||
|
||||
public Row selectOneByQuery(String tableName, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.selectOneByQuery(tableName, queryWrapper));
|
||||
}
|
||||
@ -167,6 +180,19 @@ public class RowMapperInvoker {
|
||||
return execute(mapper -> mapper.selectListByMap(tableName, whereColumns));
|
||||
}
|
||||
|
||||
public List<Row> selectListByMap(String tableName, Map<String, Object> whereColumns, int count) {
|
||||
return execute(mapper -> mapper.selectListByMap(tableName, whereColumns, count));
|
||||
}
|
||||
|
||||
public List<Row> selectListByCondition(String tableName, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.selectListByCondition(tableName, condition));
|
||||
}
|
||||
|
||||
public List<Row> selectListByCondition(String tableName, QueryCondition condition, int count) {
|
||||
return execute(mapper -> mapper.selectListByCondition(tableName, condition, count));
|
||||
}
|
||||
|
||||
|
||||
public List<Row> selectListByQuery(String tableName, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.selectListByQuery(tableName, queryWrapper));
|
||||
}
|
||||
@ -187,6 +213,10 @@ public class RowMapperInvoker {
|
||||
return execute(mapper -> mapper.selectCount(sql, args));
|
||||
}
|
||||
|
||||
public long selectCountByCondition(String tableName, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.selectCountByCondition(tableName, condition));
|
||||
}
|
||||
|
||||
public long selectCountByQuery(String tableName, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.selectCountByQuery(tableName, queryWrapper));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user