Skip to content

Commit 396b235

Browse files
committed
refactoring documentation.
1 parent 857b2e8 commit 396b235

File tree

2 files changed

+60
-49
lines changed

2 files changed

+60
-49
lines changed

lib/helpers/columnSet.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,26 +481,30 @@ function ColumnSet(columns, options) {
481481
* Prepares a source object to be formatted, by cloning it and applying the rules
482482
* as set by the columns configuration.
483483
*
484-
* This method is primarily for internal use.
484+
* This method is primarily for internal use, and as such it does not validate
485+
* its input parameters.
486+
*
487+
* @param {object} source
488+
* The source object to be prepared, if required.
485489
*
486-
* @param {object} obj
487-
* Source object to be prepared.
490+
* It must be a non-`null` object, which the method does not validate, as it is
491+
* intended primarily for internal use by the library.
488492
*
489493
* @returns {object}
490494
* When the object needs to be prepared, the method returns a clone of the source object,
491495
* with all properties and values set according to the columns configuration.
492496
*
493497
* When the object does not need to be prepared, the original object is returned.
494498
*/
495-
this.prepare = function (obj) {
499+
this.prepare = function (source) {
496500
if (isSimple) {
497-
return obj; // a simple ColumnSet requires no object preparation;
501+
return source; // a simple ColumnSet requires no object preparation;
498502
}
499503
var target = {};
500504
$arr.forEach(this.columns, function (c) {
501-
var a = colDesc(c, obj);
505+
var a = colDesc(c, source);
502506
if (c.init) {
503-
target[a.name] = c.init.call(obj, a);
507+
target[a.name] = c.init.call(source, a);
504508
} else {
505509
if (a.exists || 'def' in c) {
506510
target[a.name] = a.value;

lib/queryFile.js

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,8 @@ var $npm = {
3131
*
3232
* If there is any problem reading the file, it will be reported when executing the query.
3333
*
34-
* @param {object} [options]
35-
* A set of configuration options.
36-
*
37-
* @param {boolean} [options.debug]
38-
* When in debug mode, the query file is checked for its last modification time on every query request,
39-
* so if it changes, the file is read afresh.
40-
*
41-
* The default for this property is `true` when `NODE_ENV` = `development`,
42-
* or `false` otherwise.
43-
*
44-
* @param {boolean|string} [options.minify=false]
45-
* Parses and minifies the SQL using $[pg-minify]:
46-
* - `false` - do not use $[pg-minify]
47-
* - `true` - use $[pg-minify] to parse and minify SQL
48-
* - `'after'` - use $[pg-minify] after applying static formatting parameters
49-
* (option `params`), as opposed to before it (default)
50-
*
51-
* If option `compress` is set, then the default for `minify` is `true`.
52-
*
53-
* Failure to parse SQL will result in $[SQLParsingError].
54-
*
55-
* @param {boolean} [options.compress=false]
56-
* Sets option `compress` as supported by $[pg-minify], to uglify the SQL:
57-
* - `false` - no compression to be applied, keep minimum spaces for easier read
58-
* - `true` - remove all unnecessary spaces from SQL
59-
*
60-
* This option has no meaning, if `minify` is explicitly set to `false`. However, if `minify` is not
61-
* specified and `compress` is specified as `true`, then `minify` defaults to `true`.
62-
*
63-
* @param {array|object|value} [options.params]
64-
* Static formatting parameters to be applied to the SQL, using the same method {@link formatting.format as.format},
65-
* but with option `partial` = `true`.
66-
*
67-
* Most of the time query formatting is fully dynamic, and applied just before executing the query.
68-
* In some cases though you may need to pre-format SQL with static values. Examples of it can be a
69-
* schema name, or a configurable table name.
70-
*
71-
* This option makes two-step SQL formatting easy: you can pre-format the SQL initially, and then
72-
* apply the second-step dynamic formatting when executing the query.
34+
* @param {QueryFile.Options} [options]
35+
* Set of configuration options, as documented by {@link QueryFile.Options}.
7336
*
7437
* @returns {QueryFile}
7538
*
@@ -229,7 +192,7 @@ function QueryFile(file, options) {
229192

230193
/**
231194
* @name QueryFile#query
232-
* @type string
195+
* @type {string}
233196
* @default undefined
234197
* @readonly
235198
* @summary Prepared query string.
@@ -262,7 +225,7 @@ function QueryFile(file, options) {
262225

263226
/**
264227
* @name QueryFile#file
265-
* @type string
228+
* @type {string}
266229
* @readonly
267230
* @description
268231
* File name that was passed into the constructor.
@@ -277,7 +240,7 @@ function QueryFile(file, options) {
277240

278241
/**
279242
* @name QueryFile#options
280-
* @type object
243+
* @type {QueryFile.Options}
281244
* @readonly
282245
* @description
283246
* Set of options, as configured during the object's construction.
@@ -328,3 +291,47 @@ QueryFile.prototype.inspect = function () {
328291
};
329292

330293
module.exports = QueryFile;
294+
295+
/**
296+
* @typedef QueryFile.Options
297+
* @description
298+
* A set of configuration options as passed into the {@link QueryFile} constructor.
299+
*
300+
* @property {boolean} debug
301+
* When in debug mode, the query file is checked for its last modification time on every query request,
302+
* so if it changes, the file is read afresh.
303+
*
304+
* The default for this property is `true` when `NODE_ENV` = `development`,
305+
* or `false` otherwise.
306+
*
307+
* @property {boolean|string} minify=false
308+
* Parses and minifies the SQL using $[pg-minify]:
309+
* - `false` - do not use $[pg-minify]
310+
* - `true` - use $[pg-minify] to parse and minify SQL
311+
* - `'after'` - use $[pg-minify] after applying static formatting parameters
312+
* (option `params`), as opposed to before it (default)
313+
*
314+
* If option `compress` is set, then the default for `minify` is `true`.
315+
*
316+
* Failure to parse SQL will result in $[SQLParsingError].
317+
*
318+
* @property {boolean} compress=false
319+
* Sets option `compress` as supported by $[pg-minify], to uglify the SQL:
320+
* - `false` - no compression to be applied, keep minimum spaces for easier read
321+
* - `true` - remove all unnecessary spaces from SQL
322+
*
323+
* This option has no meaning, if `minify` is explicitly set to `false`. However, if `minify` is not
324+
* specified and `compress` is specified as `true`, then `minify` defaults to `true`.
325+
*
326+
* @property {array|object|value} params
327+
*
328+
* Static formatting parameters to be applied to the SQL, using the same method {@link formatting.format as.format},
329+
* but with option `partial` = `true`.
330+
*
331+
* Most of the time query formatting is fully dynamic, and applied just before executing the query.
332+
* In some cases though you may need to pre-format SQL with static values. Examples of it can be a
333+
* schema name, or a configurable table name.
334+
*
335+
* This option makes two-step SQL formatting easy: you can pre-format the SQL initially, and then
336+
* apply the second-step dynamic formatting when executing the query.
337+
*/

0 commit comments

Comments
 (0)