Skip to content

Commit

Permalink
Merge e69b91f into 2249e05
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Mar 26, 2022
2 parents 2249e05 + e69b91f commit 7835c09
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 3 deletions.
30 changes: 30 additions & 0 deletions bin/generate-type-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const got = require('got');
const JSON5 = require('json5');

const parseDat = (subject) => {
// I was not able to identify what is the file format that pg_type.dat uses, i.e. what parser to use.
// However, making these modifications makes it similar enough to JSON5 compatible format to parse correctly.
return JSON5.parse(subject.replaceAll('#', '//').replaceAll(' => ', ': '));
};

const main = async () => {
const pgTypesDocument = await got('https://raw.githubusercontent.com/postgres/postgres/master/src/include/catalog/pg_type.dat', {
resolveBodyOnly: true,
});

const pgTypes = parseDat(pgTypesDocument)
.map((pgType) => {
return pgType.typname;
})
.sort((a, b) => {
return a.localeCompare(b);
})
.map((typeName) => {
return `'${typeName}'`;
})
.join('\n | ');

console.log(pgTypes);
};

void main();
6 changes: 6 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"got": "^11.8.3",
"json5": "^2.2.1"
}
}
112 changes: 109 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,124 @@ export type ConnectionOptions = {
username?: string,
};

/**
* Do not edit manually. This type definition is generated using: ./bin/generate-type-name.js
*/
export type TypeNameIdentifier =
// We have to provide `string` fallback for custom types.
| string
| '_record'
| 'aclitem'
| 'any'
| 'anyarray'
| 'anycompatible'
| 'anycompatiblearray'
| 'anycompatiblemultirange'
| 'anycompatiblenonarray'
| 'anycompatiblerange'
| 'anyelement'
| 'anyenum'
| 'anymultirange'
| 'anynonarray'
| 'anyrange'
| 'bit'
| 'bool'
| 'box'
| 'bpchar'
| 'bytea'
| 'char'
| 'cid'
| 'cidr'
| 'circle'
| 'cstring'
| 'date'
| 'datemultirange'
| 'daterange'
| 'event_trigger'
| 'fdw_handler'
| 'float4'
| 'float8'
| 'gtsvector'
| 'index_am_handler'
| 'inet'
| 'int2'
| 'int2vector'
| 'int4'
| 'int4multirange'
| 'int4range'
| 'int8'
| 'int8multirange'
| 'int8range'
| 'internal'
| 'interval'
| 'json'
| 'jsonb'
| 'jsonpath'
| 'language_handler'
| 'line'
| 'lseg'
| 'macaddr'
| 'macaddr8'
| 'money'
| 'name'
| 'numeric'
| 'nummultirange'
| 'numrange'
| 'oid'
| 'oidvector'
| 'path'
| 'pg_attribute'
| 'pg_brin_bloom_summary'
| 'pg_brin_minmax_multi_summary'
| 'pg_class'
| 'pg_ddl_command'
| 'pg_dependencies'
| 'pg_lsn'
| 'pg_mcv_list'
| 'pg_ndistinct'
| 'pg_node_tree'
| 'pg_proc'
| 'pg_snapshot'
| 'pg_type'
| 'point'
| 'polygon'
| 'record'
| 'refcursor'
| 'regclass'
| 'regcollation'
| 'regconfig'
| 'regdictionary'
| 'regnamespace'
| 'regoper'
| 'regoperator'
| 'regproc'
| 'regprocedure'
| 'regrole'
| 'regtype'
| 'table_am_handler'
| 'text'
| 'tid'
| 'time'
| 'timestamp'
| 'timestamptz'
| 'uuid';
| 'timetz'
| 'trigger'
| 'tsm_handler'
| 'tsmultirange'
| 'tsquery'
| 'tsrange'
| 'tstzmultirange'
| 'tstzrange'
| 'tsvector'
| 'txid_snapshot'
| 'unknown'
| 'uuid'
| 'varbit'
| 'varchar'
| 'void'
| 'xid'
| 'xid8'
| 'xml';

export type SerializableValue =
boolean | number | string | readonly SerializableValue[] | {
Expand Down Expand Up @@ -267,7 +373,7 @@ export type QueryContext = {
};

export type ArraySqlToken = {
readonly memberType: SqlToken | TypeNameIdentifier | string,
readonly memberType: SqlToken | TypeNameIdentifier,
readonly type: typeof tokens.ArrayToken,
readonly values: readonly PrimitiveValueExpression[],
};
Expand Down Expand Up @@ -299,7 +405,7 @@ export type SqlSqlToken = {
readonly values: readonly PrimitiveValueExpression[],
};

export type UnnestSqlColumn = string | readonly string[];
export type UnnestSqlColumn = TypeNameIdentifier | readonly TypeNameIdentifier[];

export type UnnestSqlToken = {
readonly columnTypes: readonly UnnestSqlColumn[],
Expand Down

0 comments on commit 7835c09

Please sign in to comment.