new(kb.gblib): added postgres.
This commit is contained in:
parent
b751dbb418
commit
c97a6ec0bf
1 changed files with 84 additions and 46 deletions
|
@ -253,6 +253,18 @@ export class GBVMService extends GBService {
|
||||||
const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT'));
|
const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT'));
|
||||||
let sequelizeOptions;
|
let sequelizeOptions;
|
||||||
|
|
||||||
|
|
||||||
|
// Simple function to convert all object keys to lowercase
|
||||||
|
const toLowerCase = (obj) => {
|
||||||
|
if (!obj) return obj;
|
||||||
|
if (typeof obj !== 'object') return obj;
|
||||||
|
|
||||||
|
return Object.keys(obj).reduce((acc, key) => {
|
||||||
|
acc[key.toLowerCase()] = obj[key];
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
if (dialect === 'postgres') {
|
if (dialect === 'postgres') {
|
||||||
|
|
||||||
sequelizeOptions = {
|
sequelizeOptions = {
|
||||||
|
@ -263,8 +275,8 @@ export class GBVMService extends GBService {
|
||||||
dialectOptions: {
|
dialectOptions: {
|
||||||
ssl: false,
|
ssl: false,
|
||||||
application_name: 'General Bots',
|
application_name: 'General Bots',
|
||||||
connectTimeout:10000,
|
connectTimeout: 10000,
|
||||||
query_timeout:10000,
|
query_timeout: 10000,
|
||||||
statement_timeout: 10000,
|
statement_timeout: 10000,
|
||||||
idle_in_transaction_session_timeout: 10000,
|
idle_in_transaction_session_timeout: 10000,
|
||||||
|
|
||||||
|
@ -275,12 +287,38 @@ export class GBVMService extends GBService {
|
||||||
idle: 10000,
|
idle: 10000,
|
||||||
evict: 10000,
|
evict: 10000,
|
||||||
acquire: acquire
|
acquire: acquire
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
// Convert all table names to lowercase
|
||||||
|
freezeTableName: true,
|
||||||
|
hooks: {
|
||||||
|
beforeDefine: (attributes, options) => {
|
||||||
|
// Convert model and column names to lowercase
|
||||||
|
options.tableName = options.tableName?.toLowerCase();
|
||||||
|
for (const attr in attributes) {
|
||||||
|
const lowered = attr.toLowerCase();
|
||||||
|
if (attr !== lowered) {
|
||||||
|
attributes[lowered] = attributes[attr];
|
||||||
|
delete attributes[attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Convert query attributes to lowercase
|
||||||
|
hooks: {
|
||||||
|
beforeFind: (options) => {
|
||||||
|
if (options.where) {
|
||||||
|
options.where = toLowerCase(options.where);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
|
|
||||||
sequelizeOptions = {
|
sequelizeOptions = {
|
||||||
define: {
|
define: {
|
||||||
|
@ -451,7 +489,7 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
// Do not erase tables in case of an error in collection retrieval.
|
// Do not erase tables in case of an error in collection retrieval.
|
||||||
|
|
||||||
if (tables.length === 0){
|
if (tables.length === 0) {
|
||||||
sync = false;
|
sync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,8 +583,8 @@ export class GBVMService extends GBService {
|
||||||
const jsfile: string = `${filename}.js`;
|
const jsfile: string = `${filename}.js`;
|
||||||
|
|
||||||
const template = (await fs.readFile('./vm-inject.js')).toString();
|
const template = (await fs.readFile('./vm-inject.js')).toString();
|
||||||
code = template.replace('//##INJECTED_CODE_HERE', code );
|
code = template.replace('//##INJECTED_CODE_HERE', code);
|
||||||
code = code.replace('//##INJECTED_HEADER', `port=${GBVMService.API_PORT}; botId='${min.botId}';` );
|
code = code.replace('//##INJECTED_HEADER', `port=${GBVMService.API_PORT}; botId='${min.botId}';`);
|
||||||
|
|
||||||
code = ji.default(code, ' ');
|
code = ji.default(code, ' ');
|
||||||
|
|
||||||
|
@ -974,7 +1012,7 @@ export class GBVMService extends GBService {
|
||||||
return await new Promise((resolve) => {
|
return await new Promise((resolve) => {
|
||||||
sandbox['resolve'] = resolve;
|
sandbox['resolve'] = resolve;
|
||||||
// TODO: #411 sandbox['reject'] = reject;
|
// TODO: #411 sandbox['reject'] = reject;
|
||||||
sandbox['reject'] = () => {};
|
sandbox['reject'] = () => { };
|
||||||
|
|
||||||
const vm1 = new NodeVM({
|
const vm1 = new NodeVM({
|
||||||
allowAsync: true,
|
allowAsync: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue