Comments (4)
Hi,
I have the same problem, I would love to see just ISO date returned by date.past
and date.future
, as faker-js returns exactly that, forcing us to use Date().toISOString defeats all purposes of using faker here...
(thanks @lordrip for the workaround)
from typeorm-fixtures.
I've forgot to mention, if I can help somehow investigating this further, just let me know :)
from typeorm-fixtures.
As a workaround, I'm using ejs forcing an ISO string
entity: MyEntity
items:
sync{1..3}:
topic: 'a-given-topic'
id: '{{datatype.uuid}}'
company: '@company*'
syncDateTime: <%= (new Date()).toISOString() %>
from typeorm-fixtures.
Another way to approach this in the meantime could be leveraging Processors
.
import { IProcessor } from 'typeorm-fixtures-cli';
// Importing 'YourEntityEntity' it's optional, it's mostly for typing purposes
import { YourEntity } from './yourentity';
import { faker } from '@faker-js/faker';
export default class EntityProcessor implements IProcessor<YourEntity> {
async preProcess(name: string, entity: YourEntity): Promise<YourEntity> {
// Here we can leverage any fakerjs module
// We could also leverage location.zipCode but for the sake of the example, we send some parameters as well
const zipCode = faker.string.numeric({ length: 5, allowLeadingZeros: true });
return { ...entity, zipCode };
}
}
then in the fixture yaml
file
entity: YourEntity
processor: ./EntityProcessor # Load the above processor
items:
provider{1..10}:
id: '{{string.uuid}}'
# zipCode is no longer required here as we're providing it through the processor
name: '{{company.name}}'
address: '{{location.streetAddress}}'
phone: '{{phone.number}}'
email: '{{internet.email}}'
representativeName: '{{person.fullName}}'
representativePhone: '{{phone.number}}'
representativeEmail: '{{internet.email}}'
from typeorm-fixtures.
Related Issues (20)
- Selectively apply Load Processor values to fixture items
- [Feature request] "Scenario": load fixtures from a single file and that can extend each other HOT 1
- [Bug] Lodash dependency pin
- [Feature request] Add support for typeorm ^0.3.0 HOT 18
- [Bug] Update dependencies HOT 2
- [Bug] $current not working on array fields
- [Bug] class-validator entities may be incorrectly "unserialized/initialized" HOT 1
- [Bug] HOT 2
- [Bug] fix faker deprecation warning
- [Bug] Null ID when referencing another fixture HOT 1
- [Bug] glob is broken in Windows and cannot iterate by folder HOT 2
- [Feature request] Add support for regular expressions/glob patterns when setting fixtures location HOT 1
- [Bug]
- [Feature request] Add TsLoader for fixture
- Problem with @Exclude HOT 2
- [Feature request] Add faker examples with parameters in README
- [Feature request] Reference one field to generate another
- [Feature request] access to entity name in processor HOT 2
- [Feature request] Replace class-transformer usage with TypeORM Repository#merge
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-fixtures.