Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Latest commit

 

History

History
53 lines (43 loc) · 1.54 KB

api_sql.md

File metadata and controls

53 lines (43 loc) · 1.54 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>
order by field3, @param4
	</sql>
	<sql id="sql2">
	...
	</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.
The if tag can be nested.

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.