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

Receive problem when trying to reproduce tutorial example on my project entities #370

Open
goodstemy opened this issue Dec 11, 2023 · 3 comments

Comments

@goodstemy
Copy link

Describe the bug

I'm using nest.js + typeorm. Based on this example I tried to create test with pg-mem.

 FAIL  src/controllers/order/order.service.spec.ts
  Order module
    ✕ Should work (1 ms)

  ● Order module › Should work

    QueryFailedError: Invalid timestamp format: now

    🐜 This seems to be an execution error, which means that your request syntax seems okay,
        but the resulting statement cannot be executed → Probably not a pg-mem error.

    *️⃣ Failed SQL statement: CREATE TABLE "session" ("id" BIGSERIAL NOT NULL, "version" integer NOT NULL, "type" "public"."session_type_enum" NOT NULL, "userId" integer, "isRevoked" boolean NOT NULL DEFAULT false, "revokeReason" character varying, "createdAt" TIMESTAMP NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, "updatedAt" TIMESTAMP NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, CONSTRAINT "PK_f55da76ac1c3ac420f444d2ff11" PRIMARY KEY ("id"));

This query works fine if it running on real pg db.

To Reproduce

Looks like error reason in the entity field:

  @Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
  })
  createdAt: Date;

pg-mem version

"version": "2.7.2",

@goodstemy
Copy link
Author

goodstemy commented Dec 11, 2023

Also find out rn if I change:

@Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
  })
  createdAt: Date;

to

@Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'NOW()',
  })
  createdAt: Date;

it works fine. But for me really matters to make timestamp with precision using current_timestamp function.

@goodstemy
Copy link
Author

goodstemy commented Dec 11, 2023

And also got warning (doesn't seen this first time):

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
    Arguments:
    [0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: now, _f: undefined, _strict: undefined, _locale: [object Object]
    Error:
        at Function.createFromInputFallback (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:324:25)
        at configFromString (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2550:19)
        at configFromInput (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2993:13)
        at prepareConfig (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2976:13)
        at createFromConfig (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2943:44)
        at createLocalOrUTC (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:3037:16)
        at Function.createUTC [as utc] (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:106:16)
        at value.setConversion.toTs.toTs (/Users/ivan/coding/boqpod/laox/core/node_modules/pg-mem/src/datatypes/t-timestamp.ts:97:53)
        at Evaluator.val (/Users/ivan/coding/boqpod/laox/core/node_modules/pg-mem/src/evaluator.ts:128:28)

How can I solve it?

@eliasjtg
Copy link

eliasjtg commented Mar 1, 2024

Any fix or workaround?

I have the same issue

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