From 820d59059d04d0dee68123ff04de8ef82bf669f9 Mon Sep 17 00:00:00 2001 From: jayven Date: Tue, 18 Sep 2018 14:44:28 +0800 Subject: [PATCH] Update README with newly added bind directive --- README.md | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b2cad60..3699d85 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ - [Arg directive](#arg-directive) - [Vars directive](#vars-directive) - [Replace directive](#replace-directive) + - [Bind directive](#bind-directive) - [Text directive](#text-directive) - [Wildcard directive](#wildcard-directive) - [How wildcard directive works](#how-wildcard-directive-works) @@ -194,14 +195,14 @@ Another example, if you want to find subordinates of some employees (e.g. `one2m FROM employee AS superior LEFT JOIN employee AS subordinate ON subordinate.superior_id=superior.id WHERE - superior.id IN (1) + superior.id IN () ``` Brief explanation about new directives: - `` specifies an argument of the generated function. - `` specifies arbitary variables that the template can use. `in_query="1"` tells the template that the SQL use `IN` operator. -- `` can replace arbitary statement text. +- `` argument binding. _See [Directives](#directives) for detail._ @@ -306,6 +307,27 @@ Declare arbitary key/value pairs (XML attributes) for template to use. Always re Returns the inner text for the first pass and returns the value in `by` attribute for the second pass. +### Bind directive + +- Name: ``/`` +- Example: `` or `10` +- First pass result: `"NULL"` or inner text of `` element. +- Second pass result: `":id"` + +`` is equivalent to `NULL` and `val` is equivalent to `val`. And the bind name must be an argument name. + +NOTE: `NULL` is not allowed in some clause in MySQL. For example: + +```sql +SELECT * FROM user LIMIT NULL -- Invalid +``` + +Thus if you want to bind an argument in the `LIMIT` clause, you have to write a number explicitly: + +```sql +LIMIT 1 +``` + #### Text directive - Name: ``/`` @@ -455,18 +477,18 @@ An example of `use_template`: user WHERE {{ if ne .id 0 }} - id=1 AND + id= AND {{ end }} {{ if ne (len .name) 0 }} - name="hjw" AND + name= AND {{ end }} {{ if not .birthday.IsZero }} - birthday=NOW() AND + birthday= AND {{ end }} 1 - LIMIT 10 + LIMIT 10 ```