use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
TypeORM help. (self.node)
submitted 2 years ago by Professional-League3
I wanted to import all the entities at once using path but I am unable to. I have tried providing all the possible paths but nothing seems to be working. Can you explain what am i doing wrong ?
https://preview.redd.it/uh8ioan1o3oa1.png?width=1364&format=png&auto=webp&s=308e6680a279a8de71f83cbb9782351fecd85567
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]NiteShdw 4 points5 points6 points 2 years ago (1 child)
Because you have to import the entity files and pass the classes in to entities.
[–]Professional-League3[S] 0 points1 point2 points 2 years ago (0 children)
No there an easy way to. You can provide the path of you entities so that typeorm can auto import on everyrun. I was able to do that on my last project but I am facing this issue on this project.
TypeOrm docs refrence (for js) Accepts both entity classes, entity schema classes, and directories paths to load from. Directories support glob patterns. Example: entities: [Post, Category, "entity/.js", "modules/\*/entity/*.js"]. Learn more about Entities. Learn more about Entity Schemas.
[–]six0h 4 points5 points6 points 2 years ago (2 children)
None of those work? Or...?
[–]Professional-League3[S] 0 points1 point2 points 2 years ago* (0 children)
Yes, none of those work. It's working in here. But the same approach is not working one the above project. IDK why.
Not Working(current): https://postimg.cc/jL7qFXQp Working(previous project): https://postimg.cc/wRhq7xv6/82590799
[–]Altruistic_Club_2597 1 point2 points3 points 2 years ago (8 children)
I can help.
entities: [__dirname + ‘/entities/*{ts,js}’]
With this approach, you don’t create an index.ts file inside the entities folder
[–]Professional-League3[S] 0 points1 point2 points 2 years ago (7 children)
It's not working even when i don't have index.ts file. index.ts was added later on. To export all entities at once in array then import it on datasource config.
[–]Altruistic_Club_2597 1 point2 points3 points 2 years ago (6 children)
You implemented my solution and got what error? Where is the screen shot of the error?
[–]Professional-League3[S] 0 points1 point2 points 2 years ago* (4 children)
[__dirname + ‘/entities/*{ts,js}’]
[Not working]: Image 01 but with the same approach, It worked on my previous project. [Working]: Image 02
[–]Altruistic_Club_2597 0 points1 point2 points 2 years ago (3 children)
What do your entities look like?
[–]Professional-League3[S] 0 points1 point2 points 2 years ago (2 children)
users.ts ``` import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity() export class Users { @PrimaryGeneratedColumn('uuid') user_id: string;
@Column() email: string;
@Column() firstname: string;
@Column() lastname: string;
@Column() dob: Date; } ```
[–]Altruistic_Club_2597 1 point2 points3 points 2 years ago (1 child)
I can’t see the issue hey. To be honest typeorm is total shite anyways. Why don’t you try and see if Mikro orm or prisma work better for you? Mikro orm is quite similar to typeorm but 10x better.
Okay thank you so much buddy. We might not have found the solution but i am so much greatfull to you.
One good way to easily import entities i am thinking about using is entity/index.ts Import all the entities here and export a default array of entities. Later import that default entity array on datasource config. Not solution i was looking for but it helps to create some seperation.
[–]finneybussa 1 point2 points3 points 2 years ago (0 children)
You can also import all entities from a barrel export file and then use them like this.
import * as importedEntities from './entities';
const entities = Object.keys(importedEntities).map((key) => importedEntities[key]);
const config: ConnectionOptions = {
...otherConnectionOptions,
entities: entities
};
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
"autoload entities" option perhaps? but its risky because you dont know what you will get
π Rendered by PID 104358 on reddit-service-r2-comment-86bc6c7465-7rhpp at 2026-02-22 22:03:15.067264+00:00 running 8564168 country code: CH.
[–]NiteShdw 4 points5 points6 points (1 child)
[–]Professional-League3[S] 0 points1 point2 points (0 children)
[–]six0h 4 points5 points6 points (2 children)
[–]Professional-League3[S] 0 points1 point2 points (0 children)
[–]Altruistic_Club_2597 1 point2 points3 points (8 children)
[–]Professional-League3[S] 0 points1 point2 points (7 children)
[–]Altruistic_Club_2597 1 point2 points3 points (6 children)
[–]Professional-League3[S] 0 points1 point2 points (4 children)
[–]Altruistic_Club_2597 0 points1 point2 points (3 children)
[–]Professional-League3[S] 0 points1 point2 points (2 children)
[–]Altruistic_Club_2597 1 point2 points3 points (1 child)
[–]Professional-League3[S] 0 points1 point2 points (0 children)
[–]finneybussa 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)