Where communities thrive

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

    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'
    class HighlightEntity {
      id: string
      name: string
      deleted: boolean
    const getEntityManagerMock = async (): Promise<EntityManager> => {
      const mockedGetConnection = mocked(getConnection, true)
      // inside the test case
        () =>
            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
            .select('id', 'id')
            .addSelect('name', 'name')
            .from(HighlightEntity, 'highlight')
            .where('id = :id', {
            .andWhere('deleted = false')
          const res = query.getRawOne()

    What do I miss here?

    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
    never mind,my mistake,sorry to bother
    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
    Hey Guys

    Can somebody help me in the below issue ?

    await getManager().transaction(async transactionalEntityManager => {
    await transactionalEntityManager.save(hotelEntity);
    const mappings = await this.getHotelMappingsByChannel(
    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

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



    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
    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
    this chat seems dead

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

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


    this chat seems dead

    they are on slack


    Hi everybody. I create AbstractEntity

    export abstract class AbstractEntity {
      @CreateDateColumn({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)' })
      createdAt: Date;
        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> {
      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


    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
    Could someone help me understand why my code dies after this
    this starts the txn and then it does not even throw an error

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

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



    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
    Hi guys!
    how are you?
    i have a question about a transaction with relation, some body can help me?
     await this.createQueryBuilder()
          .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
    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

    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
    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!
    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?!!
    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
    not getting all items in collection mongo db typeorm
    export class Collection {
        id !: string ;
        symbol !: string 
        name !: string
        description !: string
        image !: string
        totalItems !: number
        createdAt!: string
        @Column ()
        categories!: string[];
        stats!: Stats[];
        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
    Result missing totalItems and isListed
    can anyone know solution???
    Jonathan Gomes
    need help
    Jonathan Gomes

    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