Skip to content

Commit 1ce02fa

Browse files
committed
refactor: match interfaces to SQL templates
1 parent 1c8f7d5 commit 1ce02fa

File tree

10 files changed

+132
-98
lines changed

10 files changed

+132
-98
lines changed

src/api/roles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { grants, roles } = sql
55
import { coalesceRowsToArray } from '../lib/helpers'
66
import { RunQuery } from '../lib/connectionPool'
77
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants/schemas'
8-
import { Roles } from '../lib/interfaces/roles'
8+
import { Roles } from '../lib/interfaces'
99

1010
/**
1111
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas

src/api/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sql = require('../lib/sql')
44
const { schemas } = sql
55
import { RunQuery } from '../lib/connectionPool'
66
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants/schemas'
7-
import { Schemas } from '../lib/interfaces/schemas'
7+
import { Schemas } from '../lib/interfaces'
88

99
/**
1010
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas

src/api/tables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { columns, grants, primary_keys, relationships, tables } = sql
55
import { coalesceRowsToArray } from '../lib/helpers'
66
import { RunQuery } from '../lib/connectionPool'
77
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants/schemas'
8-
import { Tables } from '../lib/interfaces/tables'
8+
import { Tables } from '../lib/interfaces'
99

1010
const router = Router()
1111
router.get('/', async (req, res) => {

src/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sql = require('../lib/sql')
44
const { types } = sql
55
import { RunQuery } from '../lib/connectionPool'
66
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants/schemas'
7-
import { Types } from '../lib/interfaces/types'
7+
import { Types } from '../lib/interfaces'
88

99
const router = Router()
1010
router.get('/', async (req, res) => {

src/lib/connectionPool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import pg = require('pg')
2+
// HACK: Number has 53 bits of precision, may overflow with bigint (64 bits).
3+
// Maybe use BigInt?
4+
// TODO: Use Date object for timestamptz?
25
pg.types.setTypeParser(20, 'text', parseInt)
36
const { Pool } = pg
47

src/lib/interfaces.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
export namespace Roles {
2+
export interface Role {
3+
name: string
4+
id: number
5+
has_create_db_privileges: boolean
6+
is_super_user: boolean
7+
has_replication_privileges: boolean
8+
can_bypass_rls: boolean
9+
valid_until: string | null
10+
user_config: string | null
11+
connections: number
12+
max_user_connections: number
13+
max_db_connections: number
14+
grants: Grant[]
15+
}
16+
17+
export interface Grant {
18+
table_id: string
19+
grantor: string
20+
grantee: string
21+
catalog: string
22+
schema: string
23+
table_name: string
24+
privilege_type: string
25+
is_grantable: boolean
26+
with_hierarchy: boolean
27+
}
28+
}
29+
30+
export namespace Schemas {
31+
export interface Schema {
32+
catalog_name: string
33+
name: string
34+
owner: string
35+
default_character_set_catalog: string | null
36+
default_character_set_schema: string | null
37+
default_character_set_name: string | null
38+
sql_path: string | null
39+
}
40+
}
41+
42+
export namespace Tables {
43+
export interface Table {
44+
table_id: string
45+
catalog: string
46+
schema: string
47+
name: string
48+
is_insertable_into: boolean
49+
is_typed: boolean
50+
bytes: number
51+
size: string
52+
53+
// pg_stat_all_tables columns
54+
sequential_scans: number
55+
sequential_scan_row_reads: number
56+
index_scans: number
57+
index_scan_row_reads: number
58+
row_inserts: number
59+
row_updates: number
60+
row_deletes: number
61+
row_hot_updates: number
62+
live_rows: number
63+
dead_rows: number
64+
rows_modified_since_analyze: number
65+
last_vacuum: string | null
66+
last_autovacuum: string | null
67+
last_analyze: string | null
68+
last_autoanalyze: string | null
69+
vacuum_count: number
70+
autovacuum_count: number
71+
analyze_count: number
72+
autoanalyze_count: number
73+
74+
columns: Column[]
75+
grants: Roles.Grant[]
76+
primary_keys: PrimaryKey[]
77+
relationships: Relationship[]
78+
}
79+
80+
export interface Column {
81+
schema: string
82+
table: string
83+
name: string
84+
default_value: string | null
85+
is_identity: boolean
86+
is_nullable: boolean
87+
is_updatable: boolean
88+
data_type: string
89+
format: string
90+
identity_generation: string | null
91+
table_id: string
92+
description: string | null
93+
enums: string[]
94+
}
95+
96+
export interface PrimaryKey {
97+
schema: string
98+
table_name: string
99+
name: string
100+
table_id: string
101+
}
102+
103+
export interface Relationship {
104+
source_table_id: string
105+
source_schema: string
106+
source_table_name: string
107+
source_column_name: string
108+
target_table_id: string
109+
target_table_schema: string
110+
target_table_name: string
111+
target_column_name: string
112+
constraint_name: string
113+
}
114+
}
115+
116+
export namespace Types {
117+
export interface Type {
118+
type_id: string
119+
name: string
120+
schema: string
121+
format: string
122+
description: string | null
123+
enums: string[]
124+
}
125+
}

src/lib/interfaces/roles.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/lib/interfaces/schemas.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/lib/interfaces/tables.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/lib/interfaces/types.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)