Permalink
Browse files

DELETE builder now also accepts table aliases.

  • Loading branch information...
1 parent bc2c45e commit 2fec2a2455bf69e10f6e74f7697ad886dfeca060 @hiddentao committed Nov 2, 2012
Showing with 64 additions and 19 deletions.
  1. +8 −3 docs/squel.html
  2. +12 −3 squel.js
  3. +1 −1 squel.min.js
  4. +8 −3 src/squel.coffee
  5. +35 −9 test/delete.test.coffee
View
@@ -301,12 +301,17 @@
<p>All the build methods in this object return the object instance for chained method calling purposes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Delete</span> <span class="k">extends</span> <span class="nx">JoinWhereOrderLimit</span>
<span class="nv">table: </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-70"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-70">&#182;</a> </div> <p>The table to delete from.
-Calling this will override any previously set value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">from: </span><span class="p">(</span><span class="nx">table</span><span class="p">)</span> <span class="o">=&gt;</span>
+Calling this will override any previously set value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">from: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">)</span> <span class="o">=&gt;</span>
<span class="nv">table = </span><span class="nx">@_sanitizeTable</span><span class="p">(</span><span class="nx">table</span><span class="p">)</span>
- <span class="vi">@table = </span><span class="nx">table</span>
+ <span class="nv">alias = </span><span class="nx">@_sanitizeAlias</span><span class="p">(</span><span class="nx">alias</span><span class="p">)</span> <span class="k">if</span> <span class="nx">alias</span>
+ <span class="vi">@table =</span>
+ <span class="nv">name: </span><span class="nx">table</span>
+ <span class="nv">alias: </span><span class="nx">alias</span>
<span class="nx">@</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>Get the final fully constructed query string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">toString: </span><span class="o">=&gt;</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>basic checks</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="o">not</span> <span class="nx">@table</span> <span class="k">then</span> <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;from() needs to be called&quot;</span>
- <span class="nv">ret = </span><span class="s">&quot;DELETE FROM </span><span class="si">#{</span><span class="nx">@table</span><span class="si">}</span><span class="s">&quot;</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>joins</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ret</span> <span class="o">+=</span> <span class="nx">@_joinString</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>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-75"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-75">&#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-76"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-76">&#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="nv">ret = </span><span class="s">&quot;DELETE FROM </span><span class="si">#{</span><span class="nx">@table</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="s">&quot;</span>
+
+ <span class="nx">ret</span> <span class="o">+=</span> <span class="s">&quot; `</span><span class="si">#{</span><span class="nx">@table</span><span class="p">.</span><span class="nx">alias</span><span class="si">}</span><span class="s">`&quot;</span> <span class="k">if</span> <span class="nx">@table</span><span class="p">.</span><span class="nx">alias</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>joins</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ret</span> <span class="o">+=</span> <span class="nx">@_joinString</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>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-75"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-75">&#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-76"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-76">&#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-77"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-77">&#182;</a> </div> <p>An INSERT query builder.</p>
View

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

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

0 comments on commit 2fec2a2

Please sign in to comment.