pgsql-ast-parser
Advanced tools
Comparing version 7.1.1 to 7.2.0
{ | ||
"name": "pgsql-ast-parser", | ||
"version": "7.1.1", | ||
"version": "7.2.0", | ||
"description": "Yet another simple Postgres SQL parser/modifier", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -169,3 +169,3 @@ import 'mocha'; | ||
assert.exists(modified); | ||
expect(toSql.statement(modified!)).to.equal('SELECT * FROM "bar"'); | ||
expect(toSql.statement(modified!)).to.equal('SELECT * FROM bar'); | ||
}) | ||
@@ -186,3 +186,3 @@ | ||
assert.exists(modified); | ||
expect(toSql.statement(modified!)).to.equal('SELECT * FROM "foo"'); | ||
expect(toSql.statement(modified!)).to.equal('SELECT * FROM foo'); | ||
}) | ||
@@ -199,3 +199,3 @@ | ||
expect(toSql.statement(result!)).to.deep.equal('SELECT "bar" FROM "test"'); | ||
expect(toSql.statement(result!)).to.deep.equal('SELECT bar FROM test'); | ||
@@ -221,3 +221,3 @@ }) | ||
expect(toSql.statement(modified!)).to.equal(`SELECT * FROM "bar"`); | ||
expect(toSql.statement(modified!)).to.equal(`SELECT * FROM bar`); | ||
}) | ||
@@ -241,5 +241,5 @@ | ||
expect(toSql.statement(modified!)).to.equal(`SELECT * FROM "foo"`); | ||
expect(toSql.statement(modified!)).to.equal(`SELECT * FROM foo`); | ||
}) | ||
}); |
@@ -6,2 +6,3 @@ import 'mocha'; | ||
import { expect } from 'chai'; | ||
import { parse } from '../parser'; | ||
@@ -8,0 +9,0 @@ |
@@ -6,2 +6,3 @@ import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper'; | ||
import { literal } from './pg-escape'; | ||
import { sqlKeywords } from './keywords'; | ||
@@ -12,12 +13,21 @@ | ||
const kwSet = new Set(sqlKeywords.map(x => x.toLowerCase())); | ||
let ret: string[] = []; | ||
function name<T extends Name>(nm: NoExtraProperties<Name, T>) { | ||
return '"' + nm.name + '"'; | ||
return ident(nm.name); | ||
} | ||
function ident(nm: string) { | ||
// only add quotes if has upper cases, or if it is a keyword. | ||
const low = nm.toLowerCase(); | ||
if (low === nm && !kwSet.has(low) && /^[a-z][a-z0-9_]+$/.test(low)) { | ||
return nm; | ||
} | ||
return '"' + nm + '"'; | ||
} | ||
function list<T>(elems: T[], act: (e: T) => any, addParen: boolean) { | ||
@@ -267,3 +277,3 @@ if (addParen) { | ||
if (cname) { | ||
ret.push(' CONSTRAINT ', name(cname)); | ||
ret.push(' CONSTRAINT ', name(cname), ' '); | ||
} | ||
@@ -738,3 +748,23 @@ addConstraint(c.constraint, m); | ||
} | ||
visitQualifiedName(d); | ||
if (d.schema) { | ||
visitQualifiedName(d); | ||
} else { | ||
// see https://www.postgresql.org/docs/13/datatype.html | ||
// & issue https://github.com/oguimbal/pgsql-ast-parser/issues/38 | ||
switch (d.name) { | ||
case 'double precision': | ||
case 'character varying': | ||
case 'bit varying': | ||
case 'time without time zone': | ||
case 'timestamp without time zone': | ||
case 'time with time zone': | ||
case 'timestamp with time zone': | ||
ret.push(d.name, ' '); | ||
break; | ||
default: | ||
visitQualifiedName(d); | ||
break; | ||
} | ||
} | ||
if (d.config?.length) { | ||
@@ -741,0 +771,0 @@ list(d.config, v => ret.push(v.toString(10)), true); |
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
1413999
165
15468