New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pgsql-ast-parser

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgsql-ast-parser - npm Package Compare versions

Comparing version 9.3.2 to 10.0.0

2

package.json
{
"name": "pgsql-ast-parser",
"version": "9.3.2",
"version": "10.0.0",
"description": "Yet another simple Postgres SQL parser/modifier",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -991,3 +991,3 @@ import * as a from './syntax/ast';

if (!on && !join.using) {
return null;
return join;
}

@@ -994,0 +994,0 @@ return assignChanged(join, {

import { compile, keywords } from 'moo';
import { PGComment, NodeLocation } from './syntax/ast';
import { sqlKeywords } from './keywords';
import { NodeLocation, PGComment } from './syntax/ast';
// build keywords
const keywodsMap: any = {};
const keywordsMap: any = {};
for (const k of sqlKeywords) {
keywodsMap['kw_' + k.toLowerCase()] = k;
keywordsMap['kw_' + k.toLowerCase()] = k;
}

@@ -20,3 +21,3 @@ const caseInsensitiveKeywords = (map: any) => {

match: /[eE](?!')[A-Za-z0-9_]*|[a-df-zA-DF-Z_][A-Za-z0-9_]*/,
type: caseInsensitiveKeywords(keywodsMap),
type: caseInsensitiveKeywords(keywordsMap),
value: x => x.toLowerCase(),

@@ -23,0 +24,0 @@ },

@@ -677,3 +677,4 @@ // import { IType } from '../../interfaces';

| 'RIGHT JOIN'
| 'FULL JOIN';
| 'FULL JOIN'
| 'CROSS JOIN';

@@ -680,0 +681,0 @@ export type Expr = ExprRef

@@ -248,2 +248,3 @@ import 'mocha';

checkInvalid('select ("*") from test');
checkInvalid('select * from (test)');
checkInvalid('select * from (select id from test)'); // <== missing alias

@@ -314,5 +315,9 @@

checkInvalid('select * from ta right inner join tb on ta.id=tb.id');
checkInvalid('select * from ta cross inner join tb on ta.id=tb.id');
checkInvalid('select * from ta cross outer join tb on ta.id=tb.id');
checkSelect(['select * from ta join tb on ta.id=tb.id'
, 'select * from ta inner join tb on ta.id=tb.id']
, 'select * from ta inner join tb on ta.id=tb.id'
, 'select * from (ta join tb on ta.id=tb.id)'
, 'select * from (((ta join tb on ta.id=tb.id)))']
, buildJoin('INNER JOIN'));

@@ -333,3 +338,116 @@

checkSelect('select * from ta cross join tb on ta.id=tb.id'
, buildJoin('CROSS JOIN'));
// implicit cross join
checkSelect('select * from ta, tb where ta.id=tb.id',
{
type: 'select',
columns: [{ expr: star }],
from: [
tbl('ta'),
tbl('tb'),
],
where: {
type: 'binary',
op: '=',
left: {
type: 'ref',
table: { name: 'ta' },
name: 'id',
},
right: {
type: 'ref',
table: { name: 'tb' },
name: 'id',
}
}
}
);
// implicit cross join multiple tables
checkSelect('select * from ta, tb, tc, td',
{
type: 'select',
columns: [{ expr: star }],
from: [
tbl('ta'),
tbl('tb'),
tbl('tc'),
tbl('td'),
]
}
);
// mixed join
checkSelect('select * from ta, tb cross join tc, (select * from td) as te', {
type: 'select',
columns: [{ expr: star }],
from: [
tbl('ta'),
tbl('tb'),
{
type: 'table',
name: name('tc'),
join: {
type: 'CROSS JOIN',
},
},
{
type: 'statement',
alias: 'te',
statement: {
type: 'select',
columns: [{ expr: star }],
from: [ tbl('td') ],
},
},
],
});
// double join with and without parens
checkSelect([`select * from ta cross join tb cross join tc`
, `select * from (ta cross join tb) cross join tc`]
, {
type: 'select',
columns: [{ expr: star }],
from: [
tbl('ta'),
{
type: 'table',
name: name('tb'),
join: {
type: 'CROSS JOIN',
},
},
{
type: 'table',
name: name('tc'),
join: {
type: 'CROSS JOIN',
},
}
],
}
);
// join, then implicit cross join
checkSelect(`select * from (ta cross join tb), tc`
, {
type: 'select',
columns: [{ expr: star }],
from: [
tbl('ta'),
{
type: 'table',
name: name('tb'),
join: {
type: 'CROSS JOIN',
},
},
tbl('tc'),
],
}
);
checkSelect(`SELECT *

@@ -336,0 +454,0 @@ FROM STUD_ASS_PROGRESS

@@ -1265,3 +1265,9 @@ import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper';

ret.push('FROM ');
for (const f of s.from) {
const tblCnt = s.from.length
for (let i = 0; i < tblCnt; i++) {
const f = s.from[i];
if (i > 0 && !f.join) {
// implicit cross join (https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FROM)
ret.push(',')
}
m.from(f);

@@ -1268,0 +1274,0 @@ }

@@ -491,3 +491,3 @@ import { nil } from '../utils';

}
export declare type JoinType = 'INNER JOIN' | 'LEFT JOIN' | 'RIGHT JOIN' | 'FULL JOIN';
export declare type JoinType = 'INNER JOIN' | 'LEFT JOIN' | 'RIGHT JOIN' | 'FULL JOIN' | 'CROSS JOIN';
export declare type Expr = ExprRef | ExprParameter | ExprList | ExprArrayFromSelect | ExprNull | ExprExtract | ExprInteger | ExprDefault | ExprMember | ExprValueKeyword | ExprArrayIndex | ExprNumeric | ExprString | ExprCase | ExprBinary | ExprUnary | ExprCast | ExprBool | ExprCall | SelectStatement | WithStatement | ExprConstant | ExprTernary | ExprOverlay | ExprSubstring;

@@ -494,0 +494,0 @@ /**

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

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