Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 1.65 KB

api_sql.md

File metadata and controls

56 lines (45 loc) · 1.65 KB

SQL XML

test.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqls>
<sqls>
	<sql id="sql1" paramPrefix=":" dynamicPrefix="@">
<!-- this is comment -->
/**
	this is comment
**/
//	this is comment

SELECT field1,field2,field3 FROM table1
WHERE
field1= :param1
<if exists="param2"> and field2 &lt; :param2</if>
<if notexists="param2"> and field2 &lt; 500</if>
<if istrue="param3.substr(0,1)=='x'"> and field3 = :param3 </if>
<if isfalse="param3.substr(0,1)=='x'"> and field3 = 'y' </if>

	</sql>
	<sql id="sql2">
		<include groupId="test" sqlId="sql1"/>
		order by field3, @param4
	</sql>
</sqls>

SQL ID

Every SQL tag should have an Id. The Id must be unique in the SQL XML file. It will be called by db.select or db.change.

Param

You can define params in SQL just write :param .
The paramPrefix attribute of sql tag is an option. You can redefine it if ":" is a must char in your sql.

Dynamic

You can add dynamic sql parts SQL just write @dynamic .
The dynamicPrefix attribute of sql tag is an option. You can redefine it if "@" is a must char in your sql.

If

You can do deffient operation by judging whether a param is existed or not, or a javascript formula is true or not, by setting the exists notexists istrue isfalse attributes. The if tag can be nested.

Include

You can include an existed sql into your sql by setting the groupId sqlId attributes.

Commet

You can write comment in several ways.

Encode

Pay attention to the mark "<". You must write it like "&lt;" to match the xml diction.