Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: date.getUTCFullYear is not a function for CreateDateColumn, UpdateDateColumn and DeleteDateColumn #152

Open
antesberger opened this issue Aug 11, 2022 · 1 comment

Comments

@antesberger
Copy link

Package versions and database engine type (please complete the following information):

  • Database Engine: postgres
  • TypeORM Version: 0.3.7
  • Driver Version: 2.4.2

Describe the bug
When creating an Entity using CreateDateColumn, UpdateDateColumn or DeleteDateColumn a TypeError: date.getUTCFullYear is not a function

To Reproduce
Create an Entity like this

@Entity()
export class Entity {
  @PrimaryColumn()
  id: string;

  @CreateDateColumn()
  created_at: Date;

  @UpdateDateColumn()
  updated_at: Date;

  @DeleteDateColumn()
  updated_at: Date;
}

and try to save an entry dataSource.getRepository(Entity).save(entity);

Possible Solution
Saving throws the following error TypeError: date.getUTCFullYear is not a function in typeorm-aurora-data-api-driver/dist/typeorm-aurora-data-api-driver.umd.js:962:25 which is called in ypeorm-aurora-data-api-driver/dist/typeorm-aurora-data-api-driver.umd.js:1235:32.

It seems like you're calling dateToDateTimeString on a string when expecting a date:

case 'timestamp':
case 'datetime':
case 'timestamp with time zone':
case 'timestamptz':
  return {
    value: dateToDateTimeString(value),
    cast: 'TIMESTAMP',
  };

changing this segment to

case 'timestamp':
case 'datetime':
case 'timestamp with time zone':
case 'timestamptz':
  return {
    value: dateToDateTimeString(new Date(value)),
    cast: 'TIMESTAMP',
  };

resolves the issue for me.

I can't tell if this has any unexpected consequences for other functionalities but as of now this seems to be working just fine. I'll fork for now but am happy to create a PR in case you approve this solution. Also I'm very open if someone can suggest a better approach.

@tugzera
Copy link

tugzera commented Feb 11, 2023

For me passing this formatOptions on the configurations solved the problem:

new DataSource({
      database,
      type: 'aurora-postgres',
      region: 'us-east-1',
      resourceArn,
      secretArn,
      formatOptions: {
        enableUuidHack: true,
        castParameters: false,
      }    
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants