ORM 框架 sqltoy-orm 4.12.2 发版
开源地址: github:https://github.com/chenrenfei/sagacity-sqltoy gitee:https://gitee.com/sagacity/sagacity-sqltoy 感谢热心朋友开发了idea 针对sqltoy的插件,快速定位sql https://gitee.com/threefish/sqltoy-idea-plugins 更新内容 1、增强直接写sql查询时自动根据情况补齐select c1,c2,.. from table where 2、优化quickvo,剔除对log4j的依赖改用jdk自带log,大幅减小jar的大小 3、增加三个单表查询、修改、删除方法,更加简化单表操作,便于内部逻辑快捷处理 /** * findEntity 模式,简化sql编写模式,面向接口服务层提供快捷数据查询和处理 * 1、通过where指定条件 * 2、支持lock * 3、支持order by (order by 在接口服务 层意义不大) * 4、自动将对象属性映射成表字段 */ @Test public void findEntity() { //条件利用sqltoy特有的#[]充当动态条件判断,#[]是支持嵌套的 List<StaffInfoVO> staffVOs = sqlToyLazyDao.findEntity(StaffInfoVO.class, EntityQuery.create().where("#[staffName like ?] #[ and status=?]") .lock(LockMode.UPGRADE).orderBy("staffName").orderByDesc("createTime") .values("陈", 1)); System.err.println(JSON.toJSONString(staffVOs)); } /** * 指定where 条件并提供对象传参 */ @Test public void findEntityByVO() { List<StaffInfoVO> staffVOs = sqlToyLazyDao.findEntity(StaffInfoVO.class, EntityQuery.create().where("#[staffName like :staffName] #[ and status=:status]") .values(new StaffInfoVO().setStatus(1).setEmail("test3@aliyun.com"))); System.err.println(JSON.toJSONString(staffVOs)); } /** * 通过参数传值进行删除,where必须有值(后端会校验),delete操作属于危险操作 */ @Test public void deleteEntity() { Long deleteCount = sqlToyLazyDao.deleteByQuery(StaffInfoVO.class, EntityQuery.create().where("status=:status").values(new StaffInfoVO().setStatus(1))); System.err.println(deleteCount); } /** * update 操作where也必须有值,以防危险操作 */ @Test public void updateEntity() { Long updateCount = sqlToyLazyDao.updateByQuery(StaffInfoVO.class, EntityUpdate.create().set("staffName", "张三").where("staffName like ? and status=?").values("陈", 1)); System.err.println(updateCount); } sqltoy特点说明: 支持mysql、postgresql、db2、oracle、sqlserver、sqlite、clickhouse、elasticsearch等 具有JPA模式的CRUD功能(即CRUD无需写sql),无需写Dao,sqltoy提供了SqlToyLazyDao,同时提供了quickvo从数据库生成POJO。 根本上杜绝了sql注入问题 最科学的sql编写方式 * sqltoy的sql编写(支持嵌套) select * from sqltoy_device_order_info t where #[t.ORDER_ID=:orderId] #[and t.ORGAN_ID in (:authedOrganIds)] #[and t.STAFF_ID in (:staffIds)] #[and t.TRANS_DATE>=:beginDate] #[and t.TRANS_DATE<:endDate] * mybatis同样功能实现 select * from sqltoy_device_order_info t <where> <if test="orderId!=null"> and t.ORDER_ID=#{orderId} </if> <if test="authedOrganIds!=null"> and t.ORGAN_ID in <foreach collection="authedOrganIds" item="order_id" separator="," open="(" close=")"> #{order_id} </foreach> </if> <if test="staffIds!=null"> and t.STAFF_ID in <foreach collection="staffIds" item="staff_id" separator="," open="(" close=")"> #{staff_id} </foreach> </if> <if test="beginDate!=null"> and t.TRANS_DATE>=#{beginDate} </if> <if test="endDate!=null"> and t.TRANS_DATE<#{endDate} </if> </where> 缓存翻译大幅提升性能,减少多表关联,让sql直观可维护 最高等级的分页优化 支持用算法代替sql实现行列转换、同比环比、分组汇总等 支持分库分表 sqltoy支持跨数据库函数自适应:一套sql可以自适应多种数据库 提供了5种默认的非数据库相关的主键策略 1、shortNanoTime 22位有序安全ID,格式: 13位当前毫秒+6位纳秒+3位主机ID 2、nanoTimeId 26位有序安全ID,格式:15位:yyMMddHHmmssSSS+6位纳秒+2位(线程Id+随机数)+3位主机ID 3、uuid:32 位uuid 4、SnowflakeId 雪花算法ID 5、redisId 基于redis 来产生规则的ID主键 提供了通用字段赋值处理 提供了树形表的统一处理机制 sql文件更新自动重载,便于开发阶段无需重启应用 慢sql统计功能