Permalink
Browse files

Updated Squel to 1.0.6.

  • Loading branch information...
1 parent e362659 commit a2d5a494b779704bd0436753bcb0435c5d0c7d62 @hiddentao committed Jan 4, 2013
Showing with 46 additions and 17 deletions.
  1. +4 −0 CHANGELOG.md
  2. +22 −9 docs/squel.html
  3. +1 −1 package.json
  4. +18 −6 squel.js
  5. +1 −1 squel.min.js
View
@@ -1,6 +1,10 @@
# Changelog for [squel](https://github.com/hiddentao/squel)
+## 4 Jan 2013 (1.0.6)
+* Squel can now be told to auto-quote table and field names.
+
+
## 3 Nov 2012 (1.0.5)
* DELETE queries can now contain JOINs
View
@@ -104,25 +104,38 @@
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">type</span><span class="si">}</span><span class="s"> must be a string&quot;</span>
<span class="nx">value</span>
- <span class="nv">_sanitizeField: </span><span class="nf">(item) -&gt;</span> <span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;field name&quot;</span>
- <span class="nv">_sanitizeTable: </span><span class="nf">(item) -&gt;</span> <span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;table name&quot;</span>
- <span class="nv">_sanitizeAlias: </span><span class="nf">(item) -&gt;</span> <span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;alias&quot;</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Sanitize the given limit/offset value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_sanitizeLimitOffset: </span><span class="nf">(value) -&gt;</span>
+ <span class="nv">_sanitizeField: </span><span class="nf">(item) -&gt;</span>
+ <span class="nv">sanitized = </span><span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;field name&quot;</span>
+
+ <span class="k">if</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">autoQuoteFieldNames</span>
+ <span class="s">&quot;</span><span class="si">#{</span><span class="nx">@options</span><span class="p">.</span><span class="nx">nameQuoteCharacter</span><span class="si">}#{</span><span class="nx">sanitized</span><span class="si">}#{</span><span class="nx">@options</span><span class="p">.</span><span class="nx">nameQuoteCharacter</span><span class="si">}</span><span class="s">&quot;</span>
+ <span class="k">else</span>
+ <span class="nx">sanitized</span>
+
+ <span class="nv">_sanitizeTable: </span><span class="nf">(item) -&gt;</span>
+ <span class="nv">sanitized = </span><span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;table name&quot;</span>
+
+ <span class="k">if</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">autoQuoteTableNames</span>
+ <span class="s">&quot;</span><span class="si">#{</span><span class="nx">@options</span><span class="p">.</span><span class="nx">nameQuoteCharacter</span><span class="si">}#{</span><span class="nx">sanitized</span><span class="si">}#{</span><span class="nx">@options</span><span class="p">.</span><span class="nx">nameQuoteCharacter</span><span class="si">}</span><span class="s">&quot;</span>
+ <span class="k">else</span>
+ <span class="nx">sanitized</span>
+
+ <span class="nv">_sanitizeAlias: </span><span class="nf">(item) -&gt;</span>
+ <span class="nx">@_sanitizeName</span> <span class="nx">item</span><span class="p">,</span> <span class="s">&quot;alias&quot;</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Sanitize the given limit/offset value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_sanitizeLimitOffset: </span><span class="nf">(value) -&gt;</span>
<span class="nv">value = </span><span class="nb">parseInt</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span>
<span class="k">if</span> <span class="mi">0</span> <span class="o">&gt;</span> <span class="nx">value</span> <span class="o">or</span> <span class="nb">isNaN</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;limit/offset must be &gt;=0&quot;</span>
<span class="nx">value</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Santize the given field value</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_sanitizeValue: </span><span class="nf">(item) -&gt;</span>
<span class="nv">t = </span><span class="k">typeof</span> <span class="nx">item</span>
<span class="k">if</span> <span class="kc">null</span> <span class="o">isnt</span> <span class="nx">item</span> <span class="o">and</span> <span class="s">&quot;string&quot;</span> <span class="o">isnt</span> <span class="nx">t</span> <span class="o">and</span> <span class="s">&quot;number&quot;</span> <span class="o">isnt</span> <span class="nx">t</span> <span class="o">and</span> <span class="s">&quot;boolean&quot;</span> <span class="o">isnt</span> <span class="nx">t</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;field value must be a string, number, boolean or null&quot;</span>
- <span class="nx">item</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Format the given field value for inclusion into the query string</p>
-
-<p>options: see DefaultBuilderOptions</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_formatValue: </span><span class="nf">(value, options) -&gt;</span>
+ <span class="nx">item</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Format the given field value for inclusion into the query string</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_formatValue: </span><span class="nf">(value) -&gt;</span>
<span class="k">if</span> <span class="kc">null</span> <span class="o">is</span> <span class="nx">value</span>
<span class="nv">value = </span><span class="s">&quot;NULL&quot;</span>
<span class="k">else</span> <span class="k">if</span> <span class="s">&quot;boolean&quot;</span> <span class="o">is</span> <span class="k">typeof</span> <span class="nx">value</span>
<span class="nv">value = </span><span class="k">if</span> <span class="nx">value</span> <span class="k">then</span> <span class="s">&quot;TRUE&quot;</span> <span class="k">else</span> <span class="s">&quot;FALSE&quot;</span>
<span class="k">else</span> <span class="k">if</span> <span class="s">&quot;number&quot;</span> <span class="o">isnt</span> <span class="k">typeof</span> <span class="nx">value</span>
- <span class="k">if</span> <span class="o">not</span> <span class="nx">options</span> <span class="o">or</span> <span class="kc">false</span> <span class="o">is</span> <span class="nx">options</span><span class="p">.</span><span class="nx">usingValuePlaceholders</span>
+ <span class="k">if</span> <span class="kc">false</span> <span class="o">is</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">usingValuePlaceholders</span>
<span class="nv">value = </span><span class="s">&quot;&#39;</span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s">&#39;&quot;</span>
<span class="nx">value</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Base class for query builders which support WHERE, ORDER and LIMIT clauses.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">WhereOrderLimit</span> <span class="k">extends</span> <span class="nx">QueryBuilder</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
@@ -298,7 +311,7 @@
<span class="nx">ret</span> <span class="o">+=</span> <span class="nx">tables</span></pre></div> </td> </tr> <tr id="section-71"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-71">&#182;</a> </div> <p>fields</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">fields = </span><span class="s">&quot;&quot;</span>
<span class="k">for</span> <span class="nx">field</span> <span class="k">in</span> <span class="nx">fieldNames</span>
<span class="nx">fields</span> <span class="o">+=</span> <span class="s">&quot;, &quot;</span> <span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">isnt</span> <span class="nx">fields</span>
- <span class="nx">fields</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">field</span><span class="si">}</span><span class="s"> = </span><span class="si">#{</span><span class="nx">@_formatValue</span><span class="p">(</span><span class="nx">@fields</span><span class="p">[</span><span class="nx">field</span><span class="p">],</span> <span class="nx">@options</span><span class="p">)</span><span class="si">}</span><span class="s">&quot;</span>
+ <span class="nx">fields</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">field</span><span class="si">}</span><span class="s"> = </span><span class="si">#{</span><span class="nx">@_formatValue</span><span class="p">(</span><span class="nx">@fields</span><span class="p">[</span><span class="nx">field</span><span class="p">])</span><span class="si">}</span><span class="s">&quot;</span>
<span class="nx">ret</span> <span class="o">+=</span> <span class="s">&quot; SET </span><span class="si">#{</span><span class="nx">fields</span><span class="si">}</span><span class="s">&quot;</span></pre></div> </td> </tr> <tr id="section-72"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-72">&#182;</a> </div> <p>where</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ret</span> <span class="o">+=</span> <span class="nx">@_whereString</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-73"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-73">&#182;</a> </div> <p>order by</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ret</span> <span class="o">+=</span> <span class="nx">@_orderString</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-74"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-74">&#182;</a> </div> <p>limit</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ret</span> <span class="o">+=</span> <span class="nx">@_limitString</span><span class="p">()</span>
<span class="nx">ret</span></pre></div> </td> </tr> <tr id="section-75"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-75">&#182;</a> </div> <p>A DELETE query builder.</p>
@@ -343,7 +356,7 @@
<span class="nx">fields</span> <span class="o">+=</span> <span class="s">&quot;, &quot;</span> <span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">isnt</span> <span class="nx">fields</span>
<span class="nx">fields</span> <span class="o">+=</span> <span class="nx">field</span>
<span class="nx">values</span> <span class="o">+=</span> <span class="s">&quot;, &quot;</span> <span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">isnt</span> <span class="nx">values</span>
- <span class="nx">values</span> <span class="o">+=</span> <span class="nx">@_formatValue</span><span class="p">(</span><span class="nx">@fields</span><span class="p">[</span><span class="nx">field</span><span class="p">],</span> <span class="nx">@options</span><span class="p">)</span>
+ <span class="nx">values</span> <span class="o">+=</span> <span class="nx">@_formatValue</span><span class="p">(</span><span class="nx">@fields</span><span class="p">[</span><span class="nx">field</span><span class="p">])</span>
<span class="s">&quot;INSERT INTO </span><span class="si">#{</span><span class="nx">@table</span><span class="si">}</span><span class="s"> (</span><span class="si">#{</span><span class="nx">fields</span><span class="si">}</span><span class="s">) VALUES (</span><span class="si">#{</span><span class="nx">values</span><span class="si">}</span><span class="s">)&quot;</span></pre></div> </td> </tr> <tr id="section-90"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-90">&#182;</a> </div> <p>Export as easily usable methods.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">_export = </span><span class="p">{</span>
<span class="nv">expr: </span><span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Expression</span>
View
@@ -1,7 +1,7 @@
{
"name": "squel",
"description": "SQL query string builder",
- "version": "1.0.5",
+ "version": "1.0.6",
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
"contributors": [
"Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit a2d5a49

Please sign in to comment.