Closed jaassoon closed 1 year ago
Hi !
The problem comes from this:
db.public.none(`insert into test.foo values('2c8ae58d-7d5a-47f4-b8c2-ee61154a46bd',null,2);`);
db.public.none(`insert into test.foo values('3c7c772e-bb92-414e-8c83-44f50fbf43ec',null,3);`);
Which inserts in the "public" schema.
Use db.getSchema('test').none(...)
instead :)
@oguimbal
Thank you for your reply.
I try to use db.getSchema('test').none(...)
, but it still not work.
Where am I going wrong?
Ok right, I found the issue, i'm reoping this. Will fix
Should be fixed in pg-mem@2.6.7
@oguimbal I am sorry again. It still not works, there is something changed though. Actually, it returns 2 records, but they are not I expected. At the moment, it returns:
[
{id:null,sub_id:null,bar:null},
{id:null,sub_id:null,bar:null}
]
I think the first row should be:
{id:'uuid_xxx',sub_id:null,bar:2},
If I use pgmem to create table, it works. Something like that:
db.getSchema('test').many(`
CREATE TABLE "test"."foo" ("id" uuid NOT NULL, "sub_id" uuid, "bar" integer NOT NULL);
insert into test.foo values('2c8ae58d-7d5a-47f4-b8c2-ee61154a46bd',null,2);
insert into test.foo values('3c7c772e-bb92-414e-8c83-44f50fbf43ec',null,3);`);
But it still not work if I use the DDL generated by typeorm
db.getSchema('test').many(`
CREATE TABLE "test"."foo" ("id" uuid NOT NULL, "sub_id" uuid, "bar" integer NOT NULL, CONSTRAINT "PK_....." PRIMARY KEY ("id"));
insert into test.foo values('2c8ae58d-7d5a-47f4-b8c2-ee61154a46bd',null,2);
insert into test.foo values('3c7c772e-bb92-414e-8c83-44f50fbf43ec',null,3);`);
I thing
, CONSTRAINT "PK_....." PRIMARY KEY ("id")
is the point.
If I create table by typeorm, it not works. I guess the auto generated DDL is difference with the one above. By typeorm:
@Entity({ name: 'foo' })
export class FooEntity {
@PrimaryColumn({ name: 'id', type: 'uuid' })
id: string;
@Column({ name: 'sub_id', type: 'uuid', nullable:true })
subId: string;
@Column({ name: 'bar', type: 'integer' })
bar: number;
}
...
dataSource = await db.adapters.createTypeormDataSource({
...
entities: [FooEntity],
});
Below is the table structure auto generate by typeorm in postgresql:
\d foo
table : test.foo
column type nullable
id uuid not null
sub_id uuid
bar integer not null
indexes:
"PK_......" primary key, btree(id)
But I dont know how to describe table in pgmem...
anyway, I can confirm the DDL from the logs.
CREATE TABLE "test"."foo" ("id" uuid NOT NULL, "sub_id" uuid, "bar" integer NOT NULL , constraint "PK_..." PRIMARY KEY ("id) );
One more thing. It works following the steps as below:
Indeed. I fucked-up my unit test. Fixing it...
is it fixed with pg-mem@2.6.8
?
(should be this time...)
@oguimbal Oh, it works like a charm! Thank you very much for your rapid fixing!
Describe the bug
Hi, guys! I defined table as below . I found that it works well in https://oguimbal.github.io/pg-mem-playground/. But it always return empty array when I query in jest test case.
To Reproduce
test case
pg-mem version
2.6.6