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.0.2 to 9.1.0

2

ast-mapper.d.ts

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

createEnum?(val: a.CreateEnumType): a.Statement | nil;
createCompositeType?(val: a.CreateCompositeType): a.Statement | nil;
dropIndex?: (val: a.DropIndexStatement) => a.Statement | nil;

@@ -144,2 +145,3 @@ show?: (val: a.ShowStatement) => a.Statement | nil;

createEnum(val: a.CreateEnumType): a.Statement | nil;
createCompositeType(val: a.CreateCompositeType): a.Statement | nil;
dropTable(val: a.DropTableStatement): a.Statement | nil;

@@ -146,0 +148,0 @@ dropIndex(val: a.DropIndexStatement): a.Statement | nil;

2

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

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

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

createEnum?(val: a.CreateEnumType): a.Statement | nil
createCompositeType?(val: a.CreateCompositeType): a.Statement | nil
dropIndex?: (val: a.DropIndexStatement) => a.Statement | nil

@@ -260,2 +261,4 @@ show?: (val: a.ShowStatement) => a.Statement | nil

return this.createEnum(val);
case 'create composite type':
return this.createCompositeType(val);
case 'union':

@@ -371,2 +374,9 @@ case 'union all':

createCompositeType(val: a.CreateCompositeType): a.Statement | nil {
const attributes = arrayNilMap(val.attributes, a => assignChanged(a, {
dataType: this.dataType(a.dataType),
}));
return assignChanged(val, { attributes });
}
dropTable(val: a.DropTableStatement): a.Statement | nil {

@@ -373,0 +383,0 @@ return val;

@@ -33,2 +33,3 @@ // import { IType } from '../../interfaces';

| CreateEnumType
| CreateCompositeType
| TruncateTableStatement

@@ -149,2 +150,14 @@ | DropTableStatement

export interface CreateCompositeType extends PGNode {
type: 'create composite type';
name: QName;
attributes: CompositeTypeAttribute[];
}
export interface CompositeTypeAttribute extends PGNode {
name: Name;
dataType: DataTypeDef;
collate?: Name;
}
export interface Literal extends PGNode {

@@ -348,2 +361,3 @@ value: string

expressions: IndexExpression[];
where?: Expr;
unique?: true;

@@ -698,2 +712,3 @@ ifNotExists?: true;

export type MultiplicativeOperator = '*' | '%' | '/';
export type ConstructOperator = 'AT TIME ZONE';
export type BinaryOperator = LogicOperator

@@ -704,3 +719,4 @@ | EqualityOperator

| MultiplicativeOperator
| MathOpsBinary;
| MathOpsBinary
| ConstructOperator;

@@ -707,0 +723,0 @@ export interface ExprBinary extends PGNode {

@@ -166,2 +166,25 @@ import 'mocha';

});
// fixes https://github.com/oguimbal/pg-mem/issues/89
checkCreateIndex(['CREATE UNIQUE INDEX my_idx ON my_table (col1, (col2 IS NULL)) WHERE col2 IS NULL'], {
type: 'create index',
unique: true,
table: { name: 'my_table' },
indexName: { name: 'my_idx' },
expressions: [
{ expression: { type: 'ref', name: 'col1' } },
{
expression: {
type: 'unary',
op: 'IS NULL',
operand: { type: 'ref', name: 'col2' },
}
},
],
where: {
type: 'unary',
op: 'IS NULL',
operand: { type: 'ref', name: 'col2' },
},
})
});

@@ -685,2 +685,49 @@ import 'mocha';

})
// fixes https://github.com/oguimbal/pgsql-ast-parser/issues/53
checkCreateTable(`CREATE TABLE "tb_user" (
"user_no" serial8 NOT NULL,
"reg_date" timestamptz DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Seoul') NOT NULL,
"complete_yn" boolean DEFAULT false NOT NULL
)`, {
type: 'create table',
name: { name: 'tb_user' },
columns: [
{
kind: 'column',
name: { name: 'user_no' },
dataType: { name: 'serial8' },
constraints: [{ type: 'not null' }],
},
{
kind: 'column',
dataType: { name: 'timestamptz' },
name: { name: 'reg_date' },
constraints: [
{
type: 'default',
default: {
type: 'binary',
op: 'AT TIME ZONE',
left: { type: 'keyword', keyword: 'current_timestamp' },
right: { type: 'string', value: 'Asia/Seoul' }
}
},
{
type: 'not null',
}
]
},
{
kind: 'column',
name: { name: 'complete_yn' },
dataType: { name: 'boolean' },
constraints: [
{ type: 'default', default: { type: 'boolean', value: false } },
{ type: 'not null' },
],
},
]
});
});

@@ -12,2 +12,22 @@ import 'mocha';

});
checkStatement([`CREATE TYPE weight AS (
unit text,
value double precision collate abc
)`], {
type: 'create composite type',
name: { name: 'weight' },
attributes: [
{
name: { name: 'unit' },
dataType: { name: 'text' },
},
{
name: { name: 'value' },
dataType: { name: 'double precision' },
collate: { name: 'abc' },
},
],
});
});

@@ -308,2 +308,17 @@ import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper';

createCompositeType: c => {
ret.push('CREATE TYPE ');
visitQualifiedName(c.name);
ret.push(' AS ');
list(c.attributes, x => {
ret.push(name(x.name), ' ');
m.dataType(x.dataType);
if (x.collate) {
ret.push('COLLATE ');
visitQualifiedName(x.collate);
}
}, true);
ret.push(' ');
},
setTableOwner: o => {

@@ -678,5 +693,5 @@ ret.push(' OWNER TO ', name(o.to));

m.dataType(a.type);
if (a.default){
ret.push(" = ");
m.expr(a.default);
if (a.default) {
ret.push(" = ");
m.expr(a.default);
}

@@ -862,2 +877,6 @@ }, true);

}, true);
if (c.where) {
ret.push(' WHERE ');
m.expr(c.where);
}
ret.push(' ');

@@ -868,3 +887,3 @@ },

ret.push('CREATE ');
if(t.locality) {
if (t.locality) {
ret.push(t.locality.toUpperCase(), ' ');

@@ -875,3 +894,3 @@ }

}
if(t.unlogged) {
if (t.unlogged) {
ret.push('UNLOGGED ');

@@ -878,0 +897,0 @@ }

import { nil } from '../utils';
export declare function locationOf(node: PGNode): NodeLocation;
export declare type Statement = SelectStatement | CreateTableStatement | CreateSequenceStatement | CreateIndexStatement | CreateExtensionStatement | CommitStatement | InsertStatement | UpdateStatement | ShowStatement | PrepareStatement | DeleteStatement | WithStatement | RollbackStatement | TablespaceStatement | CreateViewStatement | CreateMaterializedViewStatement | AlterTableStatement | AlterSequenceStatement | SetGlobalStatement | SetTimezone | CreateEnumType | TruncateTableStatement | DropTableStatement | DropSequenceStatement | DropIndexStatement | CommentStatement | CreateSchemaStatement | WithRecursiveStatement | RaiseStatement | ValuesStatement | CreateFunctionStatement | DoStatement | BeginStatement | StartTransactionStatement;
export declare type Statement = SelectStatement | CreateTableStatement | CreateSequenceStatement | CreateIndexStatement | CreateExtensionStatement | CommitStatement | InsertStatement | UpdateStatement | ShowStatement | PrepareStatement | DeleteStatement | WithStatement | RollbackStatement | TablespaceStatement | CreateViewStatement | CreateMaterializedViewStatement | AlterTableStatement | AlterSequenceStatement | SetGlobalStatement | SetTimezone | CreateEnumType | CreateCompositeType | TruncateTableStatement | DropTableStatement | DropSequenceStatement | DropIndexStatement | CommentStatement | CreateSchemaStatement | WithRecursiveStatement | RaiseStatement | ValuesStatement | CreateFunctionStatement | DoStatement | BeginStatement | StartTransactionStatement;
export interface PGNode {

@@ -87,2 +87,12 @@ _location?: NodeLocation;

}
export interface CreateCompositeType extends PGNode {
type: 'create composite type';
name: QName;
attributes: CompositeTypeAttribute[];
}
export interface CompositeTypeAttribute extends PGNode {
name: Name;
dataType: DataTypeDef;
collate?: Name;
}
export interface Literal extends PGNode {

@@ -243,2 +253,3 @@ value: string;

expressions: IndexExpression[];
where?: Expr;
unique?: true;

@@ -484,3 +495,4 @@ ifNotExists?: true;

export declare type MultiplicativeOperator = '*' | '%' | '/';
export declare type BinaryOperator = LogicOperator | EqualityOperator | ComparisonOperator | AdditiveOperator | MultiplicativeOperator | MathOpsBinary;
export declare type ConstructOperator = 'AT TIME ZONE';
export declare type BinaryOperator = LogicOperator | EqualityOperator | ComparisonOperator | AdditiveOperator | MultiplicativeOperator | MathOpsBinary | ConstructOperator;
export interface ExprBinary extends PGNode {

@@ -487,0 +499,0 @@ type: 'binary';

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

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