ORM 框架 sqltoy-orm 4.12.2 发版

栏目: 软件资讯 · 发布时间: 5年前

内容简介:开源地址: github: https://github.com/chenrenfei/sagacity-sqltoy gitee: https://gitee.com/sagacity/sagacity-sqltoy 感谢热心朋友开发了idea 针对sqltoy的插件,快速定位sql https://gitee.com/threefish/s...

开源地址:

感谢热心朋友开发了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直观可维护

ORM 框架 sqltoy-orm 4.12.2 发版

  • 最高等级的分页优化

ORM 框架 sqltoy-orm 4.12.2 发版

  • 支持用算法代替sql实现行列转换、同比环比、分组汇总等

ORM 框架 sqltoy-orm 4.12.2 发版

ORM 框架 sqltoy-orm 4.12.2 发版

  • 支持分库分表
  • 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主键
  • 提供了通用字段赋值处理

ORM 框架 sqltoy-orm 4.12.2 发版

  • 提供了树形表的统一处理机制

ORM 框架 sqltoy-orm 4.12.2 发版

  • sql文件更新自动重载,便于开发阶段无需重启应用
  • 慢sql统计功能

以上所述就是小编给大家介绍的《ORM 框架 sqltoy-orm 4.12.2 发版》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Computational Geometry

Computational Geometry

Mark de Berg、Otfried Cheong、Marc van Kreveld、Mark Overmars / Springer / 2008-4-16 / USD 49.95

This well-accepted introduction to computational geometry is a textbook for high-level undergraduate and low-level graduate courses. The focus is on algorithms and hence the book is well suited for st......一起来看看 《Computational Geometry》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具