import { ICredentialNodeAccess } from 'n8n-workflow' ; import { BeforeUpdate , Column , CreateDateColumn , Entity , Index , PrimaryGeneratedColumn , UpdateDateColumn , } from 'typeorm' ; import config = require ( '../../../config' ) ; import { DatabaseType , ICredentialsDb } from '../..' ; function resolveDataType ( dataType ) { const dbType = config . get ( 'database.type' ) as DatabaseType ; const typeMap = { sqlite : { json : 'simple-json' , } , postgresdb : { datetime : 'timestamptz' , } , mysqldb : { } , mariadb : { } , } ; return typeMap [ dbType ] [ dataType ] ?? dataType ; } function getTimestampSyntax ( ) { const dbType = config . get ( 'database.type' ) as DatabaseType ; const map = { sqlite : "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')" , postgresdb : 'CURRENT_TIMESTAMP(3)' , mysqldb : 'CURRENT_TIMESTAMP(3)' , mariadb : 'CURRENT_TIMESTAMP(3)' , } ; return map [ dbType ] ; } @ Entity ( ) export class CredentialsEntity implements ICredentialsDb { @ PrimaryGeneratedColumn ( ) id : number ; @ Column ( { length : 128 , } ) name : string ; @ Column ( 'text' ) data : string ; @ Index ( ) @ Column ( { length : 32 , } ) type : string ; @ Column ( resolveDataType ( 'json' ) ) nodesAccess : ICredentialNodeAccess [ ] ; @ CreateDateColumn ( { precision : 3 , default : ( ) => getTimestampSyntax ( ) } ) createdAt : Date ; @ UpdateDateColumn ( { precision : 3 , default : ( ) => getTimestampSyntax ( ) , onUpdate : getTimestampSyntax ( ) , } ) updatedAt : Date ; @ BeforeUpdate ( ) setUpdateDate ( ) { this . updatedAt = new Date ( ) ; } }