- 修复开发模式SQL文件不能自动刷新的BUG
- 在MarkDown管理SQL的能力外,新增XML文件管理SQL,并提供类似MyBatis的XML语法标签(基于Beetl对XML标签支持)。
<?xml version="1.0" encoding="UTF-8" ?>
<beetlsql>
<sql id="testIf">
select * from sys_user where 1=1
<if test="name!=null">
and name != #{name}
</if>
</sql>
<sql id="testIsNotEmpty">
select * from sys_user where 1=1
<isNotEmpty value="name">
and name=#{name}
</isNotEmpty>
</sql>
<sql id="testIsBlank">
select * from sys_user where 1=1
<isBlank value="name">
and name='lijz'
</isBlank>
</sql>
<sql id="testForeach">
select * from sys_user where 1=1 and id in
<foreach items="ids" var="id,status" open="(" close=")" separator=",">
#{id}
</foreach>
</sql>
<sql id="testInclude">
select * from sys_user where 1=1
<include refid="idList"/>
</sql>
<sql id="idList">
and id = #{id}
</sql>
<sql id="testWhere">
select * from sys_user
<where>
and 1=1
</where>
</sql>
<sql id="testTrim">
select * from sys_user
<trim prefix="where" prefixOverrides="and | or">
name='lijz'
</trim>
</sql>
<sql id="testBind">
select * from sys_user
<bind value="id+1" export="newValue"/>
where id=#{newValue}
</sql>
</beetlsql>
XML的SQL语句仍然能使用任何Beetl的语法,且定义一个新的XML标签非常容易,以If标签为例子,只需要20行代码
public static class IfTag extends Tag{
@Override
public void render() {
if (!containHtmlAttribute("test")) {
throw new IllegalArgumentException("缺少 test属性");
}
Object value = this.getHtmlAttribute("test");
if (!(value instanceof Boolean)) {
throw new IllegalArgumentException("期望test表达式运算结果是boolean类型");
}
if ((Boolean) value) {
this.doBodyRender();
}
}
}
maven
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetlsql</artifactId>
<version>3.21.0-RELEASE</version>
</dependency>
BeetlSQL 自主研发自 2015 年,目标是提供开发高效,维护高效,运行高效的数据访问框架,它适用范围广,定制性强,写起数据库访问代码特别顺滑,不亚于 MyBatis。你不想写 SQL 也好,或者想更好地写 SQL 也好,BeetlSQL 都能满足这要求,目前支持的数据库如下
- 传统数据库:MySQL (包括支持 MySQL 协议的各种数据库), MariaDB ,Oralce ,Postgres (包括支持 Postgres 协议的各种数据库), DB2 , SQL Server ,H2 , SQLite , Derby ,神通,达梦,华为高斯,人大金仓,PolarDB,GBase8s,GreatSQL 等
- 大数据:HBase,ClickHouse,Cassandar,Hive,GreenPlum
- 物联网时序数据库:Machbase,TD-Engine,IotDB
- SQL 查询引擎:Drill,Presto,Druid
- 内存数据库:ignite,CouchBase
如下测试使用了最新的 Hibernate,MyBatis,包含了常用的 orm 操作: 多表联合查询映射(complexMapping),直接执行 sql (executeJdbc), 执行模板 sql (executeTemplate), 执行文件中的模板 sql ( File), 内置插入(insert),Query 调用链 (Query), 翻页查询 (pageQuery), 内置主键查询 (selectById), one2Many 自动关联查询
-
Benchmark Mode Cnt Score Error Units JMHMain.beetlsqlComplexMapping thrpt 2 207.914 ops/ms JMHMain.beetlsqlExecuteJdbc thrpt 2 496.413 ops/ms JMHMain.beetlsqlExecuteTemplate thrpt 2 456.779 ops/ms JMHMain.beetlsqlFile thrpt 2 424.703 ops/ms JMHMain.beetlsqlInsert thrpt 2 254.596 ops/ms JMHMain.beetlsqlLambdaQuery thrpt 2 230.682 ops/ms JMHMain.beetlsqlOne2Many thrpt 2 122.058 ops/ms JMHMain.beetlsqlPageQuery thrpt 2 193.937 ops/ms JMHMain.beetlsqlSelectById thrpt 2 421.610 ops/ms JMHMain.jdbcExecuteJdbc thrpt 2 1041.376 ops/ms JMHMain.jdbcInsert thrpt 2 332.804 ops/ms JMHMain.jdbcSelectById thrpt 2 1048.165 ops/ms JMHMain.jpaExecuteJdbc thrpt 2 92.327 ops/ms JMHMain.jpaExecuteTemplate thrpt 2 136.409 ops/ms JMHMain.jpaInsert thrpt 2 61.157 ops/ms JMHMain.jpaOne2Many thrpt 2 98.182 ops/ms JMHMain.jpaPageQuery thrpt 2 124.133 ops/ms JMHMain.jpaSelectById thrpt 2 295.552 ops/ms JMHMain.mybatisComplexMapping thrpt 2 99.312 ops/ms JMHMain.mybatisExecuteTemplate thrpt 2 212.699 ops/ms JMHMain.mybatisFile thrpt 2 166.106 ops/ms JMHMain.mybatisInsert thrpt 2 152.376 ops/ms JMHMain.mybatisLambdaQuery thrpt 2 9.545 ops/ms JMHMain.mybatisPageQuery thrpt 2 68.617 ops/ms JMHMain.mybatisSelectById thrpt 2 251.361 ops/ms JMHMain.weedExecuteJdbc thrpt 2 402.270 ops/ms JMHMain.weedExecuteTemplate thrpt 2 426.764 ops/ms JMHMain.weedFile thrpt 2 440.994 ops/ms JMHMain.weedInsert thrpt 2 232.100 ops/ms JMHMain.weedLambdaQuery thrpt 2 335.052 ops/ms JMHMain.weedPageQuery thrpt 2 216.811 ops/ms JMHMain.weedSelectById thrpt 2 359.930 ops/ms
阅读文档 源码和例子 在线体验 多库使用 性能测试