pgsql-ast-parser
Advanced tools
Comparing version 1.5.0 to 1.5.1
{ | ||
"name": "pgsql-ast-parser", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Yet another simple Postgres SQL parser/modifier", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -64,3 +64,3 @@ import 'mocha'; | ||
name: 'a', | ||
dataType: { name: 'jsonb' }, | ||
dataType: { type: 'jsonb' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -79,3 +79,3 @@ }, | ||
name: 'a', | ||
dataType: { name: 'jsonb' }, | ||
dataType: { type: 'jsonb' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -113,3 +113,3 @@ }, | ||
type: 'set type', | ||
dataType: { name: 'jsonb' }, | ||
dataType: { type: 'jsonb' }, | ||
} | ||
@@ -116,0 +116,0 @@ } |
@@ -266,12 +266,6 @@ // import { IType } from '../../interfaces'; | ||
export type DataTypeDef = ArrayDataTypeDef | BasicDataTypeDef; | ||
export interface ArrayDataTypeDef { | ||
kind: 'array'; | ||
arrayOf: DataTypeDef; | ||
} | ||
export interface BasicDataTypeDef extends QName { | ||
kind?: undefined; | ||
export interface DataTypeDef { | ||
type: string; | ||
length?: number; | ||
arrayOf?: DataTypeDef; | ||
} | ||
@@ -278,0 +272,0 @@ |
@@ -12,31 +12,6 @@ import 'mocha'; | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
}); | ||
checkCreateTable(['create table test(value pg_catalog.text)'], { | ||
type: 'create table', | ||
name: 'test', | ||
columns: [{ | ||
name: 'value', | ||
dataType: { | ||
name: 'text', | ||
schema: 'pg_catalog', | ||
}, | ||
}], | ||
}); | ||
checkCreateTable(['create table test(value pg_catalog.varchar(12))'], { | ||
type: 'create table', | ||
name: 'test', | ||
columns: [{ | ||
name: 'value', | ||
dataType: { | ||
schema: 'pg_catalog', | ||
name: 'varchar', | ||
length: 12, | ||
}, | ||
}], | ||
}); | ||
checkCreateTable(['create table if not exists test(value text)'], { | ||
@@ -48,3 +23,3 @@ type: 'create table', | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
@@ -58,3 +33,3 @@ }); | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'primary key' }], | ||
@@ -70,3 +45,3 @@ }], | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'unique' }], | ||
@@ -82,3 +57,3 @@ }], | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'unique' }, { type: 'not null' }], | ||
@@ -94,6 +69,3 @@ }], | ||
name: 'value', | ||
dataType: { | ||
kind: 'array', | ||
arrayOf: { name: 'text' } | ||
}, | ||
dataType: { type: 'array', arrayOf: { type: 'text' } }, | ||
}], | ||
@@ -109,6 +81,6 @@ }); | ||
dataType: { | ||
kind: 'array', | ||
type: 'array', | ||
arrayOf: { | ||
kind: 'array', | ||
arrayOf: { name: 'text' } | ||
type: 'array', | ||
arrayOf: { type: 'text' } | ||
} | ||
@@ -124,3 +96,3 @@ }, | ||
name: 'value', | ||
dataType: { name: 'timestamp with time zone' }, | ||
dataType: { type: 'timestamp with time zone' }, | ||
}], | ||
@@ -137,3 +109,3 @@ }); | ||
name: 'value', | ||
dataType: { name: 'timestamp' }, | ||
dataType: { type: 'timestamp' }, | ||
}], | ||
@@ -149,7 +121,7 @@ }); | ||
name: 'id', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'primary key' }], | ||
}, { | ||
name: 'value', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'unique' }, { type: 'not null' }], | ||
@@ -164,3 +136,3 @@ }], | ||
name: 'id', | ||
dataType: { name: 'serial' }, | ||
dataType: { type: 'serial' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -177,6 +149,6 @@ }], | ||
name: 'a', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}, { | ||
name: 'b', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
@@ -196,3 +168,3 @@ constraints: [{ | ||
name: 'price', | ||
dataType: { name: 'numeric' }, | ||
dataType: { type: 'numeric' }, | ||
constraints: [{ | ||
@@ -223,3 +195,3 @@ type: 'check', | ||
name: 'a', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
@@ -243,3 +215,3 @@ constraints: [{ | ||
name: 'a', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
@@ -263,11 +235,11 @@ constraints: [{ | ||
name: 'id', | ||
dataType: { name: 'character varying' }, | ||
dataType: { type: 'character varying' }, | ||
constraints: [{ type: 'not null' }], | ||
}, { | ||
name: 'b', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ type: 'not null' }], | ||
}, { | ||
name: 'c', | ||
dataType: { name: 'character varying' }, | ||
dataType: { type: 'character varying' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -277,4 +249,4 @@ }, { | ||
dataType: { | ||
kind: 'array', | ||
arrayOf: { name: 'jsonb' } | ||
type: 'array', | ||
arrayOf: { type: 'jsonb' } | ||
}, | ||
@@ -284,3 +256,3 @@ constraints: [{ type: 'not null' }], | ||
name: 'e', | ||
dataType: { name: 'jsonb' }, | ||
dataType: { type: 'jsonb' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -309,3 +281,3 @@ }], | ||
name: 'a', | ||
dataType: { name: 'character varying' }, | ||
dataType: { type: 'character varying' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -318,3 +290,3 @@ collate: { | ||
name: 'b', | ||
dataType: { name: 'character varying' }, | ||
dataType: { type: 'character varying' }, | ||
constraints: [{ type: 'not null' }], | ||
@@ -338,3 +310,3 @@ collate: { | ||
name: 'feature', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
constraints: [{ | ||
@@ -344,3 +316,3 @@ type: 'default', | ||
type: 'cast', | ||
to: { name: 'text' }, | ||
to: { type: 'text' }, | ||
operand: { | ||
@@ -367,6 +339,6 @@ type: 'string', | ||
name: 'update_date', | ||
dataType: { name: 'timestamp without time zone' }, | ||
dataType: { type: 'timestamp without time zone' }, | ||
}, { | ||
name: 'creation_date', | ||
dataType: { name: 'timestamp without time zone' }, | ||
dataType: { type: 'timestamp without time zone' }, | ||
constraints: [{ | ||
@@ -394,3 +366,3 @@ type: 'default', | ||
name: 'categoryid', | ||
dataType: { name: 'text' }, | ||
dataType: { type: 'text' }, | ||
}], | ||
@@ -429,3 +401,3 @@ constraints: [{ | ||
columns: [{ | ||
dataType: { name: 'int' }, | ||
dataType: { type: 'int' }, | ||
name: 'color_id', | ||
@@ -446,3 +418,3 @@ constraints: [{ | ||
columns: [{ | ||
dataType: { name: 'int' }, | ||
dataType: { type: 'int' }, | ||
name: 'color_id', | ||
@@ -449,0 +421,0 @@ constraints: [{ |
@@ -195,3 +195,3 @@ import 'mocha'; | ||
type: 'cast', | ||
to: { name: 'jsonb' }, | ||
to: { type: 'jsonb' }, | ||
operand: { | ||
@@ -206,3 +206,3 @@ type: 'ref', | ||
type: 'cast', | ||
to: { name: 'json' }, | ||
to: { type: 'json' }, | ||
operand: { | ||
@@ -214,3 +214,3 @@ type: 'member', | ||
type: 'cast', | ||
to: { name: 'jsonb' }, | ||
to: { type: 'jsonb' }, | ||
operand: { | ||
@@ -459,3 +459,3 @@ type: 'ref', | ||
type: 'cast', | ||
to: { name: 'jsonb' }, | ||
to: { type: 'jsonb' }, | ||
operand: { | ||
@@ -477,3 +477,3 @@ type: 'ref', | ||
type: 'cast', | ||
to: { name: 'JSONB' }, | ||
to: { type: 'JSONB' }, | ||
operand: { | ||
@@ -488,3 +488,3 @@ type: 'ref', | ||
type: 'cast', | ||
to: { name: 'jsonb' }, | ||
to: { type: 'jsonb' }, | ||
operand: { | ||
@@ -491,0 +491,0 @@ type: 'binary', |
@@ -290,3 +290,3 @@ import 'mocha'; | ||
}, | ||
to: { name: 'time without time zone' }, | ||
to: { type: 'time without time zone' }, | ||
} | ||
@@ -293,0 +293,0 @@ }] |
@@ -20,3 +20,3 @@ import 'mocha'; | ||
cache: 1, | ||
as: { name: 'bigint' }, | ||
as: { type: 'bigint' }, | ||
cycle: 'cycle', | ||
@@ -23,0 +23,0 @@ } |
@@ -499,3 +499,7 @@ import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper'; | ||
dataType: d => { | ||
if (d?.kind === 'array') { | ||
if (!d?.type) { | ||
ret.push('unkown'); | ||
return; | ||
} | ||
if (d.type === 'array') { | ||
m.dataType(d.arrayOf!) | ||
@@ -505,10 +509,6 @@ ret.push('[]'); | ||
} | ||
if (!d?.name) { | ||
ret.push('unkown'); | ||
return; | ||
} | ||
visitQualifiedName(d); | ||
if (d.length) { | ||
ret.push('(', d.length.toString(), ')'); | ||
} | ||
const tname = d.length | ||
? (d.type + '(' + d.length + ')') | ||
: d.type; | ||
ret.push(name(tname)); | ||
}, | ||
@@ -515,0 +515,0 @@ |
@@ -195,10 +195,6 @@ import { nil } from '../utils'; | ||
} | ||
export declare type DataTypeDef = ArrayDataTypeDef | BasicDataTypeDef; | ||
export interface ArrayDataTypeDef { | ||
kind: 'array'; | ||
arrayOf: DataTypeDef; | ||
} | ||
export interface BasicDataTypeDef extends QName { | ||
kind?: undefined; | ||
export interface DataTypeDef { | ||
type: string; | ||
length?: number; | ||
arrayOf?: DataTypeDef; | ||
} | ||
@@ -205,0 +201,0 @@ export declare type ColumnConstraint = ColumnConstraintSimple | ColumnConstraintDefault | AlterColumnAddGenerated | ColumnConstraintCheck; |
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
899958
9802