typeorm#SaveOptions TypeScript Examples

The following examples show how to use typeorm#SaveOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: module.ts    From typeorm-extension with MIT License 6 votes vote down vote up
// --------------------------------------------------------------

    public async save(
        params?: Partial<O>,
        options?: SaveOptions,
    ) : Promise<O> {
        const dataSource = await useDataSource();

        const entity = await this.make(params, true);
        const entityManager = dataSource.getRepository(this.context.entity);

        return entityManager.save(entity, options);
    }
Example #2
Source File: module.ts    From typeorm-extension with MIT License 6 votes vote down vote up
public async saveMany(
        amount: number,
        params?: Partial<O>,
        options?: SaveOptions,
    ) : Promise<O[]> {
        const items : O[] = [];
        for (let i = 0; i < amount; i++) {
            const item = await this.save(params, options);
            items.push(item);
        }

        return items;
    }
Example #3
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
save<T extends DeepPartial<E>>(
    entities: T[],
    options: SaveOptions & {
      reload: false;
    },
  ): Promise<T[]>;
Example #4
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
save<T extends DeepPartial<E>>(
    entities: T[],
    options?: SaveOptions,
  ): Promise<(T & E)[]>;
Example #5
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
save<T extends DeepPartial<E>>(
    entity: T,
    options?: SaveOptions & {
      reload: false;
    },
  ): Promise<T>;
Example #6
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
public async save<T extends DeepPartial<E>>(
    entityOrEntities: T | Array<T>,
    options?: SaveOptions & { reload: false },
  ): Promise<(T & E) | Array<T & E> | T | Array<T>> {
    if (!this.isPolymorph()) {
      return Array.isArray(entityOrEntities)
        ? super.save(entityOrEntities, options)
        : super.save(entityOrEntities, options);
    }

    const metadata = this.getPolymorphicMetadata();

    metadata.map((options: PolymorphicOptionsType) => {
      if (this.isParent(options)) {
        (Array.isArray(entityOrEntities)
          ? entityOrEntities
          : [entityOrEntities]
        ).map((entity: E | DeepPartial<E>) => {
          const parent = entity[options.propertyKey];

          if (!parent || entity[entityIdColumn(options)] !== undefined) {
            return entity;
          }

          /**
           * Add parent's id and type to child's id and type field
           */
          entity[entityIdColumn(options)] = parent[PrimaryColumn(options)];
          entity[entityTypeColumn(options)] = parent.constructor.name;
          return entity;
        });
      }
    });

    /**
     * Check deleteBeforeUpdate
     */
    Array.isArray(entityOrEntities)
      ? await Promise.all(
          (entityOrEntities as Array<T>).map((entity) =>
            this.deletePolymorphs(entity, metadata),
          ),
        )
      : await this.deletePolymorphs(entityOrEntities as T, metadata);

    return Array.isArray(entityOrEntities)
      ? super.save(entityOrEntities, options)
      : super.save(entityOrEntities, options);
  }