From 4be13899f5531d87bcd747c86fb52b5b54bc3cbc Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 16 Jan 2025 02:11:12 -0300 Subject: [PATCH] new(kb.gblib): added postgres. --- package.json | 1 + packages/basic.gblib/services/GBVMService.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ed6d8227..ffba09f8 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "@semantic-release/git": "10.0.1", "@sendgrid/mail": "8.1.3", "@sequelize/core": "7.0.0-alpha.37", + "@sequelize/postgres": "^7.0.0-alpha.43", "@types/node": "22.5.2", "@types/validator": "13.12.1", "adm-zip": "0.5.16", diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index c0d2f2ef..0b405213 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -39,6 +39,7 @@ import { CollectionUtil } from 'pragmatismo-io-framework'; import { ScheduleServices } from './ScheduleServices.js'; import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js'; import urlJoin from 'url-join'; +import { PostgresDialect } from '@sequelize/postgres'; import { NodeVM, VMScript } from 'vm2'; import { createVm2Pool } from './vm2-process/index.js'; import { watch } from 'fs'; @@ -240,7 +241,7 @@ export class GBVMService extends GBService { const storageName = con['storageName']; const username = con['storageUsername']; const password = con['storagePassword']; - + const logging: boolean | Function = GBConfigService.get('STORAGE_LOGGING') === 'true' ? (str: string): void => { @@ -250,7 +251,7 @@ export class GBVMService extends GBService { const encrypt: boolean = GBConfigService.get('STORAGE_ENCRYPT') === 'true'; const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT')); - const sequelizeOptions = { + let sequelizeOptions = { define: { charset: 'utf8', collate: 'utf8_general_ci', @@ -277,9 +278,15 @@ export class GBVMService extends GBService { acquire: acquire } }; - + + if (dialect === 'postgres') { + sequelizeOptions['ssl'] = true; + sequelizeOptions['clientMinMessages'] = 'notice'; + sequelizeOptions['dialect']= PostgresDialect; + } + if (!min[connectionName]) { - GBLogEx.info(min, `Loading data connection ${connectionName}...`); + GBLogEx.info(min, `Loading data connection ${connectionName} (${dialect})...`); min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions); min[connectionName]['gbconnection'] = con; }