1 个不稳定版本
0.2.5 | 2023年8月14日 |
---|---|
0.2.4 |
|
0.2.2 |
|
0.2.1 |
|
0.1.7 |
|
#385 在 命令行工具
38 每月下载量
45KB
1K SLoC
xbatis2sql
xbatis2sql
,从 iBATIS sqlmap 文件/MyBatis 映射文件中收集 SQL 语句。
安装
cargo install xbatis2sql
用法
# xbatis2sql -h
Usage: xbatis2sql [-i|-m] -t [Oracle/MySQL] -s ... -o ...
Options:
-i, --ibatis try to parse iBATIS sqlmap files
-m, --mybatis try to parse MyBatis mapper files
-t, --type DB db type
-s, --src SRC source directory
-o, --output OUTPUT output directory
-h, --help print this help menu
iBATIS
xbatis2sql -i -t Oracle -s /java/use_ibatis_proj/src -o /tmp
或
xbatis2sql --ibatis --type Oracle --src /java/use_ibatis_proj/src --output /tmp
执行后,结果将保存在 /tmp/result.sql
。
MyBatis
xbatis2sql -m -t Oracle -s /java/use_mybatis_proj/src -o /tmp
或
xbatis2sql --mybatis --type Oracle --src /java/use_mybatis_proj/src --output /tmp
执行后,结果将保存在 /tmp/result.sql
。
示例
MyBatis
mapper-demo.xml 将被转换为 result.sql
。
结果.sql
SELECT "XML -FILE: ./test_data/mapper-demo.xml" AS XML_FILE FROM DUAL;
SELECT "STAT -ID: insert" AS STAT_ID FROM DUAL;
INSERT INTO TAB1(A,B,C,D) VALUES (:?,:?,:?,:?);
SELECT "STAT -ID: insert.selectKey" AS STAT_ID FROM DUAL;
SELECT 1 FROM DUAL;
SELECT "STAT -ID: select" AS STAT_ID FROM DUAL;
SELECT * FROM TAB1 WHERE COLUMN1 IN ( :?);
SELECT "STAT -ID: insert2" AS STAT_ID FROM DUAL;
INSERT INTO TAB2 ( ID)VALUES ( :?);
SELECT "STAT -ID: select2" AS STAT_ID FROM DUAL;
SELECT COLUMN1, COLUMN2 , (SELECT 1 FROM DUAL) FROM TAB3 WHERE COLUMN1 = :? ORDER BY COLUMN2 DESC;
SELECT "STAT -ID: update" AS STAT_ID FROM DUAL;
UPDATE TAB1 SET COLUMN1 = :? WHERE COLUMN1 = :?;
SELECT "STAT -ID: delete" AS STAT_ID FROM DUAL;
DELETE FROM TAB1 WHERE COLUMN1 = :? AND COLUMN2 = :?;
iBATIS
sqlmap-demo.xml 将被转换为 result.sql
。
结果.sql
SELECT "XML -FILE: ./test_data/sqlmap-demo.xml" AS XML_FILE FROM DUAL;
SELECT "STAT -ID: select" AS STAT_ID FROM DUAL;
SELECT COUNT(1) , (SELECT 1 FROM DUAL) FROM __REPLACE_SCHEMA__.TAB1 WHERE COLUMN1 = 'BALABALA' AND COLUMN2 = :?;
SELECT "STAT -ID: update" AS STAT_ID FROM DUAL;
UPDATE __REPLACE_SCHEMA__.TAB2 SET COLUMN2 = :? WHERE COLUMN1 = :?;
SELECT "STAT -ID: delete" AS STAT_ID FROM DUAL;
DELETE FROM __REPLACE_SCHEMA__.TAB1 WHERE COLUMN1 = :?;
SELECT "STAT -ID: insert" AS STAT_ID FROM DUAL;
INSERT INTO __REPLACE_SCHEMA__.TAB1 (COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5) VALUES (:?, :?, :?, :?, :?);
如果处于
MySQL
模式下,:?
将被替换为@1
。
变更日志
查看 变更日志
感谢
感谢 mybatis-mapper-2-sql / sqle
依赖
~4–13MB
~133K SLoC