From 290f3b767492d5e3204866447f9f4e4c098f825f Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Mon, 27 Nov 2023 18:51:29 +0100 Subject: [PATCH] Identify PostgreSQL data types, add docs --- docs/datatypeCase.md | 52 +++++++++++++++++++ .../postgresql/postgresql.keywords.ts | 47 +++++++++-------- 2 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 docs/datatypeCase.md diff --git a/docs/datatypeCase.md b/docs/datatypeCase.md new file mode 100644 index 0000000000..fb89b8eaa2 --- /dev/null +++ b/docs/datatypeCase.md @@ -0,0 +1,52 @@ +# datatypeCase (experimental) + +Converts datatypes to upper- or lowercase. + +This option doesn't yet support all types of data types: + +- multi-word data types with non-datatype keywords like `timestamp with time zone` are not fully supported - the `WITH` will be cased as a normal keyword + +## Options + +- `"preserve"` (default) preserves the original case. +- `"upper"` converts to uppercase. +- `"lower"` converts to lowercase. + +### preserve + +```sql +CREATE TABLE + users ( + id InTeGeR PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + first_name VarChaR(30) NOT NULL, + bio teXT, + is_email_verified BooL NOT NULL DEFAULT FALSE, + created_timestamp timestamPtz NOT NULL DEFAULT NOW() + ) +``` + +### upper + +```sql +CREATE TABLE + users ( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + first_name VARCHAR(30) NOT NULL, + bio TEXT, + is_email_verified BOOL NOT NULL DEFAULT FALSE, + created_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW() + ) +``` + +### lower + +```sql +CREATE TABLE + users ( + id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + first_name varchar(30) NOT NULL, + bio text, + is_email_verified bool NOT NULL DEFAULT FALSE, + created_timestamp timestamptz NOT NULL DEFAULT NOW() + ) +``` diff --git a/src/languages/postgresql/postgresql.keywords.ts b/src/languages/postgresql/postgresql.keywords.ts index 743d3dae5a..dbb81d99e3 100644 --- a/src/languages/postgresql/postgresql.keywords.ts +++ b/src/languages/postgresql/postgresql.keywords.ts @@ -35,10 +35,7 @@ export const keywords = flatKeywordList({ 'BEFORE', 'BEGIN', 'BETWEEN', // (cannot be function or type) - 'BIGINT', // (cannot be function or type) 'BINARY', // reserved (can be function or type) - 'BIT', // (cannot be function or type) - 'BOOLEAN', // (cannot be function or type) 'BOTH', // reserved 'BREADTH', 'BY', @@ -51,8 +48,6 @@ export const keywords = flatKeywordList({ 'CAST', // reserved 'CATALOG', 'CHAIN', - 'CHAR', // (cannot be function or type), requires AS - 'CHARACTER', // (cannot be function or type), requires AS 'CHARACTERISTICS', 'CHECK', // reserved 'CHECKPOINT', @@ -99,7 +94,6 @@ export const keywords = flatKeywordList({ 'DAY', // requires AS 'DEALLOCATE', 'DEC', // (cannot be function or type) - 'DECIMAL', // (cannot be function or type) 'DECLARE', 'DEFAULT', // reserved 'DEFAULTS', @@ -120,7 +114,6 @@ export const keywords = flatKeywordList({ 'DO', // reserved 'DOCUMENT', 'DOMAIN', - 'DOUBLE', 'DROP', 'EACH', 'ELSE', // reserved @@ -148,7 +141,6 @@ export const keywords = flatKeywordList({ 'FILTER', // requires AS 'FINALIZE', 'FIRST', - 'FLOAT', // (cannot be function or type) 'FOLLOWING', 'FOR', // reserved, requires AS 'FORCE', @@ -195,10 +187,7 @@ export const keywords = flatKeywordList({ 'INSENSITIVE', 'INSERT', 'INSTEAD', - 'INT', // (cannot be function or type) - 'INTEGER', // (cannot be function or type) 'INTERSECT', // reserved, requires AS - 'INTERVAL', // (cannot be function or type) 'INTO', // reserved, requires AS 'INVOKER', 'IS', // reserved (can be function or type) @@ -260,7 +249,6 @@ export const keywords = flatKeywordList({ 'NULL', // reserved 'NULLIF', // (cannot be function or type) 'NULLS', - 'NUMERIC', // (cannot be function or type) 'OBJECT', 'OF', 'OFF', @@ -295,7 +283,6 @@ export const keywords = flatKeywordList({ 'POLICY', 'POSITION', // (cannot be function or type) 'PRECEDING', - 'PRECISION', // (cannot be function or type), requires AS 'PREPARE', 'PREPARED', 'PRESERVE', @@ -310,7 +297,6 @@ export const keywords = flatKeywordList({ 'QUOTE', 'RANGE', 'READ', - 'REAL', // (cannot be function or type) 'REASSIGN', 'RECHECK', 'RECURSIVE', @@ -363,7 +349,6 @@ export const keywords = flatKeywordList({ 'SIMILAR', // reserved (can be function or type) 'SIMPLE', 'SKIP', - 'SMALLINT', // (cannot be function or type) 'SNAPSHOT', 'SOME', // reserved 'SQL', @@ -391,11 +376,8 @@ export const keywords = flatKeywordList({ 'TEMP', 'TEMPLATE', 'TEMPORARY', - 'TEXT', 'THEN', // reserved 'TIES', - 'TIME', // (cannot be function or type) - 'TIMESTAMP', // (cannot be function or type) 'TO', // reserved, requires AS 'TRAILING', // reserved 'TRANSACTION', @@ -427,9 +409,7 @@ export const keywords = flatKeywordList({ 'VALIDATOR', 'VALUE', 'VALUES', // (cannot be function or type) - 'VARCHAR', // (cannot be function or type) 'VARIADIC', // reserved - 'VARYING', // requires AS 'VERBOSE', // reserved (can be function or type) 'VERSION', 'VIEW', @@ -445,7 +425,6 @@ export const keywords = flatKeywordList({ 'WORK', 'WRAPPER', 'WRITE', - 'XML', 'XMLATTRIBUTES', // (cannot be function or type) 'XMLCONCAT', // (cannot be function or type) 'XMLELEMENT', // (cannot be function or type) @@ -459,6 +438,32 @@ export const keywords = flatKeywordList({ 'XMLTABLE', // (cannot be function or type) 'YEAR', // requires AS 'YES', + ], + // https://www.postgresql.org/docs/current/datatype.html + datatypes: [ + 'BIGINT', // (cannot be function or type) + 'BIT', // (cannot be function or type) + 'BOOL', // (cannot be function or type) + 'BOOLEAN', // (cannot be function or type) + 'CHAR', // (cannot be function or type), requires AS + 'CHARACTER', // (cannot be function or type), requires AS + 'DECIMAL', // (cannot be function or type) + 'DOUBLE', + 'FLOAT', // (cannot be function or type) + 'INT', // (cannot be function or type) + 'INTEGER', // (cannot be function or type) + 'INTERVAL', // (cannot be function or type) + 'NUMERIC', // (cannot be function or type) + 'PRECISION', // (cannot be function or type), requires AS + 'REAL', // (cannot be function or type) + 'SMALLINT', // (cannot be function or type) + 'TEXT', + 'TIME', // (cannot be function or type) + 'TIMESTAMP', // (cannot be function or type) + 'TIMESTAMPTZ', // (cannot be function or type) + 'VARCHAR', // (cannot be function or type) + 'VARYING', // requires AS + 'XML', 'ZONE', ], });