mirror of
https://github.com/knex/knex.git
synced 2025-11-30 08:56:27 +00:00
36 lines
8.5 KiB
HTML
36 lines
8.5 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>lib/raw</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="lib/raw"><meta name="groc-project-path" content="lib/raw.js"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">lib/raw.js</div></div><div id="document"><div class="segment"><div class="comments "><div class="wrapper"><h2 id="raw">Raw</h2></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="kd">var</span> <span class="nx">SqlString</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./sqlstring'</span><span class="p">);</span>
|
|
<span class="kd">var</span> <span class="nx">_</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'lodash'</span><span class="p">);</span>
|
|
<span class="kd">var</span> <span class="nx">inherits</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'inherits'</span><span class="p">);</span>
|
|
<span class="kd">var</span> <span class="nx">EventEmitter</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'events'</span><span class="p">).</span><span class="nx">EventEmitter</span><span class="p">;</span>
|
|
|
|
<span class="kd">function</span> <span class="nx">Raw</span><span class="p">(</span><span class="nx">sql</span><span class="p">,</span> <span class="nx">bindings</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="k">if</span> <span class="p">(</span><span class="nx">sql</span><span class="p">.</span><span class="nx">toSQL</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_processQuery</span><span class="p">(</span><span class="nx">sql</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">sql</span> <span class="o">=</span> <span class="nx">sql</span><span class="p">;</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">bindings</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">bindings</span><span class="p">)</span> <span class="o">?</span> <span class="nx">bindings</span> <span class="o">:</span>
|
|
<span class="nx">bindings</span> <span class="o">?</span> <span class="p">[</span><span class="nx">bindings</span><span class="p">]</span> <span class="o">:</span> <span class="p">[];</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">_debug</span> <span class="o">=</span> <span class="k">void</span> <span class="mi">0</span><span class="p">;</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">_transacting</span> <span class="o">=</span> <span class="k">void</span> <span class="mi">0</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="nx">inherits</span><span class="p">(</span><span class="nx">Raw</span><span class="p">,</span> <span class="nx">EventEmitter</span><span class="p">);</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Wraps the current sql with <code>before</code> and <code>after</code>.</p></div></div><div class="code"><div class="wrapper"><span class="nx">Raw</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">wrap</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">before</span><span class="p">,</span> <span class="nx">after</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">sql</span> <span class="o">=</span> <span class="nx">before</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">sql</span> <span class="o">+</span> <span class="nx">after</span><span class="p">;</span>
|
|
<span class="k">return</span> <span class="k">this</span><span class="p">;</span>
|
|
<span class="p">};</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Calls <code>toString</code> on the Knex object.
|
|
return '[object Knex$raw]';</p></div></div><div class="code"><div class="wrapper"><span class="nx">Raw</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toString</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
|
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">toQuery</span><span class="p">();</span>
|
|
<span class="p">};</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Returns the raw sql for the query.</p></div></div><div class="code"><div class="wrapper"><span class="nx">Raw</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toSQL</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
|
<span class="k">return</span> <span class="p">{</span>
|
|
<span class="nx">sql</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">sql</span><span class="p">,</span>
|
|
<span class="nx">method</span><span class="o">:</span> <span class="s1">'raw'</span><span class="p">,</span>
|
|
<span class="nx">bindings</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">bindings</span>
|
|
<span class="p">};</span>
|
|
<span class="p">};</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Convert the query toSQL.</p></div></div><div class="code"><div class="wrapper"><span class="nx">Raw</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_processQuery</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">sql</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="kd">var</span> <span class="nx">processed</span> <span class="o">=</span> <span class="nx">sql</span><span class="p">.</span><span class="nx">toSQL</span><span class="p">();</span>
|
|
<span class="k">return</span> <span class="k">new</span> <span class="k">this</span><span class="p">.</span><span class="nx">constructor</span><span class="p">(</span><span class="nx">processed</span><span class="p">.</span><span class="nx">sql</span><span class="p">,</span> <span class="nx">processed</span><span class="p">.</span><span class="nx">bindings</span><span class="p">);</span>
|
|
<span class="p">};</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Allow the <code>Raw</code> object to be utilized with full access to the relevant
|
|
promise API.</p></div></div><div class="code"><div class="wrapper"><span class="nx">require</span><span class="p">(</span><span class="s1">'./interface'</span><span class="p">)(</span><span class="nx">Raw</span><span class="p">);</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Turn the raw query into a string.</p></div></div><div class="code"><div class="wrapper"><span class="nx">Raw</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toQuery</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
|
<span class="k">return</span> <span class="nx">SqlString</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">sql</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">bindings</span><span class="p">);</span>
|
|
<span class="p">};</span>
|
|
|
|
<span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">Raw</span><span class="p">;</span></div></div></div></div></body></html> |