Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

679
Visualizações
What the difference between save and insert when wanting to create new record in TypeORM

What is the difference between .save() and .insert() in the Repository when wanting to create a new record?

In the code, the comment for .insert() is:

// From https://github.com/typeorm/typeorm/blob/b6c828cc6c9786c155165d97e1f21af7cf423075/src/repository/Repository.ts#L224-L232


    /**
     * Inserts a given entity into the database.
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
     * Executes fast and efficient INSERT query.
     * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
     */
    insert(entity: QueryDeepPartialEntity<Entity>|(QueryDeepPartialEntity<Entity>[])): Promise<InsertResult> {
        return this.manager.insert(this.metadata.target as any, entity);
    }

In the code, the comment for .save() is:

// From https://github.com/typeorm/typeorm/blob/b6c828cc6c9786c155165d97e1f21af7cf423075/src/repository/Repository.ts#L140-L151

    /**
     * Saves a given entity in the database.
     * If entity does not exist in the database then inserts, otherwise updates.
     */
    save<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;

    /**
     * Saves one or many given entities.
     */
    save<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {
        return this.manager.save<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);
    }

I don't understand what does:

Unlike save method executes a primitive operation without cascades, relations and other operations included.

From .insert() comment

means

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda