@travetto/model-postgres 7.1.3 → 8.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +9 -9
  2. package/src/dialect.ts +13 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-postgres",
3
- "version": "7.1.3",
3
+ "version": "8.0.0-alpha.0",
4
4
  "type": "module",
5
5
  "description": "PostgreSQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
6
6
  "keywords": [
@@ -28,16 +28,16 @@
28
28
  "directory": "module/model-postgres"
29
29
  },
30
30
  "dependencies": {
31
- "@travetto/config": "^7.1.3",
32
- "@travetto/context": "^7.1.3",
33
- "@travetto/model": "^7.1.3",
34
- "@travetto/model-query": "^7.1.3",
35
- "@travetto/model-sql": "^7.1.3",
36
- "@types/pg": "^8.16.0",
37
- "pg": "^8.16.3"
31
+ "@travetto/config": "^8.0.0-alpha.0",
32
+ "@travetto/context": "^8.0.0-alpha.0",
33
+ "@travetto/model": "^8.0.0-alpha.0",
34
+ "@travetto/model-query": "^8.0.0-alpha.0",
35
+ "@travetto/model-sql": "^8.0.0-alpha.0",
36
+ "@types/pg": "^8.18.0",
37
+ "pg": "^8.19.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@travetto/cli": "^7.1.3"
40
+ "@travetto/cli": "^8.0.0-alpha.0"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "@travetto/cli": {
package/src/dialect.ts CHANGED
@@ -47,9 +47,8 @@ export class PostgreSQLDialect extends SQLDialect {
47
47
  async describeTable(table: string): Promise<SQLTableDescription | undefined> {
48
48
  const IGNORE_FIELDS = [this.pathField.name, this.parentPathField.name, this.idxField.name].map(field => `'${field}'`);
49
49
 
50
- const [columns, foreignKeys, indices] = await Promise.all([
51
- // 1. Columns
52
- this.executeSQL<{ name: string, type: string, is_not_null: boolean }>(`
50
+ // 1. Columns
51
+ const columns = await this.executeSQL<{ name: string, type: string, is_not_null: boolean }>(`
53
52
  SELECT
54
53
  a.attname AS name,
55
54
  pg_catalog.format_type(a.atttypid, a.atttypmod) AS type,
@@ -66,10 +65,14 @@ export class PostgreSQLDialect extends SQLDialect {
66
65
  AND a.attname NOT IN (${IGNORE_FIELDS.join(',')})
67
66
  ORDER BY
68
67
  a.attnum;
69
- `),
68
+ `);
70
69
 
71
- // 2. Foreign Keys
72
- this.executeSQL<{ name: string, from_column: string, to_column: string, to_table: string }>(`
70
+ if (!columns.count) {
71
+ return undefined;
72
+ }
73
+
74
+ // 2. Foreign Keys
75
+ const foreignKeys = await this.executeSQL<{ name: string, from_column: string, to_column: string, to_table: string }>(`
73
76
  SELECT
74
77
  tc.constraint_name AS name,
75
78
  kcu.column_name AS from_column,
@@ -82,10 +85,10 @@ export class PostgreSQLDialect extends SQLDialect {
82
85
  ON ccu.constraint_name = tc.constraint_name
83
86
  WHERE tc.constraint_type = 'FOREIGN KEY'
84
87
  AND tc.table_name = '${table}'
85
- `),
88
+ `);
86
89
 
87
- // 3. Indices
88
- this.executeSQL<{ name: string, is_unique: boolean, columns: string[] }>(`
90
+ // 3. Indices
91
+ const indices = await this.executeSQL<{ name: string, is_unique: boolean, columns: string[] }>(`
89
92
  SELECT
90
93
  i.relname AS name,
91
94
  ix.indisunique AS is_unique,
@@ -101,12 +104,7 @@ export class PostgreSQLDialect extends SQLDialect {
101
104
  AND NOT ix.indisprimary
102
105
  AND co.conindid IS NULL
103
106
  GROUP BY i.relname, ix.indisunique
104
- `)
105
- ]);
106
-
107
- if (!columns.count) {
108
- return undefined;
109
- }
107
+ `);
110
108
 
111
109
  return {
112
110
  columns: columns.records.map(col => ({