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'));
|
||||
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') {
|
||||
|
||||
sequelizeOptions = {
|
||||
|
@ -275,6 +287,32 @@ export class GBVMService extends GBService {
|
|||
idle: 10000,
|
||||
evict: 10000,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue