Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved Block.exposedMethods() logic.

Updated README with custom query example.

Bumped version to 1.1
  • Loading branch information...
commit a0cefe8a44eb5ccc1d991bd15e1ace69b918c12e 1 parent 4afea7b
Ramesh Nair authored
5 CHANGELOG.md
View
@@ -1,6 +1,11 @@
# Changelog for [squel](https://github.com/hiddentao/squel)
+## 27 Mar 2013 (1.1)
+* Squel can now be customized to include proprietary commands and queries.
+* AMD support added.
+
+
## 4 Jan 2013 (1.0.6)
* Squel can now be told to auto-quote table and field names.
72 README.md
View
@@ -2,15 +2,15 @@
[![Build Status](https://secure.travis-ci.org/hiddentao/squel.png)](http://travis-ci.org/hiddentao/squel)
-A simple, well tested SQL query string builder for Javascript.
+A flexible and powerful SQL query string builder for Javascript.
## Features
* Works in node.js and in the browser.
-* Supports the construction of all standard SQL queries: SELECT, UPDATE, INSERT and DELETE.
+* Supports the standard SQL queries: SELECT, UPDATE, INSERT and DELETE.
+* Can be customized to support non-standard queries.
* Uses method chaining for ease of use.
-* Well tested (~200 tests).
-* Small: ~3 KB when minified and gzipped.
+* Well tested (~230 tests).
## Installation
@@ -142,6 +142,70 @@ There is also an expression builder which allows you to build complex expression
.join( "test2", null, squel.expr().and("test.id = test2.id") )
.where( squel.expr().or("test = 3").or("test = 4") )
+**Custom queries**
+
+Squel allows you to override the built-in query builders with your own as well as create your own types of queries:
+
+ // ------------------------------------------------------
+ // Setup the PRAGMA query builder
+ // ------------------------------------------------------
+ var util = require('util'); // to use util.inherits() from node.js
+
+ var CommandBlock = function() {};
+ util.inherits(CommandBlock, squel.cls.Block);
+
+ CommandBlock.prototype.compress = function() {
+ this._command = 'compress';
+ };
+
+ CommandBlock.prototype.buildStr = function() {
+ return this._command.toUpperCase();
+ };
+
+
+ // generic parameter block
+ var ParamBlock = function() {};
+ util.inherits(ParamBlock, squel.cls.Block);
+
+ ParamBlock.prototype.param = function(p) {
+ this._p = p;
+ };
+
+ ParamBlock.prototype.buildStr = function() {
+ return this._p;
+ };
+
+
+ // pragma query builder
+ var PragmaQuery = function(options) {
+ var blocks = [
+ new squel.cls.StringBlock(options, 'PRAGMA'),
+ new CommandBlock(),
+ new ParamBlock()
+ ];
+
+ squel.cls.QueryBuilder.call(this, options, blocks);
+ };
+ util.inherits(PragmaQuery, squel.cls.QueryBuilder);
+
+
+ // convenience method (we can override built-in squel methods this way too)
+ squel.pragma = function(options) {
+ return new PragmaQuery(options)
+ };
+
+
+ // ------------------------------------------------------
+ // Build a PRAGMA query
+ // ------------------------------------------------------
+
+ squel.pragma()
+ .compress()
+ .param('test')
+ .toString();
+
+ // 'PRAGMA COMPRESS test'
+
## Documentation
132 docs/squel.html
View
@@ -108,27 +108,27 @@
<span class="nv">nodes: </span><span class="p">[]</span>
<span class="nx">@current</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span> <span class="nx">new_tree</span>
<span class="vi">@current = </span><span class="nx">@current</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span><span class="nx">@current</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
- <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Begin a nested expression and combine it with the current expression using the intersection operator (AND).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">and_begin: </span><span class="o">=&gt;</span>
- <span class="nx">@_begin</span> <span class="s">&#39;AND&#39;</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Begin a nested expression and combine it with the current expression using the union operator (OR).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">or_begin: </span><span class="o">=&gt;</span>
+ <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Begin a nested expression and combine it with the current expression using the intersection operator (AND).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">and_begin: </span><span class="o">-&gt;</span>
+ <span class="nx">@_begin</span> <span class="s">&#39;AND&#39;</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Begin a nested expression and combine it with the current expression using the union operator (OR).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">or_begin: </span><span class="o">-&gt;</span>
<span class="nx">@_begin</span> <span class="s">&#39;OR&#39;</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>End the current compound expression.</p>
-<p>This will throw an error if begin() hasn't been called yet.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">end: </span><span class="o">=&gt;</span>
+<p>This will throw an error if begin() hasn't been called yet.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">end: </span><span class="o">-&gt;</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">@current</span><span class="p">.</span><span class="nx">parent</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;begin() needs to be called&quot;</span>
<span class="vi">@current = </span><span class="nx">@current</span><span class="p">.</span><span class="nx">parent</span>
- <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Combine the current expression with the given expression using the intersection operator (AND).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="o">and:</span> <span class="p">(</span><span class="nx">expr</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Combine the current expression with the given expression using the intersection operator (AND).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="o">and:</span> <span class="nf">(expr) -&gt;</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">expr</span> <span class="o">or</span> <span class="s">&quot;string&quot;</span> <span class="o">isnt</span> <span class="k">typeof</span> <span class="nx">expr</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;expr must be a string&quot;</span>
<span class="nx">@current</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span>
<span class="nv">type: </span><span class="s">&#39;AND&#39;</span>
<span class="nv">expr: </span><span class="nx">expr</span>
- <span class="nx">@</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>Combine the current expression with the given expression using the union operator (OR).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="o">or:</span> <span class="p">(</span><span class="nx">expr</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="nx">@</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>Combine the current expression with the given expression using the union operator (OR).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="o">or:</span> <span class="nf">(expr) -&gt;</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">expr</span> <span class="o">or</span> <span class="s">&quot;string&quot;</span> <span class="o">isnt</span> <span class="k">typeof</span> <span class="nx">expr</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;expr must be a string&quot;</span>
<span class="nx">@current</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span>
<span class="nv">type: </span><span class="s">&#39;OR&#39;</span>
<span class="nv">expr: </span><span class="nx">expr</span>
- <span class="nx">@</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>Get the final fully constructed expression string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">toString: </span><span class="o">=&gt;</span>
+ <span class="nx">@</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>Get the final fully constructed expression string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">toString: </span><span class="o">-&gt;</span>
<span class="k">if</span> <span class="kc">null</span> <span class="o">isnt</span> <span class="nx">@current</span><span class="p">.</span><span class="nx">parent</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;end() needs to be called&quot;</span>
<span class="nx">_toString</span> <span class="nx">@tree</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>Get a string representation of the given expression tree node.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_toString = </span><span class="nf">(node) -&gt;</span>
@@ -163,35 +163,33 @@
<p>@return Object key -> function pairs</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">exposedMethods: </span><span class="o">-&gt;</span>
<span class="nv">ret = </span><span class="p">{}</span>
- <span class="k">for</span> <span class="nx">own</span> <span class="nx">attr</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="nx">@</span>
- <span class="k">if</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">is</span> <span class="s">&quot;function&quot;</span>
- <span class="k">if</span> <span class="nx">attr</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">isnt</span> <span class="s">&#39;_&#39;</span> <span class="o">and</span> <span class="nx">attr</span> <span class="o">isnt</span> <span class="s">&#39;buildStr&#39;</span>
- <span class="nx">ret</span><span class="p">[</span><span class="nx">attr</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span>
+ <span class="k">for</span> <span class="nx">attr</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>only want functions from this class</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">is</span> <span class="s">&quot;function&quot;</span> <span class="o">and</span> <span class="nx">attr</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">isnt</span> <span class="s">&#39;_&#39;</span> <span class="o">and</span> <span class="o">!</span><span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span><span class="o">::</span><span class="p">[</span><span class="nx">attr</span><span class="p">]</span>
+ <span class="nx">ret</span><span class="p">[</span><span class="nx">attr</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span>
- <span class="nx">ret</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Build this block.</p>
+ <span class="nx">ret</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Build this block.</p>
<p>Subclasses may override this method.</p>
<p>@param queryBuilder cls.QueryBuilder a reference to the query builder that owns this block.</p>
<p>@return String the string representing this block</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="s">&#39;&#39;</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>A String which always gets output</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="s">&#39;&#39;</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">&#182;</a> </div> <p>A String which always gets output</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options, str) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
<span class="vi">@str = </span><span class="nx">str</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="nx">@str</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">&#182;</a> </div> <p>Table specifier base class</p>
+ <span class="nx">@str</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Table specifier base class</p>
<p>Additional options
- singleTable - only allow one table to be specified</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">AbstractTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@tables = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Update given table.</p>
+ <span class="vi">@tables = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-44">&#182;</a> </div> <p>Update given table.</p>
<p>An alias may also be specified for the table.</p>
-<p>Concrete subclasses should provide a method which calls this</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_table: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
+<p>Concrete subclasses should provide a method which calls this</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_table: </span><span class="nf">(table, alias = null) -&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="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>
@@ -211,10 +209,10 @@
<span class="nx">tables</span> <span class="o">+=</span> <span class="nx">table</span><span class="p">.</span><span class="nx">name</span>
<span class="nx">tables</span> <span class="o">+=</span> <span class="s">&quot; AS `</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>
- <span class="nx">tables</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-44">&#182;</a> </div> <p>Update Table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">UpdateTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">AbstractTableBlock</span>
- <span class="nv">table: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
- <span class="nx">@_table</span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>FROM table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">FromTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">AbstractTableBlock</span>
- <span class="nv">from: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="nx">tables</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>Update Table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">UpdateTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">AbstractTableBlock</span>
+ <span class="nv">table: </span><span class="nf">(table, alias = null) -&gt;</span>
+ <span class="nx">@_table</span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-46">&#182;</a> </div> <p>FROM table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">FromTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">AbstractTableBlock</span>
+ <span class="nv">from: </span><span class="nf">(table, alias = null) -&gt;</span>
<span class="nx">@_table</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="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
@@ -226,23 +224,23 @@
<span class="nx">tables</span> <span class="o">+=</span> <span class="nx">table</span><span class="p">.</span><span class="nx">name</span>
<span class="nx">tables</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>
- <span class="s">&quot;FROM </span><span class="si">#{</span><span class="nx">tables</span><span class="si">}</span><span class="s">&quot;</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-46">&#182;</a> </div> <p>INTO table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">IntoTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="s">&quot;FROM </span><span class="si">#{</span><span class="nx">tables</span><span class="si">}</span><span class="s">&quot;</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>INTO table</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">IntoTableBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@table = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>Into given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">into: </span><span class="p">(</span><span class="nx">table</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="vi">@table = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>Into given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">into: </span><span class="nf">(table) -&gt;</span>
<span class="vi">@table = </span><span class="nx">@_sanitizeTable</span><span class="p">(</span><span class="nx">table</span><span class="p">)</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
<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;into() needs to be called&quot;</span>
- <span class="s">&quot;INTO </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-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>(SELECT) Get field</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">GetFieldBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="s">&quot;INTO </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-49"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-49">&#182;</a> </div> <p>(SELECT) Get field</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">GetFieldBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@fields = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-49">&#182;</a> </div> <p>Add the given field to the final result set.</p>
+ <span class="vi">@fields = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">&#182;</a> </div> <p>Add the given field to the final result set.</p>
<p>The 'field' parameter does not necessarily have to be a fieldname. It can use database functions too,
e.g. DATE_FORMAT(a.started, "%H")</p>
-<p>An alias may also be specified for this field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">field: </span><span class="p">(</span><span class="nx">field</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
+<p>An alias may also be specified for this field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">field: </span><span class="nf">(field, alias = null) -&gt;</span>
<span class="nv">field = </span><span class="nx">@_sanitizeField</span><span class="p">(</span><span class="nx">field</span><span class="p">)</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>
@@ -257,11 +255,11 @@
<span class="nx">fields</span> <span class="o">+=</span> <span class="nx">field</span><span class="p">.</span><span class="nx">name</span>
<span class="nx">fields</span> <span class="o">+=</span> <span class="s">&quot; AS \&quot;</span><span class="si">#{</span><span class="nx">field</span><span class="p">.</span><span class="nx">alias</span><span class="si">}</span><span class="s">\&quot;&quot;</span> <span class="k">if</span> <span class="nx">field</span><span class="p">.</span><span class="nx">alias</span>
- <span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">is</span> <span class="nx">fields</span> <span class="k">then</span> <span class="s">&quot;*&quot;</span> <span class="k">else</span> <span class="nx">fields</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">&#182;</a> </div> <p>(UPDATE) SET field=value</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">SetFieldBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">is</span> <span class="nx">fields</span> <span class="k">then</span> <span class="s">&quot;*&quot;</span> <span class="k">else</span> <span class="nx">fields</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>(UPDATE) SET field=value</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">SetFieldBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@fields = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>Update the given field with the given value.
-This will override any previously set value for the given field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">set: </span><span class="p">(</span><span class="nx">field</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="vi">@fields = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>Update the given field with the given value.
+This will override any previously set value for the given field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">set: </span><span class="nf">(field, value) -&gt;</span>
<span class="nv">field = </span><span class="nx">@_sanitizeField</span><span class="p">(</span><span class="nx">field</span><span class="p">)</span>
<span class="nv">value = </span><span class="nx">@_sanitizeValue</span><span class="p">(</span><span class="nx">value</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="o">=</span> <span class="nx">value</span>
@@ -276,14 +274,14 @@
<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="si">}</span><span class="s">&quot;</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-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>(INSERT INTO) ... field ... value</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">InsertFieldValueBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">SetFieldBlock</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-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">&#182;</a> </div> <p>(INSERT INTO) ... field ... value</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">InsertFieldValueBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">SetFieldBlock</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
<span class="vi">@fields = </span><span class="p">{}</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
<span class="nv">fieldNames = </span><span class="p">(</span><span class="nx">name</span> <span class="k">for</span> <span class="nx">own</span> <span class="nx">name</span> <span class="k">of</span> <span class="nx">@fields</span><span class="p">)</span>
- <span class="k">if</span> <span class="mi">0</span> <span class="o">&gt;=</span> <span class="nx">fieldNames</span><span class="p">.</span><span class="nx">length</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;set() needs to be called&quot;</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">&#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">if</span> <span class="mi">0</span> <span class="o">&gt;=</span> <span class="nx">fieldNames</span><span class="p">.</span><span class="nx">length</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;set() needs to be called&quot;</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-54">&#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="nv">values = </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>
@@ -291,17 +289,17 @@
<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="s">&quot;(</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-54"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-54">&#182;</a> </div> <p>DISTINCT</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">DistinctBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="s">&quot;(</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-55"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-55">&#182;</a> </div> <p>DISTINCT</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">DistinctBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@useDistinct = </span><span class="kc">false</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-55">&#182;</a> </div> <p>Add the DISTINCT keyword to the query.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">distinct: </span><span class="o">=&gt;</span>
+ <span class="vi">@useDistinct = </span><span class="kc">false</span></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-56">&#182;</a> </div> <p>Add the DISTINCT keyword to the query.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">distinct: </span><span class="o">-&gt;</span>
<span class="vi">@useDistinct = </span><span class="kc">true</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="k">if</span> <span class="nx">@useDistinct</span> <span class="k">then</span> <span class="s">&quot;DISTINCT&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-56">&#182;</a> </div> <p>GROUP BY</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">GroupByBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="k">if</span> <span class="nx">@useDistinct</span> <span class="k">then</span> <span class="s">&quot;DISTINCT&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-57">&#182;</a> </div> <p>GROUP BY</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">GroupByBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@groups = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-57">&#182;</a> </div> <p>Add a GROUP BY transformation for the given field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">group: </span><span class="p">(</span><span class="nx">field</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="vi">@groups = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-58">&#182;</a> </div> <p>Add a GROUP BY transformation for the given field.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">group: </span><span class="nf">(field) -&gt;</span>
<span class="nv">field = </span><span class="nx">@_sanitizeField</span><span class="p">(</span><span class="nx">field</span><span class="p">)</span>
<span class="nx">@groups</span><span class="p">.</span><span class="nx">push</span> <span class="nx">field</span>
@@ -314,34 +312,34 @@
<span class="nx">groups</span> <span class="o">+=</span> <span class="nx">f</span>
<span class="nv">groups = </span><span class="s">&quot;GROUP BY </span><span class="si">#{</span><span class="nx">groups</span><span class="si">}</span><span class="s">&quot;</span>
- <span class="nx">groups</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-58">&#182;</a> </div> <p>OFFSET x</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">OffsetBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="nx">groups</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-59">&#182;</a> </div> <p>OFFSET x</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">OffsetBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@offsets = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-59">&#182;</a> </div> <p>Set the OFFSET transformation.</p>
+ <span class="vi">@offsets = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-60">&#182;</a> </div> <p>Set the OFFSET transformation.</p>
<p>Call this will override the previously set offset for this query. Also note that Passing 0 for 'max' will remove
-the offset.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">offset: </span><span class="p">(</span><span class="nx">start</span><span class="p">)</span> <span class="o">=&gt;</span>
+the offset.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">offset: </span><span class="nf">(start) -&gt;</span>
<span class="nv">start = </span><span class="nx">@_sanitizeLimitOffset</span><span class="p">(</span><span class="nx">start</span><span class="p">)</span>
<span class="vi">@offsets = </span><span class="nx">start</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="k">if</span> <span class="nx">@offsets</span> <span class="k">then</span> <span class="s">&quot;OFFSET </span><span class="si">#{</span><span class="nx">@offsets</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-60">&#182;</a> </div> <p>WHERE</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">WhereBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="k">if</span> <span class="nx">@offsets</span> <span class="k">then</span> <span class="s">&quot;OFFSET </span><span class="si">#{</span><span class="nx">@offsets</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-61">&#182;</a> </div> <p>WHERE</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">WhereBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@wheres = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-61">&#182;</a> </div> <p>Add a WHERE condition.</p>
+ <span class="vi">@wheres = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-62">&#182;</a> </div> <p>Add a WHERE condition.</p>
-<p>When the final query is constructed all the WHERE conditions are combined using the intersection (AND) operator.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">where: </span><span class="p">(</span><span class="nx">condition</span><span class="p">)</span> <span class="o">=&gt;</span>
+<p>When the final query is constructed all the WHERE conditions are combined using the intersection (AND) operator.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">where: </span><span class="nf">(condition) -&gt;</span>
<span class="nv">condition = </span><span class="nx">@_sanitizeCondition</span><span class="p">(</span><span class="nx">condition</span><span class="p">)</span>
<span class="k">if</span> <span class="s">&quot;&quot;</span> <span class="o">isnt</span> <span class="nx">condition</span>
<span class="nx">@wheres</span><span class="p">.</span><span class="nx">push</span> <span class="nx">condition</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="k">if</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="nx">@wheres</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="s">&quot;WHERE (&quot;</span> <span class="o">+</span> <span class="nx">@wheres</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&quot;) AND (&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-62">&#182;</a> </div> <p>ORDER BY</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">OrderByBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="k">if</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="nx">@wheres</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="s">&quot;WHERE (&quot;</span> <span class="o">+</span> <span class="nx">@wheres</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&quot;) AND (&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-63">&#182;</a> </div> <p>ORDER BY</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">OrderByBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@orders = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-63">&#182;</a> </div> <p>Add an ORDER BY transformation for the given field in the given order.</p>
+ <span class="vi">@orders = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-64">&#182;</a> </div> <p>Add an ORDER BY transformation for the given field in the given order.</p>
-<p>To specify descending order pass false for the 'asc' parameter.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">order: </span><span class="p">(</span><span class="nx">field</span><span class="p">,</span> <span class="nv">asc = </span><span class="kc">true</span><span class="p">)</span> <span class="o">=&gt;</span>
+<p>To specify descending order pass false for the 'asc' parameter.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">order: </span><span class="nf">(field, asc = true) -&gt;</span>
<span class="nv">field = </span><span class="nx">@_sanitizeField</span><span class="p">(</span><span class="nx">field</span><span class="p">)</span>
<span class="nx">@orders</span><span class="p">.</span><span class="nx">push</span>
<span class="nv">field: </span><span class="nx">field</span>
@@ -355,22 +353,22 @@
<span class="nx">orders</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">o</span><span class="p">.</span><span class="nx">field</span><span class="si">}</span><span class="s"> </span><span class="si">#{</span><span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">dir</span> <span class="k">then</span> <span class="s">&#39;ASC&#39;</span> <span class="k">else</span> <span class="s">&#39;DESC&#39;</span><span class="si">}</span><span class="s">&quot;</span>
<span class="s">&quot;ORDER BY </span><span class="si">#{</span><span class="nx">orders</span><span class="si">}</span><span class="s">&quot;</span>
<span class="k">else</span>
- <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-64">&#182;</a> </div> <p>LIMIT</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">LimitBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-65">&#182;</a> </div> <p>LIMIT</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">LimitBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@limits = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-65">&#182;</a> </div> <p>Set the LIMIT transformation.</p>
+ <span class="vi">@limits = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-66">&#182;</a> </div> <p>Set the LIMIT transformation.</p>
<p>Call this will override the previously set limit for this query. Also note that Passing 0 for 'max' will remove
-the limit.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">limit: </span><span class="p">(</span><span class="nx">max</span><span class="p">)</span> <span class="o">=&gt;</span>
+the limit.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">limit: </span><span class="nf">(max) -&gt;</span>
<span class="nv">max = </span><span class="nx">@_sanitizeLimitOffset</span><span class="p">(</span><span class="nx">max</span><span class="p">)</span>
<span class="vi">@limits = </span><span class="nx">max</span>
<span class="nv">buildStr: </span><span class="nf">(queryBuilder) -&gt;</span>
- <span class="k">if</span> <span class="nx">@limits</span> <span class="k">then</span> <span class="s">&quot;LIMIT </span><span class="si">#{</span><span class="nx">@limits</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-66">&#182;</a> </div> <p>JOIN</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">JoinBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
+ <span class="k">if</span> <span class="nx">@limits</span> <span class="k">then</span> <span class="s">&quot;LIMIT </span><span class="si">#{</span><span class="nx">@limits</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">else</span> <span class="s">&quot;&quot;</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-67">&#182;</a> </div> <p>JOIN</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">JoinBlock</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Block</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@joins = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-67">&#182;</a> </div> <p>Add a JOIN with the given table.</p>
+ <span class="vi">@joins = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-68">&#182;</a> </div> <p>Add a JOIN with the given table.</p>
<p>'table' is the name of the table to join with.</p>
@@ -379,7 +377,7 @@
<p>'condition' is an optional condition (containing an SQL expression) for the JOIN. If this is an instance of
an expression builder then it gets evaluated straight away.</p>
-<p>'type' must be either one of INNER, OUTER, LEFT or RIGHT. Default is 'INNER'.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">join: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">,</span> <span class="nv">condition = </span><span class="kc">null</span><span class="p">,</span> <span class="nv">type = </span><span class="s">&#39;INNER&#39;</span><span class="p">)</span> <span class="o">=&gt;</span>
+<p>'type' must be either one of INNER, OUTER, LEFT or RIGHT. Default is 'INNER'.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">join: </span><span class="nf">(table, alias = null, condition = null, type = &#39;INNER&#39;) -&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="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="nv">condition = </span><span class="nx">@_sanitizeCondition</span><span class="p">(</span><span class="nx">condition</span><span class="p">)</span> <span class="k">if</span> <span class="nx">condition</span>
@@ -389,9 +387,9 @@
<span class="nv">table: </span><span class="nx">table</span>
<span class="nv">alias: </span><span class="nx">alias</span>
<span class="nv">condition: </span><span class="nx">condition</span>
- <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-68">&#182;</a> </div> <p>Add a LEFT JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">left_join: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">,</span> <span class="nv">condition = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
- <span class="nx">@join</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="s">&#39;LEFT&#39;</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-69">&#182;</a> </div> <p>Add a RIGHT JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">right_join: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">,</span> <span class="nv">condition = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
- <span class="nx">@join</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="s">&#39;RIGHT&#39;</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>Add an OUTER JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">outer_join: </span><span class="p">(</span><span class="nx">table</span><span class="p">,</span> <span class="nv">alias = </span><span class="kc">null</span><span class="p">,</span> <span class="nv">condition = </span><span class="kc">null</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="nx">@</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-69">&#182;</a> </div> <p>Add a LEFT JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">left_join: </span><span class="nf">(table, alias = null, condition = null) -&gt;</span>
+ <span class="nx">@join</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="s">&#39;LEFT&#39;</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>Add a RIGHT JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">right_join: </span><span class="nf">(table, alias = null, condition = null) -&gt;</span>
+ <span class="nx">@join</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="s">&#39;RIGHT&#39;</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>Add an OUTER JOIN with the given table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">outer_join: </span><span class="nf">(table, alias = null, condition = null) -&gt;</span>
<span class="nx">@join</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">alias</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="s">&#39;OUTER&#39;</span>
@@ -404,36 +402,36 @@
<span class="nx">joins</span> <span class="o">+=</span> <span class="s">&quot; `</span><span class="si">#{</span><span class="nx">j</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">j</span><span class="p">.</span><span class="nx">alias</span>
<span class="nx">joins</span> <span class="o">+=</span> <span class="s">&quot; ON (</span><span class="si">#{</span><span class="nx">j</span><span class="p">.</span><span class="nx">condition</span><span class="si">}</span><span class="s">)&quot;</span> <span class="k">if</span> <span class="nx">j</span><span class="p">.</span><span class="nx">condition</span>
- <span class="nx">joins</span></pre></div> </td> </tr> <tr id="section-71"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-71">&#182;</a> </div> <h2>---------------------------------------------------------------------------------------------------------</h2>
+ <span class="nx">joins</span></pre></div> </td> </tr> <tr id="section-72"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-72">&#182;</a> </div> <h2>---------------------------------------------------------------------------------------------------------</h2>
<h2>Query builders</h2>
-<hr /> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-72"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-72">&#182;</a> </div> <p>Query builder base class</p>
+<hr /> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-73"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-73">&#182;</a> </div> <p>Query builder base class</p>
<p>Note that the query builder does not check the final query string for correctness.</p>
-<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">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">BaseBuilder</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>Constructor</p>
+<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">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">BaseBuilder</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>Constructor</p>
<p>blocks - array of cls.BaseBuilderBlock instances to build the query with.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(options, blocks) -&gt;</span>
<span class="k">super</span> <span class="nx">options</span>
- <span class="vi">@blocks = </span><span class="nx">blocks</span> <span class="o">or</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>Copy exposed methods into myself</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="nx">block</span> <span class="k">in</span> <span class="nx">@blocks</span>
+ <span class="vi">@blocks = </span><span class="nx">blocks</span> <span class="o">or</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>Copy exposed methods into myself</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="nx">block</span> <span class="k">in</span> <span class="nx">@blocks</span>
<span class="k">for</span> <span class="nx">methodName</span><span class="p">,</span> <span class="nx">methodBody</span> <span class="k">of</span> <span class="nx">block</span><span class="p">.</span><span class="nx">exposedMethods</span><span class="p">()</span>
<span class="k">if</span> <span class="nx">@</span><span class="p">[</span><span class="nx">methodName</span><span class="p">]</span><span class="o">?</span>
<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">@_getObjectClassName</span><span class="p">(</span><span class="nx">@</span><span class="p">)</span><span class="si">}</span><span class="s"> already has a builder method called: </span><span class="si">#{</span><span class="nx">methodName</span><span class="si">}</span><span class="s">&quot;</span>
- <span class="p">(</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">body</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="p">(</span> <span class="p">(</span><span class="nx">block</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">body</span><span class="p">)</span> <span class="o">=&gt;</span>
<span class="nx">@</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">=&gt;</span>
- <span class="nx">body</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">@</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
+ <span class="nx">body</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">block</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
<span class="nx">@</span>
- <span class="p">)(</span><span class="nx">methodName</span><span class="p">,</span> <span class="nx">methodBody</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>Update query builder options</p>
+ <span class="p">)(</span><span class="nx">block</span><span class="p">,</span> <span class="nx">methodName</span><span class="p">,</span> <span class="nx">methodBody</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>Update query builder options</p>
<p>This will update the options for all blocks too. Use this method with caution as it allows you to change the
behaviour of your query builder mid-build.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">updateOptions: </span><span class="nf">(options) -&gt;</span>
<span class="vi">@options = </span><span class="nx">_extend</span><span class="p">({},</span> <span class="nx">@options</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span>
<span class="k">for</span> <span class="nx">block</span> <span class="k">in</span> <span class="nx">@blocks</span>
- <span class="nv">block.options = </span><span class="nx">_extend</span><span class="p">({},</span> <span class="nx">block</span><span class="p">.</span><span class="nx">options</span><span class="p">,</span> <span class="nx">options</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>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>
- <span class="p">(</span><span class="nx">block</span><span class="p">.</span><span class="nx">buildStr</span><span class="p">(</span><span class="nx">@</span><span class="p">)</span> <span class="k">for</span> <span class="nx">block</span> <span class="k">in</span> <span class="nx">@blocks</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span> <span class="nf">(v) -&gt;</span> <span class="k">return</span> <span class="p">(</span><span class="mi">0</span> <span class="o">&lt;</span> <span class="nx">v</span><span class="p">.</span><span class="nx">length</span><span class="p">)).</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">)</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>SELECT query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Select</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
+ <span class="nv">block.options = </span><span class="nx">_extend</span><span class="p">({},</span> <span class="nx">block</span><span class="p">.</span><span class="nx">options</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</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>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>
+ <span class="p">(</span><span class="nx">block</span><span class="p">.</span><span class="nx">buildStr</span><span class="p">(</span><span class="nx">@</span><span class="p">)</span> <span class="k">for</span> <span class="nx">block</span> <span class="k">in</span> <span class="nx">@blocks</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span> <span class="nf">(v) -&gt;</span> <span class="k">return</span> <span class="p">(</span><span class="mi">0</span> <span class="o">&lt;</span> <span class="nx">v</span><span class="p">.</span><span class="nx">length</span><span class="p">)).</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-78">&#182;</a> </div> <p>SELECT query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Select</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="nv">blocks = </span><span class="p">[</span>
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="s">&#39;SELECT&#39;</span><span class="p">),</span>
@@ -448,7 +446,7 @@
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">OffsetBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
<span class="p">]</span>
- <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-78">&#182;</a> </div> <p>UPDATE query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Update</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
+ <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-79">&#182;</a> </div> <p>UPDATE query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Update</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="nv">blocks = </span><span class="p">[</span>
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="s">&#39;UPDATE&#39;</span><span class="p">),</span>
@@ -459,7 +457,7 @@
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">LimitBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
<span class="p">]</span>
- <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-79">&#182;</a> </div> <p>DELETE query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Delete</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
+ <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-80"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-80">&#182;</a> </div> <p>DELETE query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Delete</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="nv">blocks = </span><span class="p">[</span>
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="s">&#39;DELETE&#39;</span><span class="p">),</span>
@@ -470,7 +468,7 @@
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">LimitBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">),</span>
<span class="p">]</span>
- <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-80"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-80">&#182;</a> </div> <p>An INSERT query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Insert</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
+ <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-81"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-81">&#182;</a> </div> <p>An INSERT query builder.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Insert</span> <span class="k">extends</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">QueryBuilder</span>
<span class="nv">constructor: </span><span class="nf">(options) -&gt;</span>
<span class="nv">blocks = </span><span class="p">[</span>
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">StringBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="s">&#39;INSERT&#39;</span><span class="p">),</span>
@@ -478,7 +476,7 @@
<span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">InsertFieldValueBlock</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
<span class="p">]</span>
- <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-81"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-81">&#182;</a> </div> <h2>---------------------------------------------------------------------------------------------------------</h2>
+ <span class="k">super</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">blocks</span></pre></div> </td> </tr> <tr id="section-82"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-82">&#182;</a> </div> <h2>---------------------------------------------------------------------------------------------------------</h2>
<h2>Exported API</h2>
@@ -487,10 +485,10 @@
<span class="nv">select: </span><span class="nf">(options) -&gt;</span> <span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Select</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
<span class="nv">update: </span><span class="nf">(options) -&gt;</span> <span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Update</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
<span class="nv">insert: </span><span class="nf">(options) -&gt;</span> <span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Insert</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span>
- <span class="k">delete</span><span class="o">:</span> <span class="nf">(options) -&gt;</span> <span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Delete</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-82"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-82">&#182;</a> </div> <p>defaults</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-83"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-83">&#182;</a> </div> <p>aliases</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">squel.remove = </span><span class="nx">squel</span><span class="p">.</span><span class="k">delete</span></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-84">&#182;</a> </div> <p>classes</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">squel.cls = </span><span class="nx">cls</span></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-85">&#182;</a> </div> <p>AMD</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">define</span><span class="o">?</span><span class="p">.</span><span class="nx">amd</span>
+ <span class="k">delete</span><span class="o">:</span> <span class="nf">(options) -&gt;</span> <span class="k">new</span> <span class="nx">cls</span><span class="p">.</span><span class="nx">Delete</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-83"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-83">&#182;</a> </div> <p>defaults</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-84">&#182;</a> </div> <p>aliases</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">squel.remove = </span><span class="nx">squel</span><span class="p">.</span><span class="k">delete</span></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-85">&#182;</a> </div> <p>classes</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">squel.cls = </span><span class="nx">cls</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-86">&#182;</a> </div> <p>AMD</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">define</span><span class="o">?</span><span class="p">.</span><span class="nx">amd</span>
<span class="nx">define</span> <span class="o">-&gt;</span>
- <span class="k">return</span> <span class="nx">squel</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-86">&#182;</a> </div> <p>CommonJS</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span> <span class="k">if</span> <span class="nx">module</span><span class="o">?</span><span class="p">.</span><span class="nx">exports</span>
- <span class="nv">module.exports = </span><span class="nx">squel</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-87">&#182;</a> </div> <p>Browser</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span>
+ <span class="k">return</span> <span class="nx">squel</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-87">&#182;</a> </div> <p>CommonJS</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span> <span class="k">if</span> <span class="nx">module</span><span class="o">?</span><span class="p">.</span><span class="nx">exports</span>
+ <span class="nv">module.exports = </span><span class="nx">squel</span></pre></div> </td> </tr> <tr id="section-88"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-88">&#182;</a> </div> <p>Browser</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span>
<span class="nb">window</span><span class="o">?</span><span class="p">.</span><span class="nv">squel = </span><span class="nx">squel</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
2  package.json
View
@@ -1,7 +1,7 @@
{
"name": "squel",
"description": "SQL query string builder",
- "version": "1.0.7",
+ "version": "1.1",
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
"contributors": [
"Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
49 squel.js
View
@@ -30,8 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
var cls, squel, _extend,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
cls = {};
@@ -179,18 +178,6 @@ OTHER DEALINGS IN THE SOFTWARE.
Expression.prototype.current = null;
function Expression() {
- this.toString = __bind(this.toString, this);
-
- this.or = __bind(this.or, this);
-
- this.and = __bind(this.and, this);
-
- this.end = __bind(this.end, this);
-
- this.or_begin = __bind(this.or_begin, this);
-
- this.and_begin = __bind(this.and_begin, this);
-
var _this = this;
this.tree = {
parent: null,
@@ -295,12 +282,9 @@ OTHER DEALINGS IN THE SOFTWARE.
var attr, ret, value;
ret = {};
for (attr in this) {
- if (!__hasProp.call(this, attr)) continue;
value = this[attr];
- if (typeof value === "function") {
- if (attr.charAt(0) !== '_' && attr !== 'buildStr') {
- ret[attr] = value;
- }
+ if (typeof value === "function" && attr.charAt(0) !== '_' && !cls.Block.prototype[attr]) {
+ ret[attr] = value;
}
}
return ret;
@@ -336,7 +320,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(AbstractTableBlock, _super);
function AbstractTableBlock(options) {
- this._table = __bind(this._table, this);
AbstractTableBlock.__super__.constructor.call(this, options);
this.tables = [];
}
@@ -387,7 +370,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(UpdateTableBlock, _super);
function UpdateTableBlock() {
- this.table = __bind(this.table, this);
return UpdateTableBlock.__super__.constructor.apply(this, arguments);
}
@@ -407,7 +389,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(FromTableBlock, _super);
function FromTableBlock() {
- this.from = __bind(this.from, this);
return FromTableBlock.__super__.constructor.apply(this, arguments);
}
@@ -447,7 +428,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(IntoTableBlock, _super);
function IntoTableBlock(options) {
- this.into = __bind(this.into, this);
IntoTableBlock.__super__.constructor.call(this, options);
this.table = null;
}
@@ -472,7 +452,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(GetFieldBlock, _super);
function GetFieldBlock(options) {
- this.field = __bind(this.field, this);
GetFieldBlock.__super__.constructor.call(this, options);
this.fields = [];
}
@@ -521,7 +500,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(SetFieldBlock, _super);
function SetFieldBlock(options) {
- this.set = __bind(this.set, this);
SetFieldBlock.__super__.constructor.call(this, options);
this.fields = {};
}
@@ -612,7 +590,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(DistinctBlock, _super);
function DistinctBlock(options) {
- this.distinct = __bind(this.distinct, this);
DistinctBlock.__super__.constructor.call(this, options);
this.useDistinct = false;
}
@@ -638,7 +615,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(GroupByBlock, _super);
function GroupByBlock(options) {
- this.group = __bind(this.group, this);
GroupByBlock.__super__.constructor.call(this, options);
this.groups = [];
}
@@ -674,7 +650,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(OffsetBlock, _super);
function OffsetBlock(options) {
- this.offset = __bind(this.offset, this);
OffsetBlock.__super__.constructor.call(this, options);
this.offsets = null;
}
@@ -701,7 +676,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(WhereBlock, _super);
function WhereBlock(options) {
- this.where = __bind(this.where, this);
WhereBlock.__super__.constructor.call(this, options);
this.wheres = [];
}
@@ -730,7 +704,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(OrderByBlock, _super);
function OrderByBlock(options) {
- this.order = __bind(this.order, this);
OrderByBlock.__super__.constructor.call(this, options);
this.orders = [];
}
@@ -773,7 +746,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(LimitBlock, _super);
function LimitBlock(options) {
- this.limit = __bind(this.limit, this);
LimitBlock.__super__.constructor.call(this, options);
this.limits = null;
}
@@ -800,13 +772,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(JoinBlock, _super);
function JoinBlock(options) {
- this.outer_join = __bind(this.outer_join, this);
-
- this.right_join = __bind(this.right_join, this);
-
- this.left_join = __bind(this.left_join, this);
-
- this.join = __bind(this.join, this);
JoinBlock.__super__.constructor.call(this, options);
this.joins = [];
}
@@ -896,8 +861,6 @@ OTHER DEALINGS IN THE SOFTWARE.
__extends(QueryBuilder, _super);
function QueryBuilder(options, blocks) {
- this.toString = __bind(this.toString, this);
-
var block, methodBody, methodName, _fn, _i, _len, _ref, _ref1,
_this = this;
QueryBuilder.__super__.constructor.call(this, options);
@@ -906,9 +869,9 @@ OTHER DEALINGS IN THE SOFTWARE.
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
block = _ref[_i];
_ref1 = block.exposedMethods();
- _fn = function(name, body) {
+ _fn = function(block, name, body) {
return _this[name] = function() {
- body.apply(_this, arguments);
+ body.apply(block, arguments);
return _this;
};
};
@@ -917,7 +880,7 @@ OTHER DEALINGS IN THE SOFTWARE.
if (this[methodName] != null) {
throw new Error("" + (this._getObjectClassName(this)) + " already has a builder method called: " + methodName);
}
- _fn(methodName, methodBody);
+ _fn(block, methodName, methodBody);
}
}
}
2  squel.min.js
View
@@ -22,4 +22,4 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-*/(function(){var e,t,n,r=[].slice,i={}.hasOwnProperty,s=function(e,t){function r(){this.constructor=e}for(var n in t)i.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},o=function(e,t){return function(){return e.apply(t,arguments)}};e={},n=function(){var e,t,n,s,o,u,a;e=arguments[0],n=2<=arguments.length?r.call(arguments,1):[];if(n)for(u=0,a=n.length;u<a;u++){s=n[u];if(s)for(t in s){if(!i.call(s,t))continue;o=s[t],e[t]=o}}return e},e.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,nameQuoteCharacter:"`",usingValuePlaceholders:!1},e.Cloneable=function(){function e(){}return e.prototype.clone=function(){var e;return e=new this.constructor,n(e,JSON.parse(JSON.stringify(this)))},e}(),e.BaseBuilder=function(t){function r(t){this.options=n({},e.DefaultQueryBuilderOptions,t)}return s(r,t),r.prototype._getObjectClassName=function(e){var t;if(e&&e.constructor&&e.constructor.toString){t=e.constructor.toString().match(/function\s*(\w+)/);if(t&&t.length===2)return t[1]}return void 0},r.prototype._sanitizeCondition=function(e){var t,n;n=typeof e,t=this._getObjectClassName(e);if("Expression"!==t&&"string"!==n)throw new Error("condition must be a string or Expression instance");if("Expression"===n||"Expression"===t)e=e.toString();return e},r.prototype._sanitizeName=function(e,t){if("string"!=typeof e)throw new Error(""+t+" must be a string");return e},r.prototype._sanitizeField=function(e){var t;return t=this._sanitizeName(e,"field name"),this.options.autoQuoteFieldNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},r.prototype._sanitizeTable=function(e){var t;return t=this._sanitizeName(e,"table name"),this.options.autoQuoteTableNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},r.prototype._sanitizeAlias=function(e){return this._sanitizeName(e,"alias")},r.prototype._sanitizeLimitOffset=function(e){e=parseInt(e);if(0>e||isNaN(e))throw new Error("limit/offset must be >=0");return e},r.prototype._sanitizeValue=function(e){var t;t=typeof e;if(null!==e&&"string"!==t&&"number"!==t&&"boolean"!==t)throw new Error("field value must be a string, number, boolean or null");return e},r.prototype._formatValue=function(e){return null===e?e="NULL":"boolean"==typeof e?e=e?"TRUE":"FALSE":"number"!=typeof e&&!1===this.options.usingValuePlaceholders&&(e="'"+e+"'"),e},r}(e.Cloneable),e.Expression=function(){function t(){this.toString=o(this.toString,this),this.or=o(this.or,this),this.and=o(this.and,this),this.end=o(this.end,this),this.or_begin=o(this.or_begin,this),this.and_begin=o(this.and_begin,this);var e=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(t){var n;return n={type:t,parent:e.current,nodes:[]},e.current.nodes.push(n),e.current=e.current.nodes[e.current.nodes.length-1],e}}var e;return t.prototype.tree=null,t.prototype.current=null,t.prototype.and_begin=function(){return this._begin("AND")},t.prototype.or_begin=function(){return this._begin("OR")},t.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},t.prototype.and=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:e}),this},t.prototype.or=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:e}),this},t.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return e(this.tree)},e=function(t){var n,r,i,s,o,u;i="",u=t.nodes;for(s=0,o=u.length;s<o;s++)n=u[s],n.expr!=null?r=n.expr:(r=e(n),""!==r&&(r="("+r+")")),""!==r&&(""!==i&&(i+=" "+n.type+" "),i+=r);return i},t}(),e.Block=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.exposedMethods=function(){var e,t,n;t={};for(e in this){if(!i.call(this,e))continue;n=this[e],typeof n=="function"&&e.charAt(0)!=="_"&&e!=="buildStr"&&(t[e]=n)}return t},t.prototype.buildStr=function(e){return""},t}(e.BaseBuilder),e.StringBlock=function(e){function t(e,n){t.__super__.constructor.call(this,e),this.str=n}return s(t,e),t.prototype.buildStr=function(e){return this.str},t}(e.Block),e.AbstractTableBlock=function(e){function t(e){this._table=o(this._table,this),t.__super__.constructor.call(this,e),this.tables=[]}return s(t,e),t.prototype._table=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.options.singleTable&&(this.tables=[]),this.tables.push({name:e,alias:t})},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0>=this.tables.length)throw new Error("table() needs to be called");n="",s=this.tables;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=" AS `"+t.alias+"`");return n},t}(e.Block),e.UpdateTableBlock=function(e){function t(){return this.table=o(this.table,this),t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.table=function(e,t){return t==null&&(t=null),this._table(e,t)},t}(e.AbstractTableBlock),e.FromTableBlock=function(e){function t(){return this.from=o(this.from,this),t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.from=function(e,t){return t==null&&(t=null),this._table(e,t)},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0>=this.tables.length)throw new Error("from() needs to be called");n="",s=this.tables;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=" `"+t.alias+"`");return"FROM "+n},t}(e.AbstractTableBlock),e.IntoTableBlock=function(e){function t(e){this.into=o(this.into,this),t.__super__.constructor.call(this,e),this.table=null}return s(t,e),t.prototype.into=function(e){return this.table=this._sanitizeTable(e)},t.prototype.buildStr=function(e){if(!this.table)throw new Error("into() needs to be called");return"INTO "+this.table},t}(e.Block),e.GetFieldBlock=function(e){function t(e){this.field=o(this.field,this),t.__super__.constructor.call(this,e),this.fields=[]}return s(t,e),t.prototype.field=function(e,t){return t==null&&(t=null),e=this._sanitizeField(e),t&&(t=this._sanitizeAlias(t)),this.fields.push({name:e,alias:t})},t.prototype.buildStr=function(e){var t,n,r,i,s;n="",s=this.fields;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=' AS "'+t.alias+'"');return""===n?"*":n},t}(e.Block),e.SetFieldBlock=function(e){function t(e){this.set=o(this.set,this),t.__super__.constructor.call(this,e),this.fields={}}return s(t,e),t.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},t.prototype.buildStr=function(e){var t,n,r,s,o;n=function(){var e,n;e=this.fields,n=[];for(t in e){if(!i.call(e,t))continue;n.push(t)}return n}.call(this);if(0>=n.length)throw new Error("set() needs to be called");r="";for(s=0,o=n.length;s<o;s++)t=n[s],""!==r&&(r+=", "),r+=""+t+" = "+this._formatValue(this.fields[t]);return"SET "+r},t}(e.Block),e.InsertFieldValueBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.fields={}}return s(t,e),t.prototype.buildStr=function(e){var t,n,r,s,o,u,a;n=function(){var e,t;e=this.fields,t=[];for(s in e){if(!i.call(e,s))continue;t.push(s)}return t}.call(this);if(0>=n.length)throw new Error("set() needs to be called");r="",o="";for(u=0,a=n.length;u<a;u++)t=n[u],""!==r&&(r+=", "),r+=t,""!==o&&(o+=", "),o+=this._formatValue(this.fields[t]);return"("+r+") VALUES ("+o+")"},t}(e.SetFieldBlock),e.DistinctBlock=function(e){function t(e){this.distinct=o(this.distinct,this),t.__super__.constructor.call(this,e),this.useDistinct=!1}return s(t,e),t.prototype.distinct=function(){return this.useDistinct=!0},t.prototype.buildStr=function(e){return this.useDistinct?"DISTINCT":""},t}(e.Block),e.GroupByBlock=function(e){function t(e){this.group=o(this.group,this),t.__super__.constructor.call(this,e),this.groups=[]}return s(t,e),t.prototype.group=function(e){return e=this._sanitizeField(e),this.groups.push(e)},t.prototype.buildStr=function(e){var t,n,r,i,s;n="";if(0<this.groups.length){s=this.groups;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t;n="GROUP BY "+n}return n},t}(e.Block),e.OffsetBlock=function(e){function t(e){this.offset=o(this.offset,this),t.__super__.constructor.call(this,e),this.offsets=null}return s(t,e),t.prototype.offset=function(e){return e=this._sanitizeLimitOffset(e),this.offsets=e},t.prototype.buildStr=function(e){return this.offsets?"OFFSET "+this.offsets:""},t}(e.Block),e.WhereBlock=function(e){function t(e){this.where=o(this.where,this),t.__super__.constructor.call(this,e),this.wheres=[]}return s(t,e),t.prototype.where=function(e){e=this._sanitizeCondition(e);if(""!==e)return this.wheres.push(e)},t.prototype.buildStr=function(e){return 0<this.wheres.length?"WHERE ("+this.wheres.join(") AND (")+")":""},t}(e.Block),e.OrderByBlock=function(e){function t(e){this.order=o(this.order,this),t.__super__.constructor.call(this,e),this.orders=[]}return s(t,e),t.prototype.order=function(e,t){return t==null&&(t=!0),e=this._sanitizeField(e),this.orders.push({field:e,dir:t?!0:!1})},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0<this.orders.length){n="",s=this.orders;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=""+t.field+" "+(t.dir?"ASC":"DESC");return"ORDER BY "+n}return""},t}(e.Block),e.LimitBlock=function(e){function t(e){this.limit=o(this.limit,this),t.__super__.constructor.call(this,e),this.limits=null}return s(t,e),t.prototype.limit=function(e){return e=this._sanitizeLimitOffset(e),this.limits=e},t.prototype.buildStr=function(e){return this.limits?"LIMIT "+this.limits:""},t}(e.Block),e.JoinBlock=function(e){function t(e){this.outer_join=o(this.outer_join,this),this.right_join=o(this.right_join,this),this.left_join=o(this.left_join,this),this.join=o(this.join,this),t.__super__.constructor.call(this,e),this.joins=[]}return s(t,e),t.prototype.join=function(e,t,n,r){return t==null&&(t=null),n==null&&(n=null),r==null&&(r="INNER"),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),n&&(n=this._sanitizeCondition(n)),this.joins.push({type:r,table:e,alias:t,condition:n}),this},t.prototype.left_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"LEFT")},t.prototype.right_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"RIGHT")},t.prototype.outer_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"OUTER")},t.prototype.buildStr=function(e){var t,n,r,i,s;n="",s=this.joins||[];for(r=0,i=s.length;r<i;r++)t=s[r],n!==""&&(n+=" "),n+=""+t.type+" JOIN "+t.table,t.alias&&(n+=" `"+t.alias+"`"),t.condition&&(n+=" ON ("+t.condition+")");return n},t}(e.Block),e.QueryBuilder=function(e){function t(e,n){this.toString=o(this.toString,this);var r,i,s,u,a,f,l,c,h=this;t.__super__.constructor.call(this,e),this.blocks=n||[],l=this.blocks;for(a=0,f=l.length;a<f;a++){r=l[a],c=r.exposedMethods(),u=function(e,t){return h[e]=function(){return t.apply(h,arguments),h}};for(s in c){i=c[s];if(this[s]!=null)throw new Error(""+this._getObjectClassName(this)+" already has a builder method called: "+s);u(s,i)}}}return s(t,e),t.prototype.updateOptions=function(e){var t,r,i,s,o;this.options=n({},this.options,e),s=this.blocks,o=[];for(r=0,i=s.length;r<i;r++)t=s[r],o.push(t.options=n({},t.options,e));return o},t.prototype.toString=function(){var e;return function(){var t,n,r,i;r=this.blocks,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.buildStr(this));return i}.call(this).filter(function(e){return 0<e.length}).join(" ")},t}(e.BaseBuilder),e.Select=function(t){function n(t){var r;r=[new e.StringBlock(t,"SELECT"),new e.DistinctBlock(t),new e.GetFieldBlock(t),new e.FromTableBlock(t),new e.JoinBlock(t),new e.WhereBlock(t),new e.GroupByBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t),new e.OffsetBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),e.Update=function(t){function n(t){var r;r=[new e.StringBlock(t,"UPDATE"),new e.UpdateTableBlock(t),new e.SetFieldBlock(t),new e.WhereBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),e.Delete=function(t){function r(t){var i;i=[new e.StringBlock(t,"DELETE"),new e.FromTableBlock(n({},t,{singleTable:!0})),new e.JoinBlock(t),new e.WhereBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t)],r.__super__.constructor.call(this,t,i)}return s(r,t),r}(e.QueryBuilder),e.Insert=function(t){function n(t){var r;r=[new e.StringBlock(t,"INSERT"),new e.IntoTableBlock(t),new e.InsertFieldValueBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),t={expr:function(){return new e.Expression},select:function(t){return new e.Select(t)},update:function(t){return new e.Update(t)},insert:function(t){return new e.Insert(t)},"delete":function(t){return new e.Delete(t)}},t.remove=t["delete"],t.cls=e,(typeof define!="undefined"&&define!==null?define.amd:void 0)?define(function(){return t}):(typeof module!="undefined"&&module!==null?module.exports:void 0)?module.exports=t:typeof window!="undefined"&&window!==null&&(window.squel=t)}).call(this);
+*/(function(){var e,t,n,r=[].slice,i={}.hasOwnProperty,s=function(e,t){function r(){this.constructor=e}for(var n in t)i.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};e={},n=function(){var e,t,n,s,o,u,a;e=arguments[0],n=2<=arguments.length?r.call(arguments,1):[];if(n)for(u=0,a=n.length;u<a;u++){s=n[u];if(s)for(t in s){if(!i.call(s,t))continue;o=s[t],e[t]=o}}return e},e.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,nameQuoteCharacter:"`",usingValuePlaceholders:!1},e.Cloneable=function(){function e(){}return e.prototype.clone=function(){var e;return e=new this.constructor,n(e,JSON.parse(JSON.stringify(this)))},e}(),e.BaseBuilder=function(t){function r(t){this.options=n({},e.DefaultQueryBuilderOptions,t)}return s(r,t),r.prototype._getObjectClassName=function(e){var t;if(e&&e.constructor&&e.constructor.toString){t=e.constructor.toString().match(/function\s*(\w+)/);if(t&&t.length===2)return t[1]}return void 0},r.prototype._sanitizeCondition=function(e){var t,n;n=typeof e,t=this._getObjectClassName(e);if("Expression"!==t&&"string"!==n)throw new Error("condition must be a string or Expression instance");if("Expression"===n||"Expression"===t)e=e.toString();return e},r.prototype._sanitizeName=function(e,t){if("string"!=typeof e)throw new Error(""+t+" must be a string");return e},r.prototype._sanitizeField=function(e){var t;return t=this._sanitizeName(e,"field name"),this.options.autoQuoteFieldNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},r.prototype._sanitizeTable=function(e){var t;return t=this._sanitizeName(e,"table name"),this.options.autoQuoteTableNames?""+this.options.nameQuoteCharacter+t+this.options.nameQuoteCharacter:t},r.prototype._sanitizeAlias=function(e){return this._sanitizeName(e,"alias")},r.prototype._sanitizeLimitOffset=function(e){e=parseInt(e);if(0>e||isNaN(e))throw new Error("limit/offset must be >=0");return e},r.prototype._sanitizeValue=function(e){var t;t=typeof e;if(null!==e&&"string"!==t&&"number"!==t&&"boolean"!==t)throw new Error("field value must be a string, number, boolean or null");return e},r.prototype._formatValue=function(e){return null===e?e="NULL":"boolean"==typeof e?e=e?"TRUE":"FALSE":"number"!=typeof e&&!1===this.options.usingValuePlaceholders&&(e="'"+e+"'"),e},r}(e.Cloneable),e.Expression=function(){function t(){var e=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(t){var n;return n={type:t,parent:e.current,nodes:[]},e.current.nodes.push(n),e.current=e.current.nodes[e.current.nodes.length-1],e}}var e;return t.prototype.tree=null,t.prototype.current=null,t.prototype.and_begin=function(){return this._begin("AND")},t.prototype.or_begin=function(){return this._begin("OR")},t.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},t.prototype.and=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:e}),this},t.prototype.or=function(e){if(!e||"string"!=typeof e)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:e}),this},t.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return e(this.tree)},e=function(t){var n,r,i,s,o,u;i="",u=t.nodes;for(s=0,o=u.length;s<o;s++)n=u[s],n.expr!=null?r=n.expr:(r=e(n),""!==r&&(r="("+r+")")),""!==r&&(""!==i&&(i+=" "+n.type+" "),i+=r);return i},t}(),e.Block=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return s(n,t),n.prototype.exposedMethods=function(){var t,n,r;n={};for(t in this)r=this[t],typeof r=="function"&&t.charAt(0)!=="_"&&!e.Block.prototype[t]&&(n[t]=r);return n},n.prototype.buildStr=function(e){return""},n}(e.BaseBuilder),e.StringBlock=function(e){function t(e,n){t.__super__.constructor.call(this,e),this.str=n}return s(t,e),t.prototype.buildStr=function(e){return this.str},t}(e.Block),e.AbstractTableBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.tables=[]}return s(t,e),t.prototype._table=function(e,t){return t==null&&(t=null),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),this.options.singleTable&&(this.tables=[]),this.tables.push({name:e,alias:t})},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0>=this.tables.length)throw new Error("table() needs to be called");n="",s=this.tables;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=" AS `"+t.alias+"`");return n},t}(e.Block),e.UpdateTableBlock=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.table=function(e,t){return t==null&&(t=null),this._table(e,t)},t}(e.AbstractTableBlock),e.FromTableBlock=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.prototype.from=function(e,t){return t==null&&(t=null),this._table(e,t)},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0>=this.tables.length)throw new Error("from() needs to be called");n="",s=this.tables;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=" `"+t.alias+"`");return"FROM "+n},t}(e.AbstractTableBlock),e.IntoTableBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.table=null}return s(t,e),t.prototype.into=function(e){return this.table=this._sanitizeTable(e)},t.prototype.buildStr=function(e){if(!this.table)throw new Error("into() needs to be called");return"INTO "+this.table},t}(e.Block),e.GetFieldBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.fields=[]}return s(t,e),t.prototype.field=function(e,t){return t==null&&(t=null),e=this._sanitizeField(e),t&&(t=this._sanitizeAlias(t)),this.fields.push({name:e,alias:t})},t.prototype.buildStr=function(e){var t,n,r,i,s;n="",s=this.fields;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t.name,t.alias&&(n+=' AS "'+t.alias+'"');return""===n?"*":n},t}(e.Block),e.SetFieldBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.fields={}}return s(t,e),t.prototype.set=function(e,t){return e=this._sanitizeField(e),t=this._sanitizeValue(t),this.fields[e]=t,this},t.prototype.buildStr=function(e){var t,n,r,s,o;n=function(){var e,n;e=this.fields,n=[];for(t in e){if(!i.call(e,t))continue;n.push(t)}return n}.call(this);if(0>=n.length)throw new Error("set() needs to be called");r="";for(s=0,o=n.length;s<o;s++)t=n[s],""!==r&&(r+=", "),r+=""+t+" = "+this._formatValue(this.fields[t]);return"SET "+r},t}(e.Block),e.InsertFieldValueBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.fields={}}return s(t,e),t.prototype.buildStr=function(e){var t,n,r,s,o,u,a;n=function(){var e,t;e=this.fields,t=[];for(s in e){if(!i.call(e,s))continue;t.push(s)}return t}.call(this);if(0>=n.length)throw new Error("set() needs to be called");r="",o="";for(u=0,a=n.length;u<a;u++)t=n[u],""!==r&&(r+=", "),r+=t,""!==o&&(o+=", "),o+=this._formatValue(this.fields[t]);return"("+r+") VALUES ("+o+")"},t}(e.SetFieldBlock),e.DistinctBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.useDistinct=!1}return s(t,e),t.prototype.distinct=function(){return this.useDistinct=!0},t.prototype.buildStr=function(e){return this.useDistinct?"DISTINCT":""},t}(e.Block),e.GroupByBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.groups=[]}return s(t,e),t.prototype.group=function(e){return e=this._sanitizeField(e),this.groups.push(e)},t.prototype.buildStr=function(e){var t,n,r,i,s;n="";if(0<this.groups.length){s=this.groups;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=t;n="GROUP BY "+n}return n},t}(e.Block),e.OffsetBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.offsets=null}return s(t,e),t.prototype.offset=function(e){return e=this._sanitizeLimitOffset(e),this.offsets=e},t.prototype.buildStr=function(e){return this.offsets?"OFFSET "+this.offsets:""},t}(e.Block),e.WhereBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.wheres=[]}return s(t,e),t.prototype.where=function(e){e=this._sanitizeCondition(e);if(""!==e)return this.wheres.push(e)},t.prototype.buildStr=function(e){return 0<this.wheres.length?"WHERE ("+this.wheres.join(") AND (")+")":""},t}(e.Block),e.OrderByBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.orders=[]}return s(t,e),t.prototype.order=function(e,t){return t==null&&(t=!0),e=this._sanitizeField(e),this.orders.push({field:e,dir:t?!0:!1})},t.prototype.buildStr=function(e){var t,n,r,i,s;if(0<this.orders.length){n="",s=this.orders;for(r=0,i=s.length;r<i;r++)t=s[r],""!==n&&(n+=", "),n+=""+t.field+" "+(t.dir?"ASC":"DESC");return"ORDER BY "+n}return""},t}(e.Block),e.LimitBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.limits=null}return s(t,e),t.prototype.limit=function(e){return e=this._sanitizeLimitOffset(e),this.limits=e},t.prototype.buildStr=function(e){return this.limits?"LIMIT "+this.limits:""},t}(e.Block),e.JoinBlock=function(e){function t(e){t.__super__.constructor.call(this,e),this.joins=[]}return s(t,e),t.prototype.join=function(e,t,n,r){return t==null&&(t=null),n==null&&(n=null),r==null&&(r="INNER"),e=this._sanitizeTable(e),t&&(t=this._sanitizeAlias(t)),n&&(n=this._sanitizeCondition(n)),this.joins.push({type:r,table:e,alias:t,condition:n}),this},t.prototype.left_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"LEFT")},t.prototype.right_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"RIGHT")},t.prototype.outer_join=function(e,t,n){return t==null&&(t=null),n==null&&(n=null),this.join(e,t,n,"OUTER")},t.prototype.buildStr=function(e){var t,n,r,i,s;n="",s=this.joins||[];for(r=0,i=s.length;r<i;r++)t=s[r],n!==""&&(n+=" "),n+=""+t.type+" JOIN "+t.table,t.alias&&(n+=" `"+t.alias+"`"),t.condition&&(n+=" ON ("+t.condition+")");return n},t}(e.Block),e.QueryBuilder=function(e){function t(e,n){var r,i,s,o,u,a,f,l,c=this;t.__super__.constructor.call(this,e),this.blocks=n||[],f=this.blocks;for(u=0,a=f.length;u<a;u++){r=f[u],l=r.exposedMethods(),o=function(e,t,n){return c[t]=function(){return n.apply(e,arguments),c}};for(s in l){i=l[s];if(this[s]!=null)throw new Error(""+this._getObjectClassName(this)+" already has a builder method called: "+s);o(r,s,i)}}}return s(t,e),t.prototype.updateOptions=function(e){var t,r,i,s,o;this.options=n({},this.options,e),s=this.blocks,o=[];for(r=0,i=s.length;r<i;r++)t=s[r],o.push(t.options=n({},t.options,e));return o},t.prototype.toString=function(){var e;return function(){var t,n,r,i;r=this.blocks,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.buildStr(this));return i}.call(this).filter(function(e){return 0<e.length}).join(" ")},t}(e.BaseBuilder),e.Select=function(t){function n(t){var r;r=[new e.StringBlock(t,"SELECT"),new e.DistinctBlock(t),new e.GetFieldBlock(t),new e.FromTableBlock(t),new e.JoinBlock(t),new e.WhereBlock(t),new e.GroupByBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t),new e.OffsetBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),e.Update=function(t){function n(t){var r;r=[new e.StringBlock(t,"UPDATE"),new e.UpdateTableBlock(t),new e.SetFieldBlock(t),new e.WhereBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),e.Delete=function(t){function r(t){var i;i=[new e.StringBlock(t,"DELETE"),new e.FromTableBlock(n({},t,{singleTable:!0})),new e.JoinBlock(t),new e.WhereBlock(t),new e.OrderByBlock(t),new e.LimitBlock(t)],r.__super__.constructor.call(this,t,i)}return s(r,t),r}(e.QueryBuilder),e.Insert=function(t){function n(t){var r;r=[new e.StringBlock(t,"INSERT"),new e.IntoTableBlock(t),new e.InsertFieldValueBlock(t)],n.__super__.constructor.call(this,t,r)}return s(n,t),n}(e.QueryBuilder),t={expr:function(){return new e.Expression},select:function(t){return new e.Select(t)},update:function(t){return new e.Update(t)},insert:function(t){return new e.Insert(t)},"delete":function(t){return new e.Delete(t)}},t.remove=t["delete"],t.cls=e,(typeof define!="undefined"&&define!==null?define.amd:void 0)?define(function(){return t}):(typeof module!="undefined"&&module!==null?module.exports:void 0)?module.exports=t:typeof window!="undefined"&&window!==null&&(window.squel=t)}).call(this);
60 src/squel.coffee
View
@@ -196,12 +196,12 @@ class cls.Expression
# Begin a nested expression and combine it with the current expression using the intersection operator (AND).
- and_begin: =>
+ and_begin: ->
@_begin 'AND'
# Begin a nested expression and combine it with the current expression using the union operator (OR).
- or_begin: =>
+ or_begin: ->
@_begin 'OR'
@@ -209,7 +209,7 @@ class cls.Expression
# End the current compound expression.
#
# This will throw an error if begin() hasn't been called yet.
- end: =>
+ end: ->
if not @current.parent
throw new Error "begin() needs to be called"
@current = @current.parent
@@ -217,7 +217,7 @@ class cls.Expression
# Combine the current expression with the given expression using the intersection operator (AND).
- and: (expr) =>
+ and: (expr) ->
if not expr or "string" isnt typeof expr
throw new Error "expr must be a string"
@current.nodes.push
@@ -226,7 +226,7 @@ class cls.Expression
@
# Combine the current expression with the given expression using the union operator (OR).
- or: (expr) =>
+ or: (expr) ->
if not expr or "string" isnt typeof expr
throw new Error "expr must be a string"
@current.nodes.push
@@ -236,7 +236,7 @@ class cls.Expression
# Get the final fully constructed expression string.
- toString: =>
+ toString: ->
if null isnt @current.parent
throw new Error "end() needs to be called"
_toString @tree
@@ -292,10 +292,10 @@ class cls.Block extends cls.BaseBuilder
exposedMethods: ->
ret = {}
- for own attr, value of @
- if typeof value is "function"
- if attr.charAt(0) isnt '_' and attr isnt 'buildStr'
- ret[attr] = value
+ for attr, value of @
+ # only want functions from this class
+ if typeof value is "function" and attr.charAt(0) isnt '_' and !cls.Block::[attr]
+ ret[attr] = value
ret
@@ -335,7 +335,7 @@ class cls.AbstractTableBlock extends cls.Block
# An alias may also be specified for the table.
#
# Concrete subclasses should provide a method which calls this
- _table: (table, alias = null) =>
+ _table: (table, alias = null) ->
table = @_sanitizeTable(table)
alias = @_sanitizeAlias(alias) if alias
@@ -360,14 +360,14 @@ class cls.AbstractTableBlock extends cls.Block
# Update Table
class cls.UpdateTableBlock extends cls.AbstractTableBlock
- table: (table, alias = null) =>
+ table: (table, alias = null) ->
@_table(table, alias)
# FROM table
class cls.FromTableBlock extends cls.AbstractTableBlock
- from: (table, alias = null) =>
+ from: (table, alias = null) ->
@_table(table, alias)
buildStr: (queryBuilder) ->
@@ -391,7 +391,7 @@ class cls.IntoTableBlock extends cls.Block
@table = null
# Into given table.
- into: (table) =>
+ into: (table) ->
@table = @_sanitizeTable(table)
buildStr: (queryBuilder) ->
@@ -412,7 +412,7 @@ class cls.GetFieldBlock extends cls.Block
# e.g. DATE_FORMAT(a.started, "%H")
#
# An alias may also be specified for this field.
- field: (field, alias = null) =>
+ field: (field, alias = null) ->
field = @_sanitizeField(field)
alias = @_sanitizeAlias(alias) if alias
@@ -439,7 +439,7 @@ class cls.SetFieldBlock extends cls.Block
# Update the given field with the given value.
# This will override any previously set value for the given field.
- set: (field, value) =>
+ set: (field, value) ->
field = @_sanitizeField(field)
value = @_sanitizeValue(value)
@fields[field] = value
@@ -488,7 +488,7 @@ class cls.DistinctBlock extends cls.Block
@useDistinct = false
# Add the DISTINCT keyword to the query.
- distinct: =>
+ distinct: ->
@useDistinct = true
buildStr: (queryBuilder) ->
@@ -503,7 +503,7 @@ class cls.GroupByBlock extends cls.Block
@groups = []
# Add a GROUP BY transformation for the given field.
- group: (field) =>
+ group: (field) ->
field = @_sanitizeField(field)
@groups.push field
@@ -529,7 +529,7 @@ class cls.OffsetBlock extends cls.Block
#
# Call this will override the previously set offset for this query. Also note that Passing 0 for 'max' will remove
# the offset.
- offset: (start) =>
+ offset: (start) ->
start = @_sanitizeLimitOffset(start)
@offsets = start
@@ -546,7 +546,7 @@ class cls.WhereBlock extends cls.Block
# Add a WHERE condition.
#
# When the final query is constructed all the WHERE conditions are combined using the intersection (AND) operator.
- where: (condition) =>
+ where: (condition) ->
condition = @_sanitizeCondition(condition)
if "" isnt condition
@wheres.push condition
@@ -564,7 +564,7 @@ class cls.OrderByBlock extends cls.Block
# Add an ORDER BY transformation for the given field in the given order.
#
# To specify descending order pass false for the 'asc' parameter.
- order: (field, asc = true) =>
+ order: (field, asc = true) ->
field = @_sanitizeField(field)
@orders.push
field: field
@@ -591,7 +591,7 @@ class cls.LimitBlock extends cls.Block
#
# Call this will override the previously set limit for this query. Also note that Passing 0 for 'max' will remove
# the limit.
- limit: (max) =>
+ limit: (max) ->
max = @_sanitizeLimitOffset(max)
@limits = max
@@ -619,7 +619,7 @@ class cls.JoinBlock extends cls.Block
#
# 'type' must be either one of INNER, OUTER, LEFT or RIGHT. Default is 'INNER'.
#
- join: (table, alias = null, condition = null, type = 'INNER') =>
+ join: (table, alias = null, condition = null, type = 'INNER') ->
table = @_sanitizeTable(table)
alias = @_sanitizeAlias(alias) if alias
condition = @_sanitizeCondition(condition) if condition
@@ -633,17 +633,17 @@ class cls.JoinBlock extends cls.Block
# Add a LEFT JOIN with the given table.
- left_join: (table, alias = null, condition = null) =>
+ left_join: (table, alias = null, condition = null) ->
@join table, alias, condition, 'LEFT'
# Add a RIGHT JOIN with the given table.
- right_join: (table, alias = null, condition = null) =>
+ right_join: (table, alias = null, condition = null) ->
@join table, alias, condition, 'RIGHT'
# Add an OUTER JOIN with the given table.
- outer_join: (table, alias = null, condition = null) =>
+ outer_join: (table, alias = null, condition = null) ->
@join table, alias, condition, 'OUTER'
@@ -688,11 +688,11 @@ class cls.QueryBuilder extends cls.BaseBuilder
if @[methodName]?
throw new Error "#{@_getObjectClassName(@)} already has a builder method called: #{methodName}"
- ( (name, body) =>
+ ( (block, name, body) =>
@[name] = =>
- body.apply(@, arguments)
+ body.apply(block, arguments)
@
- )(methodName, methodBody)
+ )(block, methodName, methodBody)
# Update query builder options
@@ -707,7 +707,7 @@ class cls.QueryBuilder extends cls.BaseBuilder
# Get the final fully constructed query string.
- toString: =>
+ toString: ->
(block.buildStr(@) for block in @blocks).filter( (v) -> return (0 < v.length)).join(' ')
Please sign in to comment.
Something went wrong with that request. Please try again.