Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@imatic/pgqb

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@imatic/pgqb - npm Package Compare versions

Comparing version 0.1.26 to 0.1.27

38

dist/helper.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.val = exports.expr = exports.returning = exports.forUpdate = exports.offset = exports.limit = exports.orderBy = exports.having = exports.groupBy = exports.where = exports.doNothing = exports.doUpdate = exports.leftJoin = exports.join = exports.joins = exports.from = exports.set = exports.onConflict = exports.values = exports.columns = exports.update = exports.insertInto = exports.selectDistinct = exports.select = exports.append = exports.merge = void 0;
const r = require("ramda");
/**

@@ -17,3 +16,3 @@ * Merges more sql maps into 1. If same property exists in more maps, value from last map

function merge(...m) {
return r.reduce(r.mergeRight, {}, m);
return m.reduce((acc, next) => Object.assign(acc, next), {});
}

@@ -25,12 +24,19 @@ exports.merge = merge;

const appendHandlers = {
columns: (c1, c2) => r.concat(c1, c2),
values: (v1, v2) => r.map((k) => r.concat(v1[k], v2[k]), Object.keys(v1)),
columns: (c1, c2) => c1.concat(c2),
values: (v1, v2) => Object.keys(v1).map((k) => v1[k].concat(v2[k])),
where: (e1, e2) => ['and', e1, e2],
having: (e1, e2) => ['and', e1, e2],
set: (e1, e2) => r.concat(e1, e2),
order_by: (o1, o2) => r.concat(o1, o2),
select: (s1, s2) => r.concat(s1, s2),
join: (j1, j2) => r.concat(j1, j2),
group_by: (g1, g2) => r.concat(g1, g2),
set: (e1, e2) => e1.concat(e2),
order_by: (o1, o2) => o1.concat(o2),
select: (s1, s2) => s1.concat(s2),
join: (j1, j2) => j1.concat(j2),
group_by: (g1, g2) => g1.concat(g2),
};
function omit(keys, obj) {
const res = Object.assign({}, obj);
for (const k of keys) {
delete res[k];
}
return res;
}
/**

@@ -40,3 +46,3 @@ * Checks if append handlers exists for clauses in given map, throws exception if not.

function checkAppendSupportedClauses(m) {
const unsupportedClauses = Object.keys(r.omit(Object.keys(appendHandlers), m));
const unsupportedClauses = Object.keys(omit(Object.keys(appendHandlers), m));
if (unsupportedClauses.length) {

@@ -58,3 +64,5 @@ throw new Error(`Trying to append following unsupported clauses: ${unsupportedClauses.join(', ')}. Only following clauses are supported: ${Object.keys(appendHandlers).join(', ')}`);

checkAppendSupportedClauses(m2);
return r.reduce((m, k) => r.assoc(k, m[k] ? appendHandlers[k](m1[k], m2[k]) : m2[k], m), m1, Object.keys(m2));
return Object.keys(m2).reduce((m, k) => Object.assign({}, m, {
[k]: m[k] ? appendHandlers[k](m1[k], m2[k]) : m2[k],
}), m1);
}

@@ -72,3 +80,3 @@ /**

function append(...m) {
return r.reduce(_append, r.head(m), r.tail(m));
return m.slice(1).reduce((acc, next) => _append(acc, next), m[0]);
}

@@ -85,7 +93,7 @@ exports.append = append;

function insertInto(table, alias) {
return { insert_into: r.isNil(alias) ? table : [table, alias] };
return { insert_into: alias == null ? table : [table, alias] };
}
exports.insertInto = insertInto;
function update(table, alias) {
return { update: r.isNil(alias) ? table : [table, alias] };
return { update: alias == null ? table : [table, alias] };
}

@@ -110,3 +118,3 @@ exports.update = update;

function from(table, alias) {
return { from: r.isNil(alias) ? table : [table, alias] };
return { from: alias == null ? table : [table, alias] };
}

@@ -113,0 +121,0 @@ exports.from = from;

{
"name": "@imatic/pgqb",
"version": "0.1.26",
"version": "0.1.27",
"description": "Functional PostgreSQL query builder",

@@ -16,4 +16,2 @@ "main": "./dist/index.js",

"dependencies": {
"@types/ramda": "^0.27.6",
"ramda": "^0.27.0",
"sql-template-strings": "^2.2.2",

@@ -20,0 +18,0 @@ "typescript": "^3.5.2"

import * as qb from './qb';
import * as r from 'ramda';

@@ -16,3 +15,3 @@ /**

export function merge(...m: qb.Sql[]): qb.Sql {
return r.reduce<qb.Sql, qb.Sql>(r.mergeRight, {}, m);
return m.reduce((acc, next) => Object.assign(acc, next), {});
}

@@ -24,17 +23,23 @@

const appendHandlers = {
columns: (c1: string[], c2: string[]): string[] => r.concat(c1, c2),
columns: (c1: string[], c2: string[]): string[] => c1.concat(c2),
values: (v1: qb.Value[][], v2: qb.Value[][]): qb.Value[][] =>
r.map(
(k) => r.concat(v1[k] as qb.Value[], v2[k] as qb.Value[]),
Object.keys(v1)
),
Object.keys(v1).map((k) => v1[k].concat(v2[k])),
where: (e1: qb.Expr, e2: qb.Expr) => ['and', e1, e2],
having: (e1: qb.Expr, e2: qb.Expr) => ['and', e1, e2],
set: (e1: qb.Expr[], e2: qb.Expr[]) => r.concat(e1, e2),
order_by: (o1: qb.OrderBy, o2: qb.OrderBy) => r.concat(o1, o2),
select: (s1: qb.Expr[], s2: qb.Expr[]) => r.concat(s1, s2),
join: (j1: qb.Join[], j2: qb.Join[]) => r.concat(j1, j2),
group_by: (g1: qb.Expr[], g2: qb.Expr[]) => r.concat(g1, g2),
set: (e1: qb.Expr[], e2: qb.Expr[]) => e1.concat(e2),
order_by: (o1: qb.OrderBy, o2: qb.OrderBy) => o1.concat(o2),
select: (s1: qb.Expr[], s2: qb.Expr[]) => s1.concat(s2),
join: (j1: qb.Join[], j2: qb.Join[]) => j1.concat(j2),
group_by: (g1: qb.Expr[], g2: qb.Expr[]) => g1.concat(g2),
};
function omit(keys: string[], obj: object): object {
const res = Object.assign({}, obj);
for (const k of keys) {
delete res[k];
}
return res;
}
/**

@@ -45,3 +50,3 @@ * Checks if append handlers exists for clauses in given map, throws exception if not.

const unsupportedClauses = Object.keys(
r.omit(Object.keys(appendHandlers), m)
omit(Object.keys(appendHandlers), m)
);

@@ -73,6 +78,8 @@

return r.reduce(
(m, k) => r.assoc(k, m[k] ? appendHandlers[k](m1[k], m2[k]) : m2[k], m),
m1,
Object.keys(m2)
return Object.keys(m2).reduce(
(m, k) =>
Object.assign({}, m, {
[k]: m[k] ? appendHandlers[k](m1[k], m2[k]) : m2[k],
}),
m1
);

@@ -92,3 +99,3 @@ }

export function append(...m: qb.Sql[]): qb.Sql {
return r.reduce(_append, r.head(m) as qb.Sql, r.tail(m) as qb.Sql[]);
return m.slice(1).reduce((acc, next) => _append(acc, next), m[0]);
}

@@ -105,7 +112,7 @@

export function insertInto(table: string | qb.Sql, alias?: string): qb.Sql {
return {insert_into: r.isNil(alias) ? table : [table, alias]};
return {insert_into: alias == null ? table : [table, alias]};
}
export function update(table: string | qb.Sql, alias?: string): qb.Sql {
return {update: r.isNil(alias) ? table : [table, alias]};
return {update: alias == null ? table : [table, alias]};
}

@@ -130,3 +137,3 @@

export function from(table: string | qb.Sql, alias?: string): qb.Sql {
return {from: r.isNil(alias) ? table : [table, alias]};
return {from: alias == null ? table : [table, alias]};
}

@@ -133,0 +140,0 @@

import {expect} from 'chai';
import * as qb from '../src/qb';
import * as r from 'ramda';
function pick(props: string[], obj: object) {
const res = {};
for (const k of props) {
res[k] = obj[k];
}
return res;
}
describe('common/qb', () => {

@@ -227,3 +235,3 @@ describe('toSql', () => {

it(test.name, () =>
expect(r.pick(['text', 'values'], qb.toSql(test.map))).eqls(
expect(pick(['text', 'values'], qb.toSql(test.map))).eqls(
test.sql

@@ -230,0 +238,0 @@ )

@@ -14,3 +14,3 @@ {

"radix": true,
"triple-equals": true,
"triple-equals": [true, "allow-null-check"],
"typeof-compare": true,

@@ -17,0 +17,0 @@ "use-isnan": true,

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