浏览代码

Added section on variables

Andrew 9 年之前
父节点
当前提交
b61c4f6309
共有 1 个文件被更改,包括 25 次插入0 次删除
  1. 25 0
      README.md

+ 25 - 0
README.md

@@ -162,6 +162,31 @@ Customize user name
 Blazer.user_name = :first_name
 Blazer.user_name = :first_name
 ```
 ```
 
 
+## Variables
+
+Create queries with variables
+
+```sql
+SELECT COUNT(*) FROM users WHERE gender = {gender}
+```
+
+### Smart Variables
+
+Supposed you have this query
+
+```sql
+SELECT COUNT(*) FROM users WHERE city_id = {city_id}
+```
+
+Instead of remembering each city’s id, users can select cities by name.
+
+Add a smart variable with:
+
+```yml
+smart_variables:
+  city_id: "SELECT id, name FROM cities ORDER BY name ASC"
+```
+
 ## Charts
 ## Charts
 
 
 Blazer will automatically generate charts based on the types of the columns returned in your query.
 Blazer will automatically generate charts based on the types of the columns returned in your query.