Skip to content

Commit

Permalink
Identify PostgreSQL data types, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Nov 27, 2023
1 parent 7978ec3 commit 290f3b7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 21 deletions.
52 changes: 52 additions & 0 deletions docs/datatypeCase.md
Original file line number Diff line number Diff line change
@@ -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()
)
```
47 changes: 26 additions & 21 deletions src/languages/postgresql/postgresql.keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -120,7 +114,6 @@ export const keywords = flatKeywordList({
'DO', // reserved
'DOCUMENT',
'DOMAIN',
'DOUBLE',
'DROP',
'EACH',
'ELSE', // reserved
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -310,7 +297,6 @@ export const keywords = flatKeywordList({
'QUOTE',
'RANGE',
'READ',
'REAL', // (cannot be function or type)
'REASSIGN',
'RECHECK',
'RECURSIVE',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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)
Expand All @@ -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',
],
});

0 comments on commit 290f3b7

Please sign in to comment.