Skip to content

Commit e18fe1f

Browse files
committed
feat: Adds the enums to every column
Fixes #12
1 parent 5324d0a commit e18fe1f

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

dist/lib/sql/tables/list.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ columns AS (
5151
(table_schema || '."' || table_name || '"') :: regclass,
5252
ordinal_position
5353
) as description,
54-
(table_schema || '.' || table_name) as table_id
54+
(table_schema || '.' || table_name) as table_id,
55+
array_to_json(array(
56+
select enumlabel
57+
FROM pg_catalog.pg_enum enums
58+
WHERE udt_name = pg_catalog.Format_type(enums.enumtypid::regclass, NULL)
59+
ORDER BY enums.enumsortorder
60+
)) AS enums
5561
from
5662
information_schema.columns
5763
),

docs/source/index.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ Get your Postgres version information.
381381
bytes: number
382382
size: string
383383
relationships: Tables.Relationship[]
384+
enums: string[]
384385
}
385386
```
386387

src/lib/interfaces/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export namespace Tables {
1010
bytes: number
1111
size: string
1212
relationships: Tables.Relationship[]
13+
enums: string[]
1314
}
1415

1516
export interface Relationship {

src/lib/sql/tables/list.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ columns AS (
5151
(table_schema || '."' || table_name || '"') :: regclass,
5252
ordinal_position
5353
) as description,
54-
(table_schema || '.' || table_name) as table_id
54+
(table_schema || '.' || table_name) as table_id,
55+
array_to_json(array(
56+
select enumlabel
57+
FROM pg_catalog.pg_enum enums
58+
WHERE udt_name = pg_catalog.Format_type(enums.enumtypid::regclass, NULL)
59+
ORDER BY enums.enumsortorder
60+
)) AS enums
5561
from
5662
information_schema.columns
5763
),

test/integration/index.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ describe('/tables', async () => {
133133
const datum = tables.data.find((x) => x.table_id == 'public.users')
134134
const idColumn = datum.columns.find((x) => x.name == 'id')
135135
const nameColumn = datum.columns.find((x) => x.name == 'name')
136+
const statusColumn = datum.columns.find((x) => x.name == 'status')
136137
assert.equal(true, !!datum)
137138
assert.equal(datum.columns.length > 0, true)
138139
assert.equal(datum.primary_keys.length > 0, true)
139140
assert.equal(idColumn.is_updatable, true)
140141
assert.equal(idColumn.is_identity, true)
141142
assert.equal(nameColumn.is_identity, false)
143+
assert.equal(statusColumn.enums.length, 2)
142144
})
143145
it('should return the grants', async () => {
144146
const tables = await axios.get(`${URL}/tables`)

test/postgres/mnt/00-init.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
CREATE TYPE public.user_status AS ENUM ('ACTIVE', 'INACTIVE');
66
CREATE TABLE public.users (
77
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
8-
name text
8+
name text,
9+
status user_status DEFAULT 'ACTIVE'
910
);
1011
INSERT INTO
1112
public.users (name)

0 commit comments

Comments
 (0)