@anchan828/typeorm-transformers
TypeScript icon, indicating that this package has built-in type declarations

1.0.100 • Public • Published

@anchan828/typeorm-transformers

npm NPM

Description

Transformer collection for TypeORM

Installation

$ npm i --save typeorm @anchan828/typeorm-transformers

Transformers

BooleanTransformer

Transform value between integer and boolean.

@Entity()
class BooleanTransformerTest extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id!: number;

  @Column({
    type: "tinyint",
    width: 1,
    nullable: true,
    transformer: new BooleanTransformer(),
  })
  public bool!: boolean;
}

JsonTransformer

Transform value between object and json.

Note: The JsonTransformer stores JSON as a string, not as a JSON type.

class TestJson {
  name!: string;
}
@Entity()
class JsonTransformerTest extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id!: number;

  @Column({
    type: "varchar",
    width: 255,
    nullable: true,
    transformer: new JsonTransformer<TestJson>({ name: "test" }),
  })
  public data!: TestJson;
}

StaticFileTransformer

Transform value between data and filePath.

@Entity()
class StaticFileTransformerTest extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id!: number;

  @Column({
    transformer: new StaticFileTransformer({ dirname: tmpdir() }),
    type: "varchar",
  })
  public file!: BinaryLike;
}

License

MIT

/@anchan828/typeorm-transformers/

    Package Sidebar

    Install

    npm i @anchan828/typeorm-transformers

    Weekly Downloads

    189

    Version

    1.0.100

    License

    MIT

    Unpacked Size

    16.9 kB

    Total Files

    19

    Last publish

    Collaborators

    • anchan828