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

[bug] JSONB seeding not working #153

Open
humbertowoody opened this issue Mar 4, 2019 · 1 comment
Open

[bug] JSONB seeding not working #153

humbertowoody opened this issue Mar 4, 2019 · 1 comment

Comments

@humbertowoody
Copy link

Hi! I created the following model:

@Entity()
export class Resource {
    @PrimaryColumn('uuid')
    public id: string;

    @IsNotEmpty()
    @Column()
    public source: string;

    @IsNotEmpty()
    @Column({ type: 'jsonb', nullable: true })
    public data: any;

    @UpdateDateColumn({ name: 'updated_at' })
    public updatedAt: Date;

    @CreateDateColumn({ name: 'created_at' })
    public createdAt: Date;
}

And this is my Factory:

define(Resource, (faker: typeof Faker) => {
    const source = faker.company.companyName();

    const resource = new Resource();
    resource.id = uuid.v1();
    resource.source = source;
    resource.data = { foo: 'bar' }; // <<<<<<<<< 
    return resource;
});

The issue, is that I am unable to seed the data field with a JSON or an Array. Only strings seem to work. Every other kind of object throws:

Could not run seed  Error: Could not save entity
    at EntityFactory.<anonymous> (/node_modules/typeorm-seeding/dist/typeorm-seeding.js:103:27)
    at Generator.throw (<anonymous>)
    at rejected (/node_modules/typeorm-seeding/dist/typeorm-seeding.js:30:65)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

This is probably an error due to the data type JSON and/or JSONB (available in PostgreSQL). Maybe a bug? Thanks in advance!

@HackAfro
Copy link

@humbertowoody have you tried setting the data type to simple-json? that seems to work for me

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