Skip to main content

Questions tagged [typeorm]

TypeORM is an object-relational mapper for TypeScript and JavaScript that supports many different databases like MySQL and PostgreSQL and platforms like Node.js and the browser.

Filter by
Sorted by
Tagged with
231 votes
24 answers
345k views

TypeError: Class extends value undefined is not a function or null

I am getting the following error when trying to create these entities. TypeError: Class extends value undefined is not a function or null I am assuming this has something to do with circular ...
prolink007's user avatar
  • 34.3k
144 votes
30 answers
151k views

TypeORM Entity in NESTJS - Cannot use import statement outside a module

Started new project with 'nest new' command. Works fine until I add entity file to it. Got following error: import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; ^^^^^^ ...
Anton's user avatar
  • 2,088
89 votes
30 answers
98k views

Entity metadata for Role#users was not found

Trying to make OneToMany and ManyToOne relationship with TypeORM but I get this error, I don't know what's wrong with my code. I have the following User entity: import { BaseEntity, Column, Entity, ...
Soufiaane's user avatar
  • 1,977
88 votes
1 answer
151k views

What’s the difference between remove and delete?

For example, I have a TypeORM entity Profile: @Entity() class Profile { @PrimaryGeneratedColumn() id: number; @Column() gender: string; @Column() photo: string; @...
Yegor's user avatar
  • 3,860
82 votes
7 answers
143k views

How to perform a like query TypeORM

Hello guys I'm trying to find all the results that have a in them. I have tried a couple of ways but the problem is nothing works. It just returns an empty array var data = await getRepository(User) ...
Gardezi's user avatar
  • 2,822
80 votes
5 answers
116k views

TypeORM "OR" operator

I could not find any notion of OR operator neither in TypeORM docs nor in the source code. does it support it at all? I'm trying to do perform a basic search with a repository. db.getRepository(...
levansuper's user avatar
78 votes
5 answers
211k views

TypeORM: update item and return it

As far as I know, it's a best practice to return an item after it has been updated. TypeORM's updateById returns void, not the updated item though. My question: Is it possible to update and return ...
sandrooco's user avatar
  • 8,578
75 votes
13 answers
167k views

TypeORM upsert - create if not exist

Does TypeORM include some functionnality to avoid this : let contraption = await thingRepository.findOne({ name : "Contraption" }); if(!contraption) // Create if not exist { let newThing = new ...
LucasBordeau's user avatar
  • 1,518
74 votes
7 answers
96k views

TypeORM array is not supported in postgres?

I have a column kid_ages which is Integer[]. When migrating, I get the following error: DataTypeNotSupportedError: Data type "Array" in "home.kid_ages" is not supported by "...
ben berizovsky's user avatar
72 votes
6 answers
121k views

How can I have IS NULL condition in TypeORM find options?

In my queries I'm using TypeORM find option. How can I have IS NULL condition in the where clause?
user4092086's user avatar
  • 1,166
70 votes
11 answers
88k views

TypeORM how to seed database

I am running my Node JS backend using typeorm ORM. Coming from Entity Framework, it was very easy to seed the db with a few lines such as Database.SetInitializer(new DbInitializer()); Where the ...
Aaron Ullal's user avatar
  • 5,145
69 votes
6 answers
129k views

How to implement pagination in NestJS with TypeORM

Is there any way to get the total count and records with a single query, instead of running it as 2 separate queries? If it's not possible, is there any way to reuse the where condition in both ...
HanJeaHwan's user avatar
  • 1,016
63 votes
6 answers
108k views

Postgres enum in TypeORM

In TypeORM, how can I create a postgres enum type Gender as in this raw query CREATE TYPE public.Gender AS ENUM ( 'male', 'female' ); ALTER TABLE public.person ALTER COLUMN gender TYPE public....
Tai Tran's user avatar
  • 633
62 votes
36 answers
146k views

No metadata for "User" was found using TypeOrm

I'm trying to get a basic setup working using TypeORM, and getting this error following the setup. Here is a REPL (just do yarn install && yarn db:dev followed by yarn db:migrate && ...
ripper234's user avatar
  • 228k
60 votes
7 answers
113k views

Typeorm how to get relations of relations

I am getting the Object ChatRoomEntity with entitymanager.findOne method. The ChatRoomEntity has the variable messages which is a OneToMany - ManyToOne Relation. I have no problems to select that but ...
xDrago's user avatar
  • 1,982
59 votes
7 answers
161k views

TypeORM: How to order by a relation field

I have a Singer entity and a related Song entity Singer entity export class Singer { @PrimaryGeneratedColumn() id: number; @Column() name: string; @OneToMany( type => Song, ...
Budget's user avatar
  • 593
59 votes
2 answers
76k views

TypeORM cascade option: cascade, onDelete, onUpdate

Do cascade options in TypeORM overlap or do they have a completely different purpose? Their description in the documentation is very scarce and partly missing, or I couldn't find it. IOW, do the ...
Serg's user avatar
  • 7,283
57 votes
4 answers
128k views

Searching data older than a Date with typeORM

I am executing a query to Postgre DB to fetch data older than a specific date. Here's my function async filesListToDelete(): Promise<any> { return await this.fileRepository.find({ where:...
infodev's user avatar
  • 5,145
55 votes
4 answers
176k views

Does TypeORM supports raw SQL queries for input and output?

I would like to know if there is a feature of TypeORM that supports raw sql queries for Insert Update Delete Select etc..
Shift 'n Tab's user avatar
  • 9,258
52 votes
16 answers
102k views

Connection "default" was not found with TypeORM

I use TypeORM with NestJS and I am not able to save properly an entity. The connection creation works, postgres is running on 5432 port. Credentials are OK too. However when I need to save a ...
ValentinV's user avatar
  • 764
49 votes
6 answers
139k views

How can I create columns with type Date and type DateTime in nestjs with typeORM?

I am new with nestjs. How can I set columns that accepts Date format and dateTime format? Not in both cases, the columns are two differents column, one accept Date and other dateTime.
kri-dev's user avatar
  • 789
48 votes
6 answers
112k views

TypeORM: auto generated UUID in PostgreSQL

I am writing a REST API and for data access I am using TypeORM. I have used this successfully but I would like to have a UUID auto-generated primary key on one of my tables. Does anyone know how to ...
Neil Stevens's user avatar
  • 3,784
47 votes
12 answers
105k views

How to exclude entity field from returned by controller JSON. NestJS + Typeorm

I want to exclude password field from returned JSON. I am using NestJS and Typeorm. The solution provided on this question doesn't work for me or in NestJS. I can post my code if needed. Any other ...
VMois's user avatar
  • 4,508
46 votes
4 answers
28k views

TypeError: rxjs_1.lastValueFrom is not a function

I am building an api using nestjs. After adding the typeorm and pg dependencies and adding the TypeOrmModule.forRoot({}) code in app.module.ts like shown below. import { Module } from '@nestjs/common';...
npkp's user avatar
  • 1,221
45 votes
4 answers
58k views

Node.js add created_at and updated_at in entity of typeorm

I have task entity like this: import {BaseEntity, Column, Entity, PrimaryGeneratedColumn} from "typeorm"; @Entity() export class Task extends BaseEntity{ @PrimaryGeneratedColumn() ...
paranoid's user avatar
  • 7,049
44 votes
5 answers
78k views

How to set a nullable database field to NULL with typeorm?

This seems like such a simple question to answer, but finding an answer for this seems impossible. I am building a password reset feature for a backend application with Express and Typescript. I am ...
Errol59's user avatar
  • 1,467
42 votes
3 answers
96k views

TypeORM Postgres WHERE ANY or IN With QueryBuilder Or Find?

I've been trying to figure out how to select every record in a Postgres db that includes a certain id in a column that has arrays of integers. I'm new at all this but I believe I want an SQL ...
Preston's user avatar
  • 3,410
40 votes
6 answers
42k views

GraphQLError: Query root type must be provided

I'm using NestJS, TypeORM and GraphQL for my backend API. I'm getting the following error: GraphQLError [Object]: Query root type must be provided. at SchemaValidationContext.reportError (/home/...
Fardeen Panjwani's user avatar
40 votes
4 answers
126k views

Select attributes on repository.find() with relations (TypeORM)

My method returns a a bill object with all of User object. I would like that I return only bill object and User with two attributes in entity. I use TypeORM /** * Returns a bills by account bill ...
promiseREact5's user avatar
40 votes
1 answer
70k views

How to query a Many-to-Many relation with TypeORM

Note has a many-to-many relationship to Subject What is the best way to query it? I would like to write the following to get all the subjects on a give note: const subjectRepo = connection....
Jonathan's user avatar
  • 16.3k
39 votes
2 answers
49k views

TypeORM: What's difference between @Unique decorator and { unique: true } in column options?

In TypeORM you have the possibility to set a unique flag in the column options, or to set column(s) to unique for the entity. When would you use which, and what's the difference there? @Unique(["...
Karl Adler's user avatar
  • 16.5k
36 votes
8 answers
100k views

How to specify ormconfig.ts for TypeORM?

I have created a sample TypeORM project using the TypeORM CLI which has ormconfig.json by default: { "type": "postgres", "host": "localhost", "...
Hussain Ali Akbar's user avatar
34 votes
10 answers
52k views

QueryFailedError: the column "price" contain null values - TypeORM - PostgreSQL

I've created a simple table: import { Column, Entity, PrimaryGeneratedColumn } from "typeorm" @Entity() export class Test { @PrimaryGeneratedColumn() public id!: number @Column(...
Avedis Maroukian's user avatar
33 votes
2 answers
19k views

typeORM: "message": "Data type \"Object\" in \"..." is not supported by \"postgres\" database."

Given the following entity definition: @Entity() export class User extends BaseEntity { @Column({ nullable: true }) name!: string | null; @Column() age!: number; } The following error ...
silicakes's user avatar
  • 6,864
33 votes
6 answers
46k views

Typeorm when trying to run migrations: Missing required argument: dataSource

I'm trying to run TypeORM migrations with ormconfig.json like this { "name": "default", "type": "postgres", "host": "ip-is-here", &...
Eddie R's user avatar
  • 514
32 votes
12 answers
86k views

TypeORM does not create tables, columns etc

I have set up a system with typeorm (https://github.com/typeorm/typeorm) and NestJs (https://github.com/nestjs/nest), but TypeORM isn't creating the tables or columns. My setup is like this: import {...
bersling's user avatar
  • 18.8k
32 votes
6 answers
14k views

TypeORM CLI: No changes in database schema were found

I'm am developing an application using NestJS and TypeORM. Whenever I try to generate migrations from my entities (by running typeorm migration:generate) I get the following message: No changes in ...
Diogo Domanski's user avatar
31 votes
2 answers
30k views

Can I map entity field names to alias column names in TypeORM?

I am in the process of migrating from Rails to NestJs with TypeORM. For historical reasons, table names and column names in Rails are snaked_cased - I don't want to copy this nuisance to our NestJs/...
Adrian E's user avatar
  • 2,063
30 votes
10 answers
73k views

TypeORM cannot find entities if entity directory was not set in configuration files

I'm using TypeORM with the fallowing configuration file: ormconfig.json { "type": "mysql", "host": "localhost", "port": 3306, "username": "root", "password": "my-secret-pw", "database": "mytestdb", } ...
Daniel Santos's user avatar
30 votes
7 answers
53k views

NestJS + TypeORM: Use two or more databases?

I'm trying since 2 days to solve this, perhaps I'm simply missing the point here. My goal was to write a NestJS app (with TypeORM included) which serves a RestAPI for 2 or 3 of my little projects, ...
sagerobert's user avatar
29 votes
9 answers
44k views

cannot connect an SSL secured database to typeorm

This is my first time using NestJS and I am having trouble connecting my Postgres database which is hosted on Digitalocean to NestJS. I searched online for solutions and tried adding "ssl": "true" or ...
bbousq's user avatar
  • 705
28 votes
5 answers
43k views

Is it possible to 'protect' a property and exclude it from select statements

I'd like to protect certain properties on the data-layer level. For example I'd like to protect the password hash I store in the database for a user, so that it doesn't show up in arbitrary select-...
Highmastdon's user avatar
  • 7,330
28 votes
6 answers
36k views

How to do custom repository using TypeORM (MongoDB) in NestJS?

I have a question. With @EntityRepository decorator being marked as deprecated in typeorm@^0.3.6, what is now the recommended or TypeScript-friendly way to create a custom repository for an entity in ...
unspeakable29's user avatar
28 votes
9 answers
32k views

EntityMetadataNotFound: No metadata for "Task" was found - NestJS

I am learning the NestJS course from Udemy https://www.udemy.com/course/nestjs-zero-to-hero. And I am stuck with a strange issue and I have tried many things but nothing seems to be working. Here is ...
RKD's user avatar
  • 435
28 votes
4 answers
64k views

TypeORM QueryRunner Select distinct

Below is my SQL query: Select distinct ports.port_name from orders left join port_master on orders.officeId = ports.portId; How to write the above SQL using typeorm query runner to select the ...
Dharita Chokshi's user avatar
28 votes
2 answers
108k views

TypeORM: Joining when we have one to many and many to one relationship

@Entity() export class User { @PrimaryColumn() id: string; @Column({unique: true}) username: string; @Column({unique: true}) email: string; @OneToMany(type => Post, post => post....
Darius Bogdan's user avatar
28 votes
16 answers
53k views

RepositoryNotFoundError: No repository for "User" was found. Looks like this entity is not registered in current "default" connection? Typeorm

I am having a fun issue trying to get TypeOrm to work in my nestjs project. I have the below code to configure my project, yes everything loads, and yes I am able to connect to my database. import { ...
theMoleKing's user avatar
27 votes
1 answer
22k views

SpyOn TypeORM repository to change the return value for unit testing NestJS

I would like to unittest corner cases for my TypeORM database calls. I have already mocked all my TypeORM repositories with valid data. But I would like to SpyOn the repository and change the return ...
David Dehghan's user avatar
27 votes
9 answers
45k views

TypeORM PostgreSQL select where JSON field equals some value

Goal: write a select query that returns all rows where state equals "florida". Entity column: @Column({ type: 'json'}) public address: Address; Sample column value: {"city": "miami", "state": ...
user2263572's user avatar
  • 5,535
26 votes
4 answers
25k views

SyntaxError: Unexpected token import TypeORM entity

So, I am working with TypeORM and am getting an odd error when I transpile my TypeScript to JavaScript. I am receiving the following error: (function (exports, require, module, __filename, __dirname) {...
tootall414's user avatar
  • 1,306

1
2 3 4 5
97