You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The seeder can be called by the configured cli command `seed:run`. In this case it generates 10 pets with a owner (User).
110
+
111
+
And last but not least, create a seeder. The seeder can be called by the configured cli command `seed:run`. In this case it generates 10 pets with a owner (User).
112
+
113
+
> Note: `seed:run` must be configured first. Go to [CLI Configuration](#cli-configuration).
Before using this TypeORM extension please read the [TypeORM Getting Started](https://typeorm.io/#/) documentation. This explains how to setup a TypeORM project.
123
127
124
-
You can install our extension with `npm` or `yarn`.
128
+
After that install the extension with `npm` or `yarn`.
125
129
126
130
```bash
127
131
npm i typeorm-seeding
128
132
# or
129
133
yarn add typeorm-seeding
130
134
```
131
135
132
-
Optional, for `Faker`types
136
+
Optional, install the type definitions of the `Faker`library.
133
137
134
138
```bash
135
139
npm install -D @types/faker
@@ -139,7 +143,7 @@ npm install -D @types/faker
139
143
140
144
To configure the path to your seeds and factories change the TypeORM config file(ormconfig.js or ormconfig.json).
|`--seed` or `-s`| null | Option to specify a specific seeder class to run individually. |
196
+
|`--seed` or `-s`| null | Option to specify a seeder class to run individually. |
191
197
|`--connection` or `-c`| null | Name of the typeorm connection. Required if there are multiple connections. |
192
198
|`--configName` or `-n`|`ormconfig.js`| Name to the typeorm config file. |
193
199
|`--root` or `-r`|`process.cwd()`| Path to the typeorm config file. |
194
200
195
201
## ❯ Basic Seeder
196
202
197
-
The seeds files define how much and how the data are connected with each other. The files will be executed alphabetically.
203
+
A seeder class only contains one method by default `run`. Within this method, you may insert data into your database. For manually insertion use the [Query Builder](https://typeorm.io/#/select-query-builder) or use the [Entity Factory](#-using-entity-factory)
204
+
205
+
> Note. The seeder files will be executed alphabetically.
Of course, manually specifying the attributes for each entity seed is cumbersome. Instead, you can use entity factories to conveniently generate large amounts of database records.
220
230
221
-
For all entities we want to seed, we need to define a factory. To do so we give you the awesome [faker](https://github.com/marak/Faker.js/) library as a parameter into your factory. Then create your "fake" entity and return it. Those factory files should be in the `src/database/factories` folder and suffixed with `.factory` like `src/database/factories/user.factory.ts`.
231
+
For all entities we want to create, we need to define a factory. To do so we give you the awesome [faker](https://github.com/marak/Faker.js/) library as a parameter into your factory. Then create your "fake" entity and return it. Those factory files should be in the `src/database/factories` folder and suffixed with `.factory` like `src/database/factories/user.factory.ts`.
Make and makeMany executes the factory functions and return a new instance of the given enity. The instance is filled with the generated values from the factory function.
290
+
Make and makeMany executes the factory functions and return a new instance of the given enity. The instance is filled with the generated values from the factory function, but not saved in the database.
281
291
282
292
**overrideParams** - Override some of the attributes of the enity.
seed and seedMany is similar to the make and makeMany method, but at the end the created entity instance gets persisted in the database.
309
+
the create and createMany method is similar to the make and makeMany method, but at the end the created entity instance gets persisted in the database.
300
310
301
311
**overrideParams** - Override some of the attributes of the enity.
The entity factories can also be used in testing. To do so call the `useSeeding` function, which loads all the defined entity factories.
329
+
330
+
> Note: Normally Jest parallelizes test runs, which all conect to the same database. This could lead to strange sideeffects. So use the `--runInBand` flag to disable parallelizes runs.
0 commit comments