pg-promise
Advanced tools
Comparing version 0.2.2 to 0.2.3
71
index.js
@@ -49,2 +49,5 @@ // Cannot declare 'use strict' here, because queryResult | ||
// Namespace for type conversion helpers; | ||
lib.as = $wrap; | ||
// Exposing PG library instance, just for flexibility. | ||
@@ -58,28 +61,2 @@ lib.pg = npm.pg; | ||
// Namespace for type conversion helpers; | ||
lib.as = { | ||
bool: function (val) { | ||
if ($isNull(val)) { | ||
return 'null'; | ||
} | ||
return val ? 'TRUE' : 'FALSE'; | ||
}, | ||
text: function (val) { | ||
if ($isNull(val)) { | ||
return 'null'; | ||
} | ||
return $wrapText($fixQuotes(val)); | ||
}, | ||
date: function (val) { | ||
if ($isNull(val)) { | ||
return 'null'; | ||
} | ||
if (val instanceof Date) { | ||
return $wrapText(val.toUTCString()); | ||
} else { | ||
throw new Error($wrapText(val) + " doesn't represent a valid Date object or value"); | ||
} | ||
} | ||
}; | ||
return lib; | ||
@@ -348,8 +325,8 @@ }; | ||
case 'string': | ||
return dbInst.as.text(val); | ||
return $wrap.text(val); | ||
case 'boolean': | ||
return dbInst.as.bool(val); | ||
return $wrap.bool(val); | ||
default: | ||
if (val instanceof Date) { | ||
return dbInst.as.date(val); | ||
return $wrap.date(val); | ||
} else { | ||
@@ -376,2 +353,38 @@ return val; | ||
// Value wrapper to be exposed through 'pgp.as' namespace; | ||
var $wrap = { | ||
text: function (txt) { | ||
if ($isNull(txt)) { | ||
return 'null'; | ||
} | ||
return $wrapText($fixQuotes(txt)); | ||
}, | ||
bool: function (val) { | ||
if ($isNull(val)) { | ||
return 'null'; | ||
} | ||
return val ? 'TRUE' : 'FALSE'; | ||
}, | ||
date: function (d) { | ||
if ($isNull(d)) { | ||
return 'null'; | ||
} | ||
if (d instanceof Date) { | ||
return $wrapText(d.toUTCString()); | ||
} else { | ||
throw new Error($wrapText(d) + " doesn't represent a valid Date object or value"); | ||
} | ||
}, | ||
csv: function (arr) { | ||
if ($isNull(arr)) { | ||
return 'null'; | ||
} | ||
if (Array.isArray(arr)) { | ||
return $formatValues(arr); | ||
} else { | ||
throw new Error($wrapText(arr) + " doesn't represent a valid Array object or value"); | ||
} | ||
} | ||
}; | ||
// Formats a proper function call from the parameters. | ||
@@ -378,0 +391,0 @@ function $createFuncQuery(funcName, params) { |
{ | ||
"name": "pg-promise", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "PG + Promise made easy, with transactions support.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
381
26796
4