Socket
Socket
Sign inDemoInstall

zol

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zol - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

2

package.json
{
"name": "zol",
"version": "0.5.0",
"version": "0.5.1",
"description": "Type safe composable SQL abstraction layer",

@@ -5,0 +5,0 @@ "keywords": [

@@ -40,2 +40,4 @@ import * as pgLib from "pg";

return new Promise<any[]>((resolve, reject) => {
let customTypeParserIgnored = true;
conn.query({

@@ -46,3 +48,6 @@ text: text,

types: {
getTypeParser: () => identityTypeParser
getTypeParser: () => (val: string) => {
customTypeParserIgnored = false;
return val;
}
}

@@ -66,3 +71,42 @@ }, (err: any, result: QueryResult) => {

for (let j = 0; j < numFields; ++j) {
const colValue = row[j];
let colValue = row[j];
// "pg" has a bug that it ignores our custom type parser
// when using "pg-native":
// <https://github.com/brianc/node-postgres/issues/2686>
//
// Here is a workaround until the bug is fixed
if (customTypeParserIgnored && colValue !== null) {
switch (result.fields[j].dataTypeID) {
case 16: // BOOL
colValue = colValue === true ? "t" : "f";
break;
case 21: // INT2
case 23: // INT4
case 700: // FLOAT4
case 701: // FLOAT8
case 1700: // NUMERIC
colValue = "" + colValue;
break;
case 114: // JSON
case 3802: // JSONB
colValue = JSON.stringify(colValue);
break;
case 1082: // DATE
colValue = formatDate(colValue);
break;
case 1184: // TIMESTAMPTZ
colValue = formatTimestamptz(colValue);
break;
case 1114: // TIMESTAMP
colValue = formatTimestamp(colValue);
break;
case 1186: // INTERVAL
colValue = formatInterval(colValue);
break;
default:
break;
}
}
// This try block is more broad than necessary.. we only expect

@@ -99,2 +143,6 @@ // an error to happen inside the call to:

export function runCustomQueryStreaming(conn: pgLib.Client, propNames: string[], propParsers: ((val: string) => any)[], text: string, values: any, rowChunkSize: number): Promise<StreamingRows<any>> {
if ((conn as any).native) {
throw new Error("Streaming not supported when using \"pg-native\" driver");
}
function parseRows(resultRows: any[]): any[] {

@@ -220,1 +268,73 @@ const resultRowsLength = resultRows.length;

}
function formatDate(date: Date): string {
return `${date.getFullYear()}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())}`;
}
function formatTimestamp(date: Date): string {
return `${date.getFullYear()}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())} ${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}:${twoDigits(date.getSeconds())}.${threeDigits(date.getMilliseconds())}`;
}
function formatTimestamptz(date: Date): string {
return `${date.getUTCFullYear()}-${twoDigits(date.getUTCMonth() + 1)}-${twoDigits(date.getUTCDate())} ${twoDigits(date.getUTCHours())}:${twoDigits(date.getUTCMinutes())}:${twoDigits(date.getUTCSeconds())}.${threeDigits(date.getUTCMilliseconds())}`;
}
function formatInterval(interval: any): string {
let result = "";
if (interval.years !== undefined) {
result += `${interval.years} years `;
}
if (interval.months !== undefined) {
result += `${interval.months} months `;
}
if (interval.days !== undefined) {
result += `${interval.days} days `;
}
let negativeInterval = false;
let hours = interval.hours !== undefined ? interval.hours : 0;
if (hours < 0) {
negativeInterval = true;
hours = -hours;
}
let minutes = interval.minutes !== undefined ? interval.minutes : 0;
if (minutes < 0) {
negativeInterval = true;
minutes = -minutes;
}
let seconds = interval.seconds !== undefined ? interval.seconds : 0;
if (seconds < 0) {
negativeInterval = true;
seconds = -seconds;
}
let milliseconds = interval.milliseconds !== undefined ? Math.trunc(interval.milliseconds) : 0;
if (milliseconds < 0) {
negativeInterval = true;
milliseconds = -milliseconds;
}
result += `${negativeInterval ? "-" : ""}${twoDigits(hours)}:${twoDigits(minutes)}:${twoDigits(seconds)}.${threeDigits(milliseconds)}`;
result = result.trim();
return result;
}
function twoDigits(val: number): string {
if (val <= 9) {
return "0" + val;
} else {
return "" + val;
}
}
function threeDigits(val: number): string {
if (val <= 9) {
return "00" + val;
} else if (val <= 99) {
return "0" + val;
} else {
return "" + val;
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc