@imatic/pgqb
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -47,16 +47,16 @@ import * as qb from './qb'; | ||
export declare const expr: { | ||
eq: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
neq: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
gt: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
gte: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
lt: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
lte: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
as: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
like: (expr1: qb.Expr, expr2: qb.Expr) => qb.Expr; | ||
and: (...exprs: qb.Expr[]) => qb.Expr; | ||
or: (...exprs: qb.Expr[]) => qb.Expr; | ||
eq: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
neq: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
gt: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
gte: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
lt: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
lte: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
as: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
like: (expr1: qb.ExprOperand, expr2: qb.ExprOperand) => qb.Expr; | ||
and: (expr: qb.Expr, ...exprs: qb.Expr[]) => qb.Expr; | ||
or: (expr: qb.Expr, ...exprs: qb.Expr[]) => qb.Expr; | ||
fn: (name: string, ...args: any[]) => qb.Expr; | ||
null: (expr: qb.Expr) => qb.Expr; | ||
notNull: (expr: qb.Expr) => qb.Expr; | ||
caseWhen: (...args: qb.Expr[]) => qb.Expr; | ||
caseWhen: (arg: qb.Expr, ...args: qb.Expr[]) => qb.Expr; | ||
in: (expr: qb.Expr, values: qb.Sql | qb.Value[]) => qb.Expr; | ||
@@ -63,0 +63,0 @@ }; |
@@ -16,3 +16,3 @@ "use strict"; | ||
function merge(...m) { | ||
return r.reduce(r.merge, {}, m); | ||
return r.reduce(r.mergeRight, {}, m); | ||
} | ||
@@ -123,3 +123,5 @@ exports.merge = merge; | ||
nullsFirst === undefined | ||
? direction === 'DESC' ? true : false | ||
? direction === 'DESC' | ||
? true | ||
: false | ||
: nullsFirst; | ||
@@ -167,8 +169,16 @@ const nullsFirstString = nullsFirst ? 'NULLS FIRST' : 'NULLS LAST'; | ||
like: binaryExprHandler('like'), | ||
and: (...exprs) => ['and', ...exprs], | ||
or: (...exprs) => ['or', ...exprs], | ||
and: (expr, ...exprs) => [ | ||
'and', | ||
expr, | ||
...exprs, | ||
], | ||
or: (expr, ...exprs) => ['or', expr, ...exprs], | ||
fn: (name, ...args) => ['%', name, ...args], | ||
null: (expr) => ['null', expr], | ||
notNull: (expr) => ['not_null', expr], | ||
caseWhen: (...args) => ['case_when', ...args], | ||
caseWhen: (arg, ...args) => [ | ||
'case_when', | ||
arg, | ||
...args, | ||
], | ||
in: (expr, values) => ['in', expr, ...(Array.isArray(values) ? values : [values])], | ||
@@ -175,0 +185,0 @@ }; |
@@ -13,5 +13,11 @@ export interface InlineParam { | ||
export declare type VarOperator = 'and' | 'or' | 'case_when' | 'in'; | ||
export declare type FunctionCall = ['%', any]; | ||
export interface FunctionCall extends Array<any> { | ||
0: '%'; | ||
} | ||
export interface VarExpr extends Array<any> { | ||
0: VarOperator; | ||
1: any; | ||
} | ||
export declare type TableExpr = string | [string | Sql, string] | Sql; | ||
export declare type Expr = [BinaryOperator, ExprOperand, ExprOperand] | string | [VarOperator, any] | FunctionCall | [UnaryOperator, any] | Value | Sql; | ||
export declare type Expr = [BinaryOperator, ExprOperand, ExprOperand] | string | VarExpr | FunctionCall | [UnaryOperator, any] | Value | Sql; | ||
export declare type Join = ['INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS', TableExpr, Expr]; | ||
@@ -18,0 +24,0 @@ export declare type OrderBy = [Expr, 'ASC' | 'DESC', 'NULLS FIRST' | 'NULLS LAST']; |
{ | ||
"name": "@imatic/pgqb", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "Functional PostgreSQL query builder", | ||
@@ -9,16 +9,21 @@ "main": "./dist/index.js", | ||
"license": "MIT", | ||
"keywords": ["sql", "query", "querybuilder", "postgresql"], | ||
"keywords": [ | ||
"sql", | ||
"query", | ||
"querybuilder", | ||
"postgresql" | ||
], | ||
"dependencies": { | ||
"@types/ramda": "^0.24.3", | ||
"ramda": "^0.24.1", | ||
"@types/ramda": "^0.26.12", | ||
"ramda": "^0.26.1", | ||
"sql-template-strings": "^2.2.2", | ||
"typescript": "^2.3.4" | ||
"typescript": "^3.5.2" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.0.0", | ||
"@types/mocha": "^2.2.41", | ||
"@types/mocha": "^5.2.7", | ||
"chai": "^4.1.0", | ||
"mocha": "^3.4.2", | ||
"mocha": "^6.1.4", | ||
"prettier": "^1.4.2", | ||
"ts-node": "^3.0.4", | ||
"ts-node": "^8.3.0", | ||
"tslint": "^5.4.3" | ||
@@ -31,7 +36,5 @@ }, | ||
"test": "mocha --require ts-node/register --sort './tests/**/*.ts'", | ||
"test:watch": | ||
"mocha --require ts-node/register --sort './tests/**/*.ts' --watch-extensions 'ts' --watch", | ||
"test:watch": "mocha --require ts-node/register --sort './tests/**/*.ts' --watch-extensions 'ts' --watch", | ||
"tslint": "tslint --project . --exclude 'dist/**'", | ||
"prettier": | ||
"prettier --tab-width 4 --single-quote --trailing-comma 'es5' --no-bracket-spacing --write 'bin/**/*.ts' 'src/**/*.ts' 'tests/**/*.ts'" | ||
"prettier": "prettier --tab-width 4 --single-quote --trailing-comma 'es5' --no-bracket-spacing --write 'bin/**/*.ts' 'src/**/*.ts' 'tests/**/*.ts'" | ||
}, | ||
@@ -38,0 +41,0 @@ "engines": { |
@@ -16,3 +16,3 @@ import * as qb from './qb'; | ||
export function merge(...m: qb.Sql[]): qb.Sql { | ||
return r.reduce(r.merge, {}, m); | ||
return r.reduce<qb.Sql, qb.Sql>(r.mergeRight, {}, m); | ||
} | ||
@@ -26,3 +26,6 @@ | ||
values: (v1: qb.Value[][], v2: qb.Value[][]): qb.Value[][] => | ||
r.map(k => r.concat(v1[k], v2[k]), Object.keys(v1)), | ||
r.map( | ||
k => r.concat(v1[k] as qb.Value[], v2[k] as qb.Value[]), | ||
Object.keys(v1) | ||
), | ||
where: (e1: qb.Expr, e2: qb.Expr) => ['and', e1, e2], | ||
@@ -150,3 +153,5 @@ set: (e1: qb.Expr[], e2: qb.Expr[]) => r.concat(e1, e2), | ||
nullsFirst === undefined | ||
? direction === 'DESC' ? true : false | ||
? direction === 'DESC' | ||
? true | ||
: false | ||
: nullsFirst; | ||
@@ -176,4 +181,4 @@ const nullsFirstString = nullsFirst ? 'NULLS FIRST' : 'NULLS LAST'; | ||
function binaryExprHandler(operator) { | ||
return (expr1: qb.Expr, expr2: qb.Expr): qb.Expr => [ | ||
function binaryExprHandler(operator: qb.BinaryOperator) { | ||
return (expr1: qb.ExprOperand, expr2: qb.ExprOperand): qb.Expr => [ | ||
operator, | ||
@@ -197,4 +202,8 @@ expr1, | ||
like: binaryExprHandler('like'), | ||
and: (...exprs: qb.Expr[]): qb.Expr => ['and', ...exprs] as qb.Expr, | ||
or: (...exprs: qb.Expr[]): qb.Expr => ['or', ...exprs] as qb.Expr, | ||
and: (expr: qb.Expr, ...exprs: qb.Expr[]): qb.Expr => [ | ||
'and', | ||
expr, | ||
...exprs, | ||
], | ||
or: (expr: qb.Expr, ...exprs: qb.Expr[]): qb.Expr => ['or', expr, ...exprs], | ||
fn: (name: string, ...args: any[]): qb.Expr => | ||
@@ -204,4 +213,7 @@ ['%', name, ...args] as qb.Expr, | ||
notNull: (expr: qb.Expr): qb.Expr => ['not_null', expr], | ||
caseWhen: (...args: qb.Expr[]): qb.Expr => | ||
['case_when', ...args] as qb.Expr, | ||
caseWhen: (arg: qb.Expr, ...args: qb.Expr[]): qb.Expr => [ | ||
'case_when', | ||
arg, | ||
...args, | ||
], | ||
in: (expr: qb.Expr, values: qb.Value[] | qb.Sql) => | ||
@@ -208,0 +220,0 @@ ['in', expr, ...(Array.isArray(values) ? values : [values])] as qb.Expr, |
@@ -32,4 +32,11 @@ import * as r from 'ramda'; | ||
export type FunctionCall = ['%', any]; | ||
export interface FunctionCall extends Array<any> { | ||
0: '%'; | ||
} | ||
export interface VarExpr extends Array<any> { | ||
0: VarOperator; | ||
1: any; | ||
} | ||
export type TableExpr = string | [string | Sql, string] | Sql; | ||
@@ -40,3 +47,3 @@ | ||
| string | ||
| [VarOperator, any] | ||
| VarExpr | ||
| FunctionCall | ||
@@ -177,3 +184,3 @@ | [UnaryOperator, any] | ||
function convertObjectValue(val: ObjectValue): SQLStatement { | ||
const inlineParam = r.prop<any>('ip', val); | ||
const inlineParam = r.prop<any, any>('ip', val); | ||
if (inlineParam !== undefined) { | ||
@@ -183,3 +190,3 @@ return SQL`${inlineParam}`; | ||
const rawValue = r.prop<any>('r', val); | ||
const rawValue = r.prop<any, any>('r', val); | ||
if (rawValue !== undefined) { | ||
@@ -501,3 +508,6 @@ return SQL``.append(rawValue); | ||
const handler = r.prop<ExprHandler | undefined>(r.head(expr), exprHandlers); | ||
const handler = r.prop<keyof ExprToHandlerMap, ExprToHandlerMap>( | ||
r.head(expr), | ||
exprHandlers | ||
); | ||
if (!handler) { | ||
@@ -527,3 +537,3 @@ throw new Error( | ||
function clauseToSql(m: Sql, clauseKey: string): SQLStatement | string { | ||
const handler = r.prop<ClauseHandler | undefined>( | ||
const handler = r.prop<keyof ClauseToHandlerMap, ClauseToHandlerMap>( | ||
clauseKey, | ||
@@ -530,0 +540,0 @@ clauseHandlers |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1914
82595
+ Added@types/ramda@0.26.44(transitive)
+ Addedramda@0.26.1(transitive)
+ Addedts-toolbelt@6.15.5(transitive)
+ Addedtypescript@3.9.10(transitive)
- Removed@types/ramda@0.24.18(transitive)
- Removedramda@0.24.1(transitive)
- Removedtypescript@2.9.2(transitive)
Updated@types/ramda@^0.26.12
Updatedramda@^0.26.1
Updatedtypescript@^3.5.2