xbatis2sql

Crates.ioxbatis2sql
lib.rsxbatis2sql
version0.2.5
sourcesrc
created_at2022-11-21 03:52:22.93002
updated_at2023-08-14 16:29:09.320412
descriptioncollect sql statements from iBATIS sqlmap files/MyBatis mapper files
homepagehttps://github.com/hellyguo/xbatis2sql
repositoryhttps://github.com/hellyguo/xbatis2sql
max_upload_size
id719688
size80,113
Helly Guo (hellyguo)

documentation

https://docs.rs/crate/xbatis2sql/latest

README

xbatis2sql

Chinese version

xbatis2sql, collect sql statements from iBATIS sqlmap files/MyBatis mapper files.

Install

cargo install xbatis2sql

Usage

# 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

or

xbatis2sql --ibatis --type Oracle --src /java/use_ibatis_proj/src --output /tmp

After executing, the result will be exist in /tmp/result.sql.

MyBatis

xbatis2sql -m -t Oracle -s /java/use_mybatis_proj/src -o /tmp

or

xbatis2sql --mybatis --type Oracle --src /java/use_mybatis_proj/src --output /tmp

After executing, the result will be exist in /tmp/result.sql.

Sample

MyBatis

mapper-demo.xml will be converted to result.sql.

result.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 will be converted to result.sql.

result.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 (:?, :?, :?, :?, :?);

If under MySQL mode, :? will be replaced with @1.

ChangeLog

See in ChangeLog

Thanks

Thanks to mybatis-mapper-2-sql / sqle

Commit count: 162

cargo fmt