Transformer collection for TypeORM
$ npm i --save typeorm @anchan828/typeorm-transformers
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;
}
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;
}
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;
}