Comments (7)
For those who are looking for a way to add custom and localized content to database, I share with you my workaround:
Add a processor
to your entity:
entity: User
processor: ../processor/user.processor.ts # <-- the `processor` folder is at the same level than `src`
items:
user{1..100}:
produit: '@produit{1..5}'
groupe: '@groupe{1..4}'
bio: '{{lorem.paragraph}}'
In your processor, you can do the following (I let some of my custom methods and getters so you have an example of what you can do inside your processor):
faker
, it'll already import the one required by typeorm-fixtures
!
import { IProcessor } from 'typeorm-fixtures-cli';
import { User } from '../src/user/user.entity';
import * as faker from 'faker';
faker.locale = 'fr'; // <-- Whatever locale you want
export default class UserProcessor implements IProcessor<User> {
private randomNumberBetween(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
private get nameEmail(): object {
const nom = faker.name.lastName();
const prenom = faker.name.firstName();
const email = `${prenom.toLowerCase()}.${nom.toLowerCase()}@domain.io`;
return { nom, prenom, email };
}
private get randomAddress(): string {
return `${this.randomNumberBetween(1, 100)} rue ${faker.address.streetName}`;
}
preProcess(name: string, object: any): any {
// Add any prop you want to customize in your fixture
return {
...object,
...this.nameEmail,
civilite: this.randomNumberBetween(1, 2),
telephone: faker.phone.phoneNumber,
adresse: this.randomAddress,
codePostal: faker.address.zipCode,
ville: faker.address.city,
};
}
postProcess(name: string, object: { [key: string]: any }): void {
// Do some processing after data is persisted
}
}
P.S.: If you're looking for the original faker
repo, the one used by typeorm-fixtures
is https://github.com/practicalmeteor/meteor-faker (it's slightly the same documentation).
Hope it will help you guys! 🤘
from typeorm-fixtures.
+1 Integration tests
from typeorm-fixtures.
Would love to see some "helper methods" to create fixtures from tests. 😄
from typeorm-fixtures.
@thonythony
entity: https://github.com/RobinCK/typeorm-fixtures-sample/blob/master/entity/Category.ts
fixtures: https://github.com/RobinCK/typeorm-fixtures-sample/blob/master/fixtures/Category.yml
from typeorm-fixtures.
Hello @RobinCK, is support tree repository ready (as you checked in your list) ? I need this feature, if you have already developed, can you release it please (in 2.0.0-alpha by example) ?
from typeorm-fixtures.
Looks like at the moment we cannot use @references
when we define relation columns with @RelationId()
. Is there a plan to support this?
from typeorm-fixtures.
+1 configure faker locale
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
- [Bug] Postgres 'timestamptz' column failing at parsing long date HOT 4
- [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.