@@ -14,6 +14,7 @@ It comes with 2 great features:
14
14
15
15
- [ ** MagicParameters** : it helps you work with SQL queries that require a variable number of parameters.] ( #parameters )
16
16
- [ ** MagicJoin** : it writes JOINs for you!] ( #joins )
17
+ - [ ** MagicTwig** : use Twig templating in your SQL queries] ( #twig )
17
18
18
19
Installation
19
20
------------
@@ -106,6 +107,62 @@ $completeSql = $magicQuery->build($sql);
106
107
107
108
Want to know more? <a class =" btn btn-primary btn-large " href =" doc/magic_join.md " >Check out the MagicJoin guide!</a >
108
109
110
+ <a name =" twig " ></a >
111
+ Use Twig templating in your SQL queries!
112
+ ----------------------------------------
113
+
114
+ Discarding unused parameters and auto-joining keys is not enough? You have very specific needs? Say hello to
115
+ Twig integration!
116
+
117
+ Using Twig integration, you can directly add Twig conditions right into your SQL.
118
+
119
+ ``` php
120
+ use Mouf\Database\MagicQuery;
121
+
122
+ $sql = "SELECT users.* FROM users {% if isAdmin %} WHERE users.admin = 1 {% endif %}";
123
+
124
+ $magicQuery = new MagicQuery();
125
+ // By default, Twig integration is disabled. You need to enable it.
126
+ $magicQuery->setEnableTwig(true);
127
+
128
+ $completeSql = $magicQuery->build($sql, ['isAdmin' => true]);
129
+ // Parameters are passed to the Twig SQL query, and the SQL query is returned.
130
+ ```
131
+
132
+ <div class =" alert alert-info " ><strong >Heads up!</strong > The Twig integration cannot be used to insert parameters
133
+ into the SQL query. You should use classic SQL parameters for this. This means that instead if writing
134
+ <code >{{ id }}</code >, you should write <code >: id </code >.</div >
135
+
136
+ Want to know more? <a class =" btn btn-primary " href =" doc/magic_twig.md " >Check out the MagicTwig guide!</a >
137
+
138
+ <a name =" twig " ></a >
139
+ Use Twig templating in your SQL queries!
140
+ ----------------------------------------
141
+
142
+ Discarding unused parameters and auto-joining keys is not enough? You have very specific needs? Say hello to
143
+ Twig integration!
144
+
145
+ Using Twig integration, you can directly add Twig conditions right into your SQL.
146
+
147
+ ``` php
148
+ use Mouf\Database\MagicQuery;
149
+
150
+ $sql = "SELECT users.* FROM users {% if isAdmin %} WHERE users.admin = 1 {% endif %}";
151
+
152
+ $magicQuery = new MagicQuery();
153
+ // By default, Twig integration is disabled. You need to enable it.
154
+ $magicQuery->setEnableTwig(true);
155
+
156
+ $completeSql = $magicQuery->build($sql, ['isAdmin' => true]);
157
+ // Parameters are passed to the Twig SQL query, and the SQL query is returned.
158
+ ```
159
+
160
+ <div class =" alert alert-info " ><strong >Heads up!</strong > The Twig integration cannot be used to insert parameters
161
+ into the SQL query. You should use classic SQL parameters for this. This means that instead if writing
162
+ <code >{{ id }}</code >, you should write <code >: id </code >.</div >
163
+
164
+ Want to know more? <a class =" btn btn-primary " href =" doc/magic_twig.md " >Check out the MagicTwig guide!</a >
165
+
109
166
Is it a MySQL only tool?
110
167
------------------------
111
168
0 commit comments