Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Update docs for 3.8.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddentao committed Aug 30, 2014
1 parent 2eeedaa commit d54bf04
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
9 changes: 7 additions & 2 deletions api.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@
desc: 'Sort direction. <code>true</code> = ascending, <code>false</code> = descending.',
type: 'Boolean',
defaultValue: true
},
'...': {
desc: 'List of parameter values specified as additional arguments.',
type: 'Any',
defaultValue: '[]'
}
},
returns: 'this'
Expand Down Expand Up @@ -889,7 +894,7 @@
'will override any globally registered handlers set via [[cls.registerValueHandler]].',
params: {
'type': {
desc: 'The class object representing the value type to handle',
desc: 'The class object or <code>typeof</code> string representing the value type to handle',
type: 'Class'
},
'handler': {
Expand Down Expand Up @@ -953,7 +958,7 @@
'Squel automatically take care of formatting them when building the output query string.',
params: {
'type': {
desc: 'The class object representing the value type to handle',
desc: 'The class object or <code>typeof</code> string representing the value type to handle',
type: 'Class'
},
'handler': {
Expand Down
36 changes: 32 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@ <h3>Sorting</h3>
/* SELECT id FROM students ORDER BY id ASC, name DESC */
</pre>

<p>Additional arguments count as parameter values, e.g. for custom sort functions::</p>

<pre class="brush: js">
alert(
squel.select()
.field("id")
.from("students")
.order("DIST(?, ?)", true, 1, 2)
);
/* SELECT id FROM students ORDER BY DIST(1, 2) ASC */
</pre>

<h3>Grouping</h3>

<pre class="brush: js">
Expand Down Expand Up @@ -841,13 +853,14 @@ <h3>Multiple fields and rows</h3>
squel.select()
.from("students")
.where("a = ? AND b = ?", "test", true)
.order("CALC(?, ?)", true, 1.2, false)
.toParam()
));

/*
{
text: SELECT * FROM students WHERE (a = ? AND b = ?),
values: [ 'test', true ]
text: SELECT * FROM students WHERE (a = ? AND b = ?) ORDER BY CALC(?, ?) ASC,
values: [ 'test', true, 1.2, false ]
}
*/
</pre>
Expand Down Expand Up @@ -1095,8 +1108,7 @@ <h3>Multiple fields and rows</h3>
<section id="custom_types">
<a name="custom_types" href="#custom_types"><h2>Custom value types</h2></a>

<p>Sometimes you might want to pass in <code>Object</code> instances as field values. For instance, let's say
you are updating a <code>DateTime</code> field. You could do the following:</p>
<p>Sometimes you might want to override how Squel formats certainst types of values, e.g. <code>Date</code> instances. You could do the following:</p>

<pre class="brush: js">
var myDate = new Date(2012, 4, 22),
Expand Down Expand Up @@ -1165,6 +1177,22 @@ <h3>Multiple fields and rows</h3>
/* UPDATE students SET value = 2 */
</pre>

<p>We can even register handlers for primitive types such as strings and booleans. Simply pass in the
primitive type name as a string:</p>

<pre class="brush: js">
squel.registerValueHandler('boolean', function(v) {
return v ? 'YES': 'NO';
});

alert(
squel.update()
.table("students")
.set("value", true)
);
/* UPDATE students SET value = 'YES' */
</pre>

<p>We can even override the registered handler for a value type on a per-instance basis.</p>

<pre class="brush: js">
Expand Down
Loading

0 comments on commit d54bf04

Please sign in to comment.