pgsql-ast-parser
Advanced tools
Comparing version 4.1.10 to 4.1.12
@@ -60,2 +60,4 @@ import * as a from './syntax/ast'; | ||
call?: (val: a.ExprCall) => a.Expr | nil; | ||
callSubstring?: (val: a.ExprSubstring) => a.Expr | nil; | ||
callOverlay?: (val: a.ExprOverlay) => a.Expr | nil; | ||
array?: (val: a.ExprList) => a.Expr | nil; | ||
@@ -182,3 +184,3 @@ constant?: (value: a.ExprLiteral) => a.Expr | nil; | ||
selectionColumn(val: a.SelectedColumn): a.SelectedColumn | nil; | ||
expr(val: a.Expr): a.Expr | nil; | ||
expr(val: a.Expr | nil): a.Expr | nil; | ||
extract(st: a.ExprExtract): a.Expr | nil; | ||
@@ -193,2 +195,4 @@ valueKeyword(val: a.ExprValueKeyword): a.Expr | nil; | ||
call(val: a.ExprCall): a.Expr | nil; | ||
callSubstring(val: a.ExprSubstring): a.Expr | nil; | ||
callOverlay(val: a.ExprOverlay): a.Expr | nil; | ||
array(val: a.ExprList): a.Expr | nil; | ||
@@ -195,0 +199,0 @@ constant(value: a.ExprLiteral): a.Expr | nil; |
{ | ||
"name": "pgsql-ast-parser", | ||
"version": "4.1.10", | ||
"version": "4.1.12", | ||
"description": "Yet another simple Postgres SQL parser/modifier", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,2 +63,4 @@ import * as a from './syntax/ast'; | ||
call?: (val: a.ExprCall) => a.Expr | nil | ||
callSubstring?: (val: a.ExprSubstring) => a.Expr | nil | ||
callOverlay?: (val: a.ExprOverlay) => a.Expr | nil | ||
array?: (val: a.ExprList) => a.Expr | nil | ||
@@ -888,3 +890,6 @@ constant?: (value: a.ExprLiteral) => a.Expr | nil | ||
expr(val: a.Expr): a.Expr | nil { | ||
expr(val: a.Expr | nil): a.Expr | nil { | ||
if (!val) { | ||
return val; | ||
} | ||
switch (val.type) { | ||
@@ -928,2 +933,6 @@ case 'binary': | ||
return this.extract(val); | ||
case 'overlay': | ||
return this.callOverlay(val); | ||
case 'substring': | ||
return this.callSubstring(val); | ||
default: | ||
@@ -1039,2 +1048,18 @@ throw NotSupported.never(val); | ||
callSubstring(val: a.ExprSubstring): a.Expr | nil { | ||
return assignChanged(val, { | ||
value: this.expr(val.value), | ||
from: this.expr(val.from), | ||
for: this.expr(val.for), | ||
}) | ||
} | ||
callOverlay(val: a.ExprOverlay): a.Expr | nil { | ||
return assignChanged(val, { | ||
value: this.expr(val.value), | ||
placing: this.expr(val.placing), | ||
from: this.expr(val.from), | ||
for: this.expr(val.for), | ||
}) | ||
} | ||
array(val: a.ExprList): a.Expr | nil { | ||
@@ -1041,0 +1066,0 @@ const expressions = arrayNilMap(val.expressions, a => this.expr(a)); |
@@ -547,5 +547,27 @@ // import { IType } from '../../interfaces'; | ||
| ExprConstant | ||
| ExprTernary; | ||
| ExprTernary | ||
| ExprOverlay | ||
| ExprSubstring; | ||
/** | ||
* Handle special syntax: overlay('12345678' placing 'ab' from 2 for 4) | ||
*/ | ||
export interface ExprOverlay { | ||
type: 'overlay'; | ||
value: Expr; | ||
placing: Expr; | ||
from: Expr; | ||
for?: Expr | nil; | ||
} | ||
/** Handle special syntax: substring('val' from 2 for 3) */ | ||
export interface ExprSubstring { | ||
type: 'substring'; | ||
value: Expr; | ||
from?: Expr | nil; | ||
for?: Expr | nil; | ||
} | ||
export type LogicOperator = 'OR' | 'AND'; | ||
@@ -552,0 +574,0 @@ export type EqualityOperator = 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE' | '=' | '!='; |
import 'mocha'; | ||
import 'chai'; | ||
import { checkTreeExpr, checkInvalidExpr } from './spec-utils'; | ||
import { checkTreeExpr, checkInvalidExpr, checkInvalid } from './spec-utils'; | ||
@@ -732,2 +732,4 @@ | ||
describe('Ternaries', () => { | ||
// === RANGE: between | ||
checkTreeExpr(['a between b and 42', '"a"between"b"and 42'], { | ||
@@ -748,2 +750,38 @@ type: 'ternary', | ||
}); | ||
// SUBSTRING FROM-FOR | ||
checkTreeExpr(`substring('val' from 2 for 3)`, { | ||
type: 'substring', | ||
value: {type: 'string', value: 'val'}, | ||
from: { type: 'integer', value: 2 }, | ||
for: { type: 'integer', value: 3 }, | ||
}); | ||
checkTreeExpr(`substring('val' from 2)`, { | ||
type: 'substring', | ||
value: {type: 'string', value: 'val'}, | ||
from: { type: 'integer', value: 2 }, | ||
}); | ||
checkTreeExpr(`substring('val' for 2)`, { | ||
type: 'substring', | ||
value: {type: 'string', value: 'val'}, | ||
for: { type: 'integer', value: 2 }, | ||
}); | ||
// OVERLAY | ||
checkTreeExpr(`overlay('12345678' placing 'ab' from 2 for 4)`, { | ||
type: 'overlay', | ||
value: { type: 'string', value: '12345678'}, | ||
placing: {type: 'string', value: 'ab'}, | ||
from: { type: 'integer', value: 2 }, | ||
for: { type: 'integer', value: 4 }, | ||
}); | ||
checkTreeExpr(`overlay('12345678' placing 'ab' from 2)`, { | ||
type: 'overlay', | ||
value: { type: 'string', value: '12345678'}, | ||
placing: {type: 'string', value: 'ab'}, | ||
from: { type: 'integer', value: 2 }, | ||
}); | ||
checkInvalid(`overlay('12345678' placing 'ab' for 4)`); | ||
checkInvalid(`overlay('12345678' from 2 for 4)`); | ||
}); | ||
@@ -750,0 +788,0 @@ |
@@ -319,2 +319,30 @@ import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper'; | ||
callOverlay: o => { | ||
ret.push('OVERLAY('); | ||
m.expr(o.value); | ||
ret.push(' PLACING '); | ||
m.expr(o.placing); | ||
ret.push(' FROM '); | ||
m.expr(o.from); | ||
if (o.for) { | ||
ret.push(' FOR '); | ||
m.expr(o.for); | ||
} | ||
ret.push(')'); | ||
}, | ||
callSubstring: s => { | ||
ret.push('SUBSTRING('); | ||
m.expr(s.value); | ||
if (s.from) { | ||
ret.push(' FROM '); | ||
m.expr(s.from); | ||
} | ||
if (s.for) { | ||
ret.push(' FOR '); | ||
m.expr(s.for); | ||
} | ||
ret.push(')'); | ||
}, | ||
binary: v => { | ||
@@ -321,0 +349,0 @@ m.expr(v.left); |
@@ -381,3 +381,20 @@ import { nil } from '../utils'; | ||
export declare type JoinType = 'INNER JOIN' | 'LEFT JOIN' | 'RIGHT JOIN' | 'FULL JOIN'; | ||
export declare type Expr = ExprRef | ExprParameter | ExprList | ExprNull | ExprExtract | ExprInteger | ExprMember | ExprValueKeyword | ExprArrayIndex | ExprNumeric | ExprString | ExprCase | ExprBinary | ExprUnary | ExprCast | ExprBool | ExprCall | SelectStatement | ExprConstant | ExprTernary; | ||
export declare type Expr = ExprRef | ExprParameter | ExprList | ExprNull | ExprExtract | ExprInteger | ExprMember | ExprValueKeyword | ExprArrayIndex | ExprNumeric | ExprString | ExprCase | ExprBinary | ExprUnary | ExprCast | ExprBool | ExprCall | SelectStatement | ExprConstant | ExprTernary | ExprOverlay | ExprSubstring; | ||
/** | ||
* Handle special syntax: overlay('12345678' placing 'ab' from 2 for 4) | ||
*/ | ||
export interface ExprOverlay { | ||
type: 'overlay'; | ||
value: Expr; | ||
placing: Expr; | ||
from: Expr; | ||
for?: Expr | nil; | ||
} | ||
/** Handle special syntax: substring('val' from 2 for 3) */ | ||
export interface ExprSubstring { | ||
type: 'substring'; | ||
value: Expr; | ||
from?: Expr | nil; | ||
for?: Expr | nil; | ||
} | ||
export declare type LogicOperator = 'OR' | 'AND'; | ||
@@ -384,0 +401,0 @@ export declare type EqualityOperator = 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE' | '=' | '!='; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1177368
12811