@anchan828/typeorm-transformers
v1.0.100
Published
[TypeORM](https://github.com/typeorm/typeorm) transformers
Downloads
880
Readme
@anchan828/typeorm-transformers
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;
}