Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Marek
    @murbanowicz
    Hi all!
    I found something and I am wondering if it is 'normal'.
    I was checking memory consumption in prod mode and after dockerizing I found about 120mb of RAM consumed by NestJS app.
    However, after I commented out the TypeORM module, I got it back to 30mb.
    Does anyone have similar memory consumption with TypeORM and Nest? It's crazy in my opinion but maybe it's TypeORM thing...
    It connects to Postgres so it is not like inMemory storage or something
    Joaquim Teixeira Duarte
    @S7R1D3R
    Hey all! I don't know why but in my project it's saying it doesn't find an "ApplicationEntity" because it's not registered in the current "default" connection, but the entity is in the correct folder. I have this as the entities: [ "./src//entities/*.entity.ts" , "./src//entities/*.entity.js" ], can anyone help me?
    please
    sheshtiwari
    @sheshtiwari
    Can anyone tell me, how can i build query createQueryBuilder. I have 3 entities - category, product, category_product

    @Entity("categories_products")
    export class CategoryProduct extends BaseEntity {
    @PrimaryColumn()
    categoryId: number;

    @PrimaryColumn()
    productId: number;

    @ManyToOne(() => CategoryEntity, category => category.productConnection, {
    onDelete: "CASCADE"
    })
    @JoinColumn({ name: "categoryId" })
    category: Promise<CategoryEntity>;

    @ManyToOne(() => Product, product => product.categoryConnection, {
    onDelete: "CASCADE"
    })
    @JoinColumn({ name: "productId" })
    product: Promise<Product>;
    }

    product -

    @ObjectType()
    @Entity("categories")
    export class CategoryEntity extends BaseEntity {
    @Field(() => ID)
    @PrimaryGeneratedColumn()
    id: number;

    @Field()
    @Column({ unique: true })
    title: string;

    @Field()
    @Column({ unique: true })
    url: string;

    @Field({ nullable: true })
    @Column({ nullable: true })
    description?: string;

    @Field({ nullable: true })
    @Column({ nullable: true })
    seoTitle?: string;

    @Field({ nullable: true })
    @Column({ nullable: true })
    seoDescription?: string;

    @Field(() => [String])
    @Column({ type: "jsonb", default: [] })
    seoKeywords: string[];

    @OneToMany(() => CategoryProduct, cp => cp.category)
    productConnection: Promise<CategoryProduct[]>;

    @Field()
    @CreateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
    createdAt: string;

    @Field()
    @UpdateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
    updatedAt: string;
    }

    category -

    @ObjectType()
    @Entity("products")
    export class Product extends BaseEntity {
    @Field(() => ID)
    @PrimaryGeneratedColumn()
    id: number;

    @Field()
    @Column({ unique: true })
    title: string;

    @Field()
    @Column({ unique: true })
    url: string;

    @Field()
    @Column()
    price: string;

    @Field(() => Image, { nullable: true })
    @Column({ type: "jsonb", nullable: true })
    logo?: object;

    @Field(() => [Image], { nullable: true })
    @Column({ type: "jsonb", nullable: true })
    gallery?: object[];

    @Field(() => [ProductVariant])
    @Column({ type: "jsonb", default: [] })
    variants: object[];

    @Field({ nullable: true })
    @Column({ nullable: true })
    description?: string;

    @Field({ nullable: true })
    @Column({ nullable: true })
    seoTitle?: string;

    @Field({ nullable: true })
    @Column({ nullable: true })
    seoDescription?: string;

    @Field(() => [String])
    @Column({ type: "jsonb", default: [] })
    seoKeywords: string[];

    @OneToMany(() => CategoryProduct, cp => cp.product)
    categoryConnection: Promise<CategoryProduct[]>;

    @Field(() => [CategoryEntity])
    async categories(): Promise<CategoryEntity[]> {
    const categoriesIds = (await CategoryProduct.find({
    productId: this.id
    })).map(cp => cp.categoryId);

    if (isEmpty(categoriesIds)) {
      return [];
    }
    
    return CategoryEntity.find({ id: In(categoriesIds) });

    }

    @Field()
    @CreateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
    createdAt: string;

    @Field()
    @UpdateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
    updatedAt: string;
    }

    Error - 'Relations "product.categoryConnection", "category_proroduct" were not found, please check if relations are correct and they exist in your entities.'
    how can i fix this error while there exist relationship
    VPak
    @VillePakarinen
    Any workarounds for this? typeorm/typeorm#926
    Bnaya Peretz
    @Bnaya
    Is it possible to get raw query from QueryBuilder?
    Another question: is it possible to get a stream our of connection.query?
    Fabian Wiles
    @Toxicable
    Anyone know if there's some typed way of using relations?
    right now it's jsut some random string array
    Antoine Guittet
    @GuittetAntoine_twitter
    Hi guys, I there a way when doing a request with queryBuilder with relation to order the relation results ?
    Adrian Hara
    @adrianhara
    when compiling my (library) code the d.ts files don't contain default values for functions anymore, i.e. foo(a: string, b: number = 1) results in the d.ts in foo(a:string, b:number)... is that normal?
    Bnaya Peretz
    @Bnaya
    What is the correct column definition for auto filled created_at & updated_at fields for mysql?
    that are filled by the mysql server
    Logan Valentine
    @krandom
    const connection = await db()
    await connection
    .getRepository(Visit)
    .createQueryBuilder('vis')
    .select('vis.visitId')
    .addSelect('ord.orderId')
    .innerJoin(Orders, 'ord', 'vis.visitId = ord.visitId')
    .where('vis.locationId = :id', { id })
    .getMany()
    .then(res => (success = res))
    .catch(({ code, message }) => (error = { code, message }))
    why would orderId not show up in the results?
    Alexander Latour
    @alexeightsix
    I'm looking for a ORM Library for my project, I'm considering TypeORM but I have a few questions: Is it possible to use factories? Generate seeds?
    Bnaya Peretz
    @Bnaya
    Why dose is JoinTable (owner side declaration) is required for ManyToMany?
    Bnaya Peretz
    @Bnaya
    Is it possible to configure a junction table?
    I have an exiting schema and i'm trying to teach TypeORM to use it
    My exiting junction table look likes so:
    Columns:
    bt_brand_to_category_id
    int(11) UN AI PK
    bt_brand_id
    varchar(20)
    bt_category_id
    int(11) UN
    My current direction is to just declare "one to many" from categories to this table, and from brands to this table,
    But when i want to use features like RelationId i get the value of bt_brand_to_category_id
    Agusti Fernandez
    @agustif
    @alexeightsix Hey Alexander, yes that's indeed possible. You can see a good example on https://github.com/w3tecch/express-typescript-boilerplate/ of both, using faker under the hood for factories
    This repo boilerplate was what made me stick with TS/TypeORM. Hope it helps . They ended up creating a npm package for typeorm seeding: https://github.com/w3tecch/typeorm-seeding
    CoonHouse
    @CoonHouse
    Hello, how do I use the .collation() cursor on repository.createEntityCursor() on MongoDB?
    Saulo S. Toledo
    @saulotoledo
    Hello all. I am having issue with a sample project here. Can somebody help me to find the issuew
    /* tslint:disable:completed-docs no-any */
    import { MigrationInterface, QueryRunner } from 'typeorm';
    
    import { User } from '../../modules/core/entities/user.model';
    
    export class AddSampleUsers1557597276952 implements MigrationInterface {
    
      public async up(queryRunner: QueryRunner): Promise<any> {
        await queryRunner
          .manager
          .createQueryBuilder()
          .insert()
          .into(User)
          .values([
            { name: 'John Doe', email: 'john@doe.com', username: 'john.doe', password: '12345' },
            { name: 'Agata Doe', email: 'agata@doe.com', username: 'agata.doe', password: '12345' },
          ])
          .execute();
      }
    
      public async down(queryRunner: QueryRunner): Promise<any> {
        await queryRunner
          .manager
          .createQueryBuilder()
          .delete()
          .from(User)
          .where('email = :email', { email: 'john@doe.com' })
          .orWhere('email = :email', { email: 'agata@doe.com' })
          .execute();
      }
    
    }
    The error when I run the migration:
    Error during migration run:
    TypeError: this.subQuery is not a function
    node_modules/typeorm/query-builder/QueryBuilder.js:361:57
    Shijie Zhou
    @shijiezhou1
    using sql query instead of this query runner.
    Dominic Watson
    @intellix
    is it known that doing qb.addOrderBy('updatedAt', 'ASC') doesn't quote the column when the table name isn't prefixed like Asset.updatedAt in Postgres? Didn't see an issue for it. It causes an error like: No column updatedat because of it being unquoted
    Toni
    @SpeedoPasanen
    Using Webpack (nrwl/nx + angular cli) How to fix a circular dependency between entities which relate to each other?
    eg. page.entity.ts:
    @OneToMany(type => Pic, item => item.page)
    pic.entity.ts:
    @ManyToOne(type => Page, item => item.pics, { onDelete: 'CASCADE' })
    obviously these entities have to import each other to make that happen the usual way. Webpack says no-no. Any ideas?
    Toni
    @SpeedoPasanen
    meh hmn i guess i need to add interfaces, which entities implement
    Toni
    @SpeedoPasanen
    nope the related type needs to be an entity. What to do?
    Toni
    @SpeedoPasanen
    ok just use an interface on the ManyToOne end, lose the decorator there
    will lose the benefit of any cascaded saves but who uses them anyway... :)
    Agusti Fernandez
    @agustif
    Toni, check out this, you can use typeorm with graphql+modules 👌🏻 https://link.medium.com/oxU6b8Is8W
    Toni
    @SpeedoPasanen
    @agustif Really, moving to graphql is the only way? :) I like REST too much, will have to figure out a way to use an injector or something to get the entity classes for the decorators :)
    Toni
    @SpeedoPasanen
    ok only using @ManyToOne() is enough to create foreign keys etc. I thought you need to do @OneToMany() in the related entity as well. Guess I can live without it
    miran
    @drekembe
    hi, love typeorm! one question, is there still no way when adding a relation (either via createQueryBuilder().innerJoinAndSelect or find({ relations: [ ... ] })) to specify which fields you want returned on the relation?
    say i have a user, and i want to get that user, their posts, but the posts should contain only the titles
    ssdk86
    @ssdk86

    @ssdk86
    Hello, guys.
    in php doctrine ORM we have opportunity to set order by default in model instance like this
    @ORM\OrderBy({"date" = "DESC"})
    for example so we set order to addresses items as order : [[ 'date', 'DESC' ]]

        /**
        * @var \KR\Model\PeopleAddresses[]
        *
        * @ORM\OneToMany(targetEntity="\PeopleAddresses", mappedBy="people")
        * @ORM\OrderBy({"date" = "DESC"})
        * @ORM\JoinColumn(name="id", referencedColumnName="people_id")
        */
    protected $addresses;

    and is there a way to do that in typeorm?

        @Field(type => OrdersModel, { nullable : true })
    ***@OrderBy('date', 'DESC')***
        @HasMany(() => OrdersModel)
        ordersItem: OrdersModel;

    i try like this, but it is not work

        @Field(type => OrdersModel, { 
            nullable : true,
            defaultValue: [{
                key: "date",
                order: "ASC"
            }]
        })
        @HasMany(() => OrdersModel)
        ordersItem: OrdersModel;
    jmls
    @jmls
    hi all, is it possible to specify a field list for a relation in a find ?