@travetto/model-postgres 7.0.0-rc.0 → 7.0.0-rc.2

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.
package/README.md CHANGED
@@ -37,8 +37,8 @@ import { PostgreSQLDialect } from '@travetto/model-postgres';
37
37
 
38
38
  export class Init {
39
39
  @InjectableFactory({ primary: true })
40
- static getModelService(ctx: AsyncContext, conf: SQLModelConfig) {
41
- return new SQLModelService(ctx, conf, new PostgreSQLDialect(ctx, conf));
40
+ static getModelService(ctx: AsyncContext, config: SQLModelConfig) {
41
+ return new SQLModelService(ctx, config, new PostgreSQLDialect(ctx, config));
42
42
  }
43
43
  }
44
44
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-postgres",
3
- "version": "7.0.0-rc.0",
3
+ "version": "7.0.0-rc.2",
4
4
  "description": "PostgreSQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
5
5
  "keywords": [
6
6
  "sql",
@@ -27,12 +27,12 @@
27
27
  "directory": "module/model-postgres"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/cli": "^7.0.0-rc.0",
31
- "@travetto/config": "^7.0.0-rc.0",
32
- "@travetto/context": "^7.0.0-rc.0",
33
- "@travetto/model": "^7.0.0-rc.0",
34
- "@travetto/model-query": "^7.0.0-rc.0",
35
- "@travetto/model-sql": "^7.0.0-rc.0",
30
+ "@travetto/cli": "^7.0.0-rc.2",
31
+ "@travetto/config": "^7.0.0-rc.2",
32
+ "@travetto/context": "^7.0.0-rc.2",
33
+ "@travetto/model": "^7.0.0-rc.2",
34
+ "@travetto/model-query": "^7.0.0-rc.2",
35
+ "@travetto/model-sql": "^7.0.0-rc.2",
36
36
  "@types/pg": "^8.15.6",
37
37
  "pg": "^8.16.3"
38
38
  },
package/src/connection.ts CHANGED
@@ -40,9 +40,9 @@ export class PostgreSQLConnection extends Connection<PoolClient> {
40
40
 
41
41
  await this.runWithActive(() =>
42
42
  this.runWithTransaction('required', () =>
43
- this.execute(this.active!, 'CREATE EXTENSION IF NOT EXISTS pgcrypto;').catch(err => {
44
- if (!(err instanceof Error && err.message.includes('already exists'))) {
45
- throw err;
43
+ this.execute(this.active!, 'CREATE EXTENSION IF NOT EXISTS pgcrypto;').catch(error => {
44
+ if (!(error instanceof Error && error.message.includes('already exists'))) {
45
+ throw error;
46
46
  }
47
47
  })
48
48
  )
@@ -52,17 +52,17 @@ export class PostgreSQLConnection extends Connection<PoolClient> {
52
52
  ShutdownManager.onGracefulShutdown(() => this.#pool.end());
53
53
  }
54
54
 
55
- async execute<T = unknown>(conn: PoolClient, query: string, values?: unknown[]): Promise<{ count: number, records: T[] }> {
55
+ async execute<T = unknown>(pool: PoolClient, query: string, values?: unknown[]): Promise<{ count: number, records: T[] }> {
56
56
  console.debug('Executing query', { query });
57
57
  try {
58
- const out = await conn.query(query, values);
59
- const records: T[] = [...out.rows].map(v => ({ ...v }));
58
+ const out = await pool.query(query, values);
59
+ const records: T[] = [...out.rows].map(value => ({ ...value }));
60
60
  return { count: out.rowCount!, records };
61
- } catch (err) {
62
- if (err instanceof Error && err.message.includes('duplicate key value')) {
61
+ } catch (error) {
62
+ if (error instanceof Error && error.message.includes('duplicate key value')) {
63
63
  throw new ExistsError('query', query);
64
64
  } else {
65
- throw err;
65
+ throw error;
66
66
  }
67
67
  }
68
68
  }
@@ -71,7 +71,7 @@ export class PostgreSQLConnection extends Connection<PoolClient> {
71
71
  return this.#pool.connect();
72
72
  }
73
73
 
74
- release(conn: PoolClient): void {
75
- conn.release();
74
+ release(pool: PoolClient): void {
75
+ pool.release();
76
76
  }
77
77
  }
package/src/dialect.ts CHANGED
@@ -14,11 +14,11 @@ import { PostgreSQLConnection } from './connection.ts';
14
14
  @Injectable()
15
15
  export class PostgreSQLDialect extends SQLDialect {
16
16
 
17
- conn: PostgreSQLConnection;
17
+ connection: PostgreSQLConnection;
18
18
 
19
19
  constructor(context: AsyncContext, config: SQLModelConfig) {
20
20
  super(config.namespace);
21
- this.conn = new PostgreSQLConnection(context, config);
21
+ this.connection = new PostgreSQLConnection(context, config);
22
22
  this.ID_AFFIX = '"';
23
23
 
24
24
  // Special operators
@@ -50,8 +50,8 @@ export class PostgreSQLDialect extends SQLDialect {
50
50
  getModifyColumnSQL(stack: VisitStack[]): string {
51
51
  const field: SchemaFieldConfig = castTo(stack.at(-1));
52
52
  const type = this.getColumnType(field);
53
- const ident = this.ident(field.name.toString());
54
- return `ALTER TABLE ${this.parentTable(stack)} ALTER COLUMN ${ident} TYPE ${type} USING (${ident}::${type});`;
53
+ const identifier = this.identifier(field.name);
54
+ return `ALTER TABLE ${this.parentTable(stack)} ALTER COLUMN ${identifier} TYPE ${type} USING (${identifier}::${type});`;
55
55
  }
56
56
 
57
57
  /**