mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
43 lines
945 B
TypeScript
43 lines
945 B
TypeScript
|
import {
|
||
|
DatabaseType,
|
||
|
} from '../index';
|
||
|
import { getConfigValueSync } from '../../src/GenericHelpers';
|
||
|
|
||
|
/**
|
||
|
* Resolves the data type for the used database type
|
||
|
*
|
||
|
* @export
|
||
|
* @param {string} dataType
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
export function resolveDataType(dataType: string) {
|
||
|
const dbType = getConfigValueSync('database.type') as DatabaseType;
|
||
|
|
||
|
const typeMap: { [key in DatabaseType]: { [key: string]: string } } = {
|
||
|
sqlite: {
|
||
|
json: 'simple-json',
|
||
|
},
|
||
|
postgresdb: {
|
||
|
datetime: 'timestamp',
|
||
|
},
|
||
|
mysqldb: {},
|
||
|
mariadb: {},
|
||
|
};
|
||
|
|
||
|
return typeMap[dbType][dataType] ?? dataType;
|
||
|
}
|
||
|
|
||
|
export function getTimestampSyntax() {
|
||
|
const dbType = getConfigValueSync('database.type') as DatabaseType;
|
||
|
|
||
|
const map: { [key in DatabaseType]: string } = {
|
||
|
sqlite: "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')",
|
||
|
postgresdb: "CURRENT_TIMESTAMP(3)",
|
||
|
mysqldb: "CURRENT_TIMESTAMP(3)",
|
||
|
mariadb: "CURRENT_TIMESTAMP(3)",
|
||
|
};
|
||
|
|
||
|
return map[dbType];
|
||
|
}
|
||
|
|