Skip to content

Commit dffc66d

Browse files
committed
refactor: Standardizes the types so that it is more inline with the other APIs
schema_name -> schema
1 parent 20e6098 commit dffc66d

File tree

6 files changed

+15
-27
lines changed

6 files changed

+15
-27
lines changed

dist/api/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ router.get('/', function (req, res) { return __awaiter(void 0, void 0, void 0, f
6565
});
6666
}); });
6767
var removeSystemSchemas = function (data) {
68-
return data.filter(function (x) { return !schemas_1.DEFAULT_SYSTEM_SCHEMAS.includes(x.schema_name); });
68+
return data.filter(function (x) { return !schemas_1.DEFAULT_SYSTEM_SCHEMAS.includes(x.schema); });
6969
};
7070
module.exports = router;

dist/lib/sql/types/list.sql

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
SELECT
2+
(t.typname || '.' || n.nspname) as type_id,
23
t.typname AS name,
4+
n.nspname as schema,
35
pg_catalog.Format_type ( t.oid, NULL ) AS format,
4-
n.nspname as schema_name,
56
pg_catalog.obj_description ( t.oid, 'pg_type' ) AS description,
6-
CASE
7-
WHEN t.typrelid != 0 THEN Cast ( 'tuple' AS pg_catalog.TEXT )
8-
WHEN t.typlen < 0 THEN Cast ( 'var' AS pg_catalog.TEXT )
9-
ELSE Cast ( t.typlen AS pg_catalog.TEXT )
10-
END AS size,
117
array (
128
select e.enumlabel
139
FROM pg_catalog.pg_enum e
@@ -24,6 +20,4 @@ and NOT EXISTS (
2420
SELECT 1
2521
FROM pg_catalog.pg_type el
2622
WHERE el.oid = t.typelem AND el.typarray = t.oid
27-
)
28-
AND pg_catalog.pg_type_is_visible ( t.oid )
29-
ORDER BY 1, 2;
23+
);

src/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ router.get('/', async (req, res) => {
2020

2121

2222
const removeSystemSchemas = (data: Types.Type[]) => {
23-
return data.filter((x) => !DEFAULT_SYSTEM_SCHEMAS.includes(x.schema_name))
23+
return data.filter((x) => !DEFAULT_SYSTEM_SCHEMAS.includes(x.schema))
2424
}
2525

2626

src/lib/interfaces/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export namespace Types {
22

33
export interface Type {
4+
type_id: string
45
name: string
6+
schema: string
57
format: string
6-
schema_name: string
78
description: string
8-
size: string
9-
enums: string
9+
enums: string[]
1010
}
1111

1212

src/lib/sql/types/list.sql

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
SELECT
2+
(t.typname || '.' || n.nspname) as type_id,
23
t.typname AS name,
4+
n.nspname as schema,
35
pg_catalog.Format_type ( t.oid, NULL ) AS format,
4-
n.nspname as schema_name,
56
pg_catalog.obj_description ( t.oid, 'pg_type' ) AS description,
6-
CASE
7-
WHEN t.typrelid != 0 THEN Cast ( 'tuple' AS pg_catalog.TEXT )
8-
WHEN t.typlen < 0 THEN Cast ( 'var' AS pg_catalog.TEXT )
9-
ELSE Cast ( t.typlen AS pg_catalog.TEXT )
10-
END AS size,
117
array (
128
select e.enumlabel
139
FROM pg_catalog.pg_enum e
@@ -24,6 +20,4 @@ and NOT EXISTS (
2420
SELECT 1
2521
FROM pg_catalog.pg_type el
2622
WHERE el.oid = t.typelem AND el.typarray = t.oid
27-
)
28-
AND pg_catalog.pg_type_is_visible ( t.oid )
29-
ORDER BY 1, 2;
23+
);

test/integration/index.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ describe('/types', () => {
103103
it('GET', async () => {
104104
const res = await axios.get(`${URL}/types`)
105105
// console.log('res.data', res.data)
106-
const datum = res.data.find((x) => x.schema_name == 'public')
107-
const notIncluded = res.data.find((x) => x.schema_name == 'pg_toast')
106+
const datum = res.data.find((x) => x.schema == 'public')
107+
const notIncluded = res.data.find((x) => x.schema == 'pg_toast')
108108
assert.equal(res.status, STATUS.SUCCESS)
109109
assert.equal(true, !!datum)
110110
assert.equal(true, !notIncluded)
111111
})
112112
it('GET with system types', async () => {
113113
const res = await axios.get(`${URL}/types?includeSystemSchemas=true`)
114114
// console.log('res.data', res.data)
115-
const datum = res.data.find((x) => x.schema_name == 'public')
116-
const included = res.data.find((x) => x.schema_name == 'pg_catalog')
115+
const datum = res.data.find((x) => x.schema == 'public')
116+
const included = res.data.find((x) => x.schema == 'pg_catalog')
117117
assert.equal(res.status, STATUS.SUCCESS)
118118
assert.equal(true, !!datum)
119119
assert.equal(true, !!included)

0 commit comments

Comments
 (0)