This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
/
mysql.html
190 lines (135 loc) · 8.17 KB
/
mysql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<title>#</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="mysql.html">
mysql.coffee
</a>
<a class="source" href="postgres.html">
postgres.coffee
</a>
<a class="source" href="squel.html">
squel.coffee
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="pilwrap for-h1">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<h1>#</h1>
</div>
<div class="content"><div class='highlight'><pre>Copyright (c) Ramesh Nair (hiddentao.com)
Permission <span class="keyword">is</span> hereby granted, free <span class="keyword">of</span> charge, to any person
obtaining a copy <span class="keyword">of</span> <span class="keyword">this</span> software <span class="keyword">and</span> associated documentation
files (the <span class="string">"Software"</span>), to deal <span class="keyword">in</span> the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, <span class="keyword">and</span>/<span class="keyword">or</span> sell
copies <span class="keyword">of</span> the Software, <span class="keyword">and</span> to permit persons to whom the
Software <span class="keyword">is</span> furnished to <span class="keyword">do</span> so, subject to the following
conditions:
The above copyright notice <span class="keyword">and</span> <span class="keyword">this</span> permission notice shall be
included <span class="keyword">in</span> all copies <span class="keyword">or</span> substantial portions <span class="keyword">of</span> the Software.
THE SOFTWARE IS PROVIDED <span class="string">"AS IS"</span>, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
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.</pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap for-h1">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h1>#</h1>
<p>This file contains additional Squel commands for use with the Postgres DB engine</p>
</div>
<div class="content"><div class='highlight'><pre>squel.flavours[<span class="string">'mysql'</span>] = ->
cls = squel.cls</pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>(INSERT INTO) ... field ... value</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="class"><span class="keyword">class</span> <span class="title">cls</span>.<span class="title">InsertFieldValueBlock</span> <span class="keyword">extends</span> <span class="title">cls</span>.<span class="title">SetFieldBlock</span></span>
constructor: (options) ->
<span class="keyword">super</span> options
<span class="property">@fields</span> = {}
<span class="property">@_duplicateKeyUpdates</span> = {}</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>Update the given field with the given value.
options.duplicateKeyUpdate - whether to include the ON DUPLICATE KEY UPDATE clause for this field. The value for
the option is the value used to update the key with</p>
</div>
<div class="content"><div class='highlight'><pre> set: (field, value, options) ->
field = <span class="property">@_sanitizeField</span>(field)
value = <span class="property">@_sanitizeValue</span>(value)
<span class="property">@fields</span>[field] = value
<span class="property">@_duplicateKeyUpdates</span>[field] = <span class="property">@_sanitizeValue</span>(options.duplicateKeyUpdate) <span class="keyword">if</span> options?.duplicateKeyUpdate <span class="keyword">isnt</span> <span class="literal">undefined</span>
@
buildStr: ->
fieldNames = (name <span class="keyword">for</span> own name <span class="keyword">of</span> <span class="property">@fields</span>)
<span class="keyword">if</span> <span class="number">0</span> >= fieldNames.length <span class="keyword">then</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"set() needs to be called"</span></pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>fields</p>
</div>
<div class="content"><div class='highlight'><pre> fields = <span class="string">""</span>
values = <span class="string">""</span>
<span class="keyword">for</span> field <span class="keyword">in</span> fieldNames
fields += <span class="string">", "</span> <span class="keyword">if</span> <span class="string">""</span> <span class="keyword">isnt</span> fields
fields += field
values += <span class="string">", "</span> <span class="keyword">if</span> <span class="string">""</span> <span class="keyword">isnt</span> values
values += <span class="property">@_formatValue</span>(<span class="property">@fields</span>[field])
str = <span class="string">"(<span class="subst">#{fields}</span>) VALUES (<span class="subst">#{values}</span>)"</span></pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<p>ON DUPLICATE KEY UPDATE</p>
</div>
<div class="content"><div class='highlight'><pre> fields = <span class="string">""</span>
<span class="keyword">for</span> field, value <span class="keyword">of</span> <span class="property">@_duplicateKeyUpdates</span>
fields += <span class="string">", "</span> <span class="keyword">if</span> <span class="string">""</span> <span class="keyword">isnt</span> fields
fields += <span class="string">"<span class="subst">#{field}</span> = <span class="subst">#{@_formatValue(value)}</span>"</span>
<span class="keyword">if</span> fields <span class="keyword">isnt</span> <span class="string">""</span>
str = <span class="string">"<span class="subst">#{str}</span> ON DUPLICATE KEY UPDATE <span class="subst">#{fields}</span>"</span>
str</pre></div></div>
</li>
</ul>
</div>
</body>
</html>