Raz*_*ton 7 javascript node.js typescript typeorm
当想要创建新记录时.save()和.insert()in之间有什么区别?Repository
代码中,注释为.insert():
// 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);
}
Run Code Online (Sandbox Code Playgroud)
代码中,注释为.save():
// 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);
}
Run Code Online (Sandbox Code Playgroud)
我不明白什么是:
与 save 方法不同,它执行原始操作,不包含级联、关系和其他操作。
来自
.insert()评论
方法