Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Meir Shamay
    @may215

    Hi, I am trying to mock SelectQueryBuilder, but I am getting error: TypeError: Cannot read property 'select' of undefined
    this is the code I am trying to run:

    import * as typeorm from 'typeorm'
    import { Connection, EntityManager, getConnection } from 'typeorm'
    import { mocked } from 'ts-jest/utils'
    
    jest.mock('typeorm')
    
    class HighlightEntity {
      id: string
      name: string
      deleted: boolean
    }
    
    const getEntityManagerMock = async (): Promise<EntityManager> => {
      const mockedGetConnection = mocked(getConnection, true)
      // inside the test case
      mockedGetConnection.mockImplementation(
        () =>
          ({
            isConnected: true,
          } as Connection),
      )
      const manager = new EntityManager(mockedGetConnection('default'))
    
      manager.save = jest.fn().mockImplementation(() => Promise.resolve())
    
      manager.transaction = jest.fn().mockImplementation((fn) => fn(manager))
    
      return manager
    }
    
    describe('SelectQueryBuilder check before select', function () {
      it('getById method passed', async () => {
        const id = 1234
        getEntityManagerMock().then((manager) => {
          const query = manager
            .createQueryBuilder()
            .select('id', 'id')
            .addSelect('name', 'name')
            .from(HighlightEntity, 'highlight')
            .where('id = :id', {
              id,
            })
            .andWhere('deleted = false')
    
          const res = query.getRawOne()
          expect(res).toBeDefined()
        })
      })
    })

    What do I miss here?

    NotGeekAtAll
    @NotGeekAtAll
    image.png
    hi,guys,how can i select two fields in one table
    In demand table, I have two columns called created_by and assigner_id,created_by and assigner_id are userId in User table
    image.png
    NotGeekAtAll
    @NotGeekAtAll
    never mind,my mistake,sorry to bother
    TheBous
    @TheBous
    guys :( did you face foreign keys null in onetomany relations ?
    I cannot find the solution
    Screenshot 2021-11-14 at 12.54.20.png
    Screenshot 2021-11-14 at 12.54.30.png
    Screenshot 2021-11-14 at 12.54.38.png
    Screenshot 2021-11-14 at 12.55.06.png
    piyush biswal
    @piyushbiswal:matrix.org
    [m]
    Hey Guys

    Can somebody help me in the below issue ?

    await getManager().transaction(async transactionalEntityManager => {
    await transactionalEntityManager.save(hotelEntity);
    const mappings = await this.getHotelMappingsByChannel(
    hotelEntity.hotelId,
    hotelEntity.channel,
    );
    await mapHotelCallback(new Hotel(hotelEntity), mappings);
    });

    I was writing the unit tests for this functionality but I'am bit stuck in mocking the getManager method of typeorm module.

    I would appreciate if anyone can help me in this
    Thanks in advance
    Bruno Lorenço Lopes
    @bruno.lorenco.lopes_gitlab

    Hello everybody. Could someone please see this issue? I can't save entities with nullable properties:

    typeorm/typeorm#8435

    Mitch
    @mittche

    Hi! That is not possible in that form with type-orm?

    return await this.repo.find({
    relations: ['availabilities'],
    where: {
    availabilities: {
    start_date_time: startDateTime
    }
    }
    });

    Kristofer Pervin
    @kpervin
    Hey there! Does anyone know of a way to remove OneToMany promise functions when querying a table? Trying to use Mocha to do some testing with expect.to.deep.equal, but it never returns true because of what I suspect are the promise functions for joins
    kamaridesu
    @kamaridesu
    this chat seems dead
    Mitch
    @mittche
    uhu

    Hello everybody. Could someone please see this issue? I can't save entities with nullable properties:

    typeorm/typeorm#8435
    Don't know may be @Column('text', { nullable: true, default: null })
    Or shorten
    @Column('text', { default: null })
    @Column({ type: 'text', default: null })

    Mitch
    @mittche

    this chat seems dead

    they are on slack

    duyleomessi
    @duyleomessi

    Hi everybody. I create AbstractEntity

    export abstract class AbstractEntity {
      @CreateDateColumn({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)' })
      createdAt: Date;
    
      @UpdateDateColumn({
        name: 'updated_at',
        type: 'timestamp',
        default: () => 'CURRENT_TIMESTAMP(6)',
        onUpdate: 'CURRENT_TIMESTAMP(6)',
      })
      updatedAt: Date;
    }

    And entity UserEntity

    @Entity({ name: 'users' })
    export class UserEntity extends AbstractEntity<UserDto> {
      @PrimaryGeneratedColumn('increment')
      id: number;
    
      @Column({ name: 'full_name' })
      fullName?: string;
    
      @Column({ name: 'date_of_birth', nullable: true })
      dateOfBirth?: Date;
    }

    When I run migration "yarn migration:generate initialize-db", the generated SQL is

    CREATE TABLE \users` (`created_at` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `id` int NOT NULL AUTO_INCREMENT, ...

    The field in AbstractEntity is created first before id, fullName ... How can I change order of filed id, fullName, ... before the created_at updated_at ?

    I posted that question and would like an answer urgently if possible.
    Ritesh Ksheersagar
    @mfprogrammer_gitlab
    Could someone help me understand why my code dies after this
    12 Query START TRANSACTION
    this starts the txn and then it does not even throw an error
    sulfanoaf
    @sulfanoaf

    Good Day All
    anybody knows how to test this part with jest ?

    await getManager().transaction(async (transactionManager) => {
         const entity = await transactionManager.save(Entity, {});
          });

    thankyou

    andevhere
    @andevhere:matrix.org
    [m]

    Hey, just wanted to know. Is that correct way to create entity?
    ```const { Column, Entity, PrimaryGeneratedColumn } = require("typeorm");

    @Entity({ name: "guild_configurations" })
    export class GuildConfiguration {
    @PrimaryGeneratedColumn("int", { nullable: true })
    id; //: number;

    @Column("int", { nullable: true }, { unique: true, name: "guild_id" })
    guildId; //: string;

    @Column("text", { nullable: true })
    prefix = "?"; //: string = "?";

    @Column("text", { nullable: true }, { name: "welcome_channel_id" })
    welcomeChannelId; //: string;
    }

    I am not receiving any errors but mysql table is not create
    Manuel Bruña
    @tecnomanu
    Hi guys!
    how are you?
    i have a question about a transaction with relation, some body can help me?
     await this.createQueryBuilder()
          .relation('purchaseOrderItems')
          .of(existPurchaseOrder)
          .add( newPoItems );
    I have this code, i want to add this new item to this repository, but nothing happend.
    This relation have two PK, ebeln and ebelp, and have relation with ebeln column.
    May be for this situation about the PK i really have problems. I don't know, Thanks you!
    Jeffery ThaGintoki
    @JefferyHus
    Hey everyone, I would love to know if anyone was ever able to mock a typeorm repository using Jest as well as a service class that has dependency injection using typedi
    Jenya Kalinin
    @torgoveli

    Hello guys, how to save geojson object save to postgres with typeorm? I am installed dep postgis and created column 'geometry'.
    my geojson obj:

    {
      type: 'Feature',
      id: 'PersilHak.8BC60991AD183269E0530C1D140A4E08',
      geometry: { type: 'MultiPolygon', coordinates: [ [Array] ] },
      geometry_name: 'BATAS',
      properties: {
        PENGGUNAAN: 'Kosong',
      }
    }

    my function to save

    await repo.save({data: item})
    Aris Konstantoulas
    @aris1009
    Hi everyone, we rely heavily on TypeORM at RudderStack, but we ran into an issue with excessively long deployment times caused by overhead from typescript.
    After thinking through solutions, we used webpack to solve the problem, and reduced deployment times by 80%.
    I wrote a post on it that I hope you might find useful. Please check it out, and give me your feedback!
    https://www.rudderstack.com/blog/how-we-reduced-startup-time-by-80-with-webpack/
    stingers
    @stingers
    Hello, Guy
    I just start a new project with typeorm@0.3.6 and I'm farcing this error RangeError: Maximum call stack size exceeded[1] at Function.check someonee can help me?!!
    prince2k2singh
    @prince2k2singh
    Can someone please point me to an example regarding how to use typeORM with existing tables. I have some tables with lots of columns, but not sure if I need to match the column type exactly in each entity class. Some examples with existing tables will be really helpful. Thanks!!
    Apoorva Kumar
    @itsAPK
    not getting all items in collection mongo db typeorm
    @Entity()
    export class Collection {
    
        @ObjectIdColumn()
        id !: string ;
    
        @Column()
        symbol !: string 
    
        @Column()
        name !: string
    
        @Column()
        description !: string
    
        @Column()
        image !: string
    
        @Column()
        totalItems !: number
    
    
        @Column()
        createdAt!: string
    
        @Column ()
        categories!: string[];
    
        @Column()
        stats!: Stats[];
    
        @Column()
        isListed!: boolean;
    
    }
    const collection = getMongoRepository(Collection)
    await collection.findOne({ where: {  symbol : { $eq : symbol}}})
    getting results like
    Collection {
      id: 6285e19cfc929d11a2ec35fd,
      symbol: 'solpunks',
      name: 'SolPunks',
      description: 'SolPunks are one of the very first NFTs on the Solana blockchain. Each of these 10,000 SolPunks has attributes that make them unique according to a defined rarity system.',
      discord: 'https://discord.com/invite/solpunks',
      image: 'https://bafkreiaoifjzhau3clwdbtap7mekvdardfg25xl24kbexc7syvws35ifk4.ipfs.nftstorage.link/',
      twitter: 'https://twitter.com/PunksOnSolana',
      website: '',
      categories: [ 'pfps' ],
      stats: [] 
    }
    Apoorva Kumar
    @itsAPK
    Result missing totalItems and isListed
    can anyone know solution???
    Jonathan Gomes
    @jongomes
    need help
    image.png
    Jonathan Gomes
    @jongomes
    hello
    jvolonda
    @jvolonda42

    Hello guys,

    We are migrating from express/knex to nest/typeorm

    We are working with micro services all connected to the same database (yes we know it's not how it's supposed to work but for back office it's much simpler)
    Entities are on different applications so we can't add decortors like @ManyToOne() and when We use migration:generate this drop our existing foreign keys.
    Is there a way to prevent this from happening?
    If I create a pull request to add the possibility to generate migration without creating or dropping foreign keys is this something that would be merged?
    Thanks for your help