@onivoro/server-typeorm-postgres 0.1.27 → 0.1.29

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.
@@ -5,7 +5,8 @@ class SqlWriter {
5
5
  static addColumn(table, option) {
6
6
  const notNullExpression = option.isPrimary ? ` PRIMARY KEY ` : (option.isNullable ? '' : ' NOT NULL ');
7
7
  const foreignKey = option.foreignKeyConstraintName ? ` REFERENCES ${option.foreignKeyConstraintName} ` : '';
8
- return `ALTER TABLE "${table}" ADD "${option.name}" ${option.type}${notNullExpression}${SqlWriter.getDefaultValueExpression(option)}${foreignKey}`;
8
+ const uniqueExpression = option.isUnique ? ' UNIQUE ' : '';
9
+ return `ALTER TABLE "${table}" ADD "${option.name}" ${option.type}${notNullExpression}${uniqueExpression}${SqlWriter.getDefaultValueExpression(option)}${foreignKey}`;
9
10
  }
10
11
  static createTable(table, options) {
11
12
  const cols = options.map(option => SqlWriter.addColumn(table, option).replace(`ALTER TABLE "${table}" ADD `, '')).join(',\n');
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dataSourceConfigFactory = void 0;
4
4
  const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
5
5
  function dataSourceConfigFactory(name, options, entities) {
6
- const { database, host, password, port, username, synchronize = false, logging = false } = options;
6
+ const { ca, database, host, password, port, username, synchronize = false, logging = false } = options;
7
7
  const config = {
8
8
  name,
9
- autoLoadEntities: true,
10
9
  type: 'postgres',
11
10
  host,
12
- port,
11
+ port: port,
13
12
  username,
14
13
  password,
14
+ ssl: ca ? { ca } : undefined,
15
15
  database,
16
16
  synchronize,
17
17
  logging,
@@ -1,9 +1,3 @@
1
1
  import { DataSource } from 'typeorm';
2
- export declare const dataSourceFactory: (name: string, options: {
3
- database: string;
4
- host: string;
5
- port: string;
6
- username: string;
7
- password: string;
8
- synchronize?: boolean;
9
- }, entities: any[]) => DataSource;
2
+ import { IDataSourceOptions } from '../types/data-source-options.interface';
3
+ export declare const dataSourceFactory: (name: string, options: IDataSourceOptions, entities: any[]) => DataSource;
@@ -6,4 +6,5 @@ export interface IDataSourceOptions {
6
6
  password: string;
7
7
  synchronize?: boolean;
8
8
  logging?: boolean;
9
+ ca?: string;
9
10
  }
@@ -5,7 +5,8 @@ class SqlWriter {
5
5
  static addColumn(table, option) {
6
6
  const notNullExpression = option.isPrimary ? ` PRIMARY KEY ` : (option.isNullable ? '' : ' NOT NULL ');
7
7
  const foreignKey = option.foreignKeyConstraintName ? ` REFERENCES ${option.foreignKeyConstraintName} ` : '';
8
- return `ALTER TABLE "${table}" ADD "${option.name}" ${option.type}${notNullExpression}${SqlWriter.getDefaultValueExpression(option)}${foreignKey}`;
8
+ const uniqueExpression = option.isUnique ? ' UNIQUE ' : '';
9
+ return `ALTER TABLE "${table}" ADD "${option.name}" ${option.type}${notNullExpression}${uniqueExpression}${SqlWriter.getDefaultValueExpression(option)}${foreignKey}`;
9
10
  }
10
11
  static createTable(table, options) {
11
12
  const cols = options.map(option => SqlWriter.addColumn(table, option).replace(`ALTER TABLE "${table}" ADD `, '')).join(',\n');
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dataSourceConfigFactory = void 0;
4
4
  const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
5
5
  function dataSourceConfigFactory(name, options, entities) {
6
- const { database, host, password, port, username, synchronize = false, logging = false } = options;
6
+ const { ca, database, host, password, port, username, synchronize = false, logging = false } = options;
7
7
  const config = {
8
8
  name,
9
- autoLoadEntities: true,
10
9
  type: 'postgres',
11
10
  host,
12
- port,
11
+ port: port,
13
12
  username,
14
13
  password,
14
+ ssl: ca ? { ca } : undefined,
15
15
  database,
16
16
  synchronize,
17
17
  logging,
@@ -1,9 +1,3 @@
1
1
  import { DataSource } from 'typeorm';
2
- export declare const dataSourceFactory: (name: string, options: {
3
- database: string;
4
- host: string;
5
- port: string;
6
- username: string;
7
- password: string;
8
- synchronize?: boolean;
9
- }, entities: any[]) => DataSource;
2
+ import { IDataSourceOptions } from '../types/data-source-options.interface';
3
+ export declare const dataSourceFactory: (name: string, options: IDataSourceOptions, entities: any[]) => DataSource;
@@ -6,4 +6,5 @@ export interface IDataSourceOptions {
6
6
  password: string;
7
7
  synchronize?: boolean;
8
8
  logging?: boolean;
9
+ ca?: string;
9
10
  }
@@ -1,9 +1,3 @@
1
1
  import { DataSource } from 'typeorm';
2
- export declare const dataSourceFactory: (name: string, options: {
3
- database: string;
4
- host: string;
5
- port: string;
6
- username: string;
7
- password: string;
8
- synchronize?: boolean;
9
- }, entities: any[]) => DataSource;
2
+ import { IDataSourceOptions } from '../types/data-source-options.interface';
3
+ export declare const dataSourceFactory: (name: string, options: IDataSourceOptions, entities: any[]) => DataSource;
@@ -6,4 +6,5 @@ export interface IDataSourceOptions {
6
6
  password: string;
7
7
  synchronize?: boolean;
8
8
  logging?: boolean;
9
+ ca?: string;
9
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-postgres",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-postgres.git"
6
6
  },