typeorm

Docker Compose cannot connect to database

烂漫一生 提交于 2021-02-08 18:28:59
问题 I'm using nestjs for my backend and using typeorm as ORM. I tried to define my database and my application in an docker-compose file. If I'm running my database as a container and my application from my local machine it works well. My program connects and creates the tables etc. But if I try to connect the database from within my container or to start the container with docker-compose up it fails. Always get an ECONNREFUSED Error. Where is my mistake ? docker-compose.yml version: '3.1'

Docker Compose cannot connect to database

China☆狼群 提交于 2021-02-08 18:28:43
问题 I'm using nestjs for my backend and using typeorm as ORM. I tried to define my database and my application in an docker-compose file. If I'm running my database as a container and my application from my local machine it works well. My program connects and creates the tables etc. But if I try to connect the database from within my container or to start the container with docker-compose up it fails. Always get an ECONNREFUSED Error. Where is my mistake ? docker-compose.yml version: '3.1'

How to return a 404 HTTP status code when promise resolve to undefined in Nest?

折月煮酒 提交于 2021-02-08 15:13:45
问题 In order to avoid boilerplate code (checking for undefined in every controller, over and over again), how can I automatically return a 404 error when the promise in getOne returns undefined? @Controller('/customers') export class CustomerController { constructor ( @InjectRepository(Customer) private readonly repository: Repository<Customer> ) { } @Get('/:id') async getOne(@Param('id') id): Promise<Customer|undefined> { return this.repository.findOne(id) .then(result => { if (typeof result ===

How to return a 404 HTTP status code when promise resolve to undefined in Nest?

纵饮孤独 提交于 2021-02-08 15:12:21
问题 In order to avoid boilerplate code (checking for undefined in every controller, over and over again), how can I automatically return a 404 error when the promise in getOne returns undefined? @Controller('/customers') export class CustomerController { constructor ( @InjectRepository(Customer) private readonly repository: Repository<Customer> ) { } @Get('/:id') async getOne(@Param('id') id): Promise<Customer|undefined> { return this.repository.findOne(id) .then(result => { if (typeof result ===

When performing query I get object instead of field, in related table in typeorm

我怕爱的太早我们不能终老 提交于 2021-02-08 08:54:52
问题 These are my tables: @Entity('localidades') export class Localidades { @PrimaryGeneratedColumn() id: number; @Column({type:"varchar",length:100}) nombre: string; @ManyToOne(type => Provincias) @JoinColumn({name: "idprovincia"}) provincia: string; } @Entity('provincias') export class Provincias { @PrimaryGeneratedColumn() id: number; @Column({type:"varchar",length:100}) nombre: string; } This is my query: return await this.repository.createQueryBuilder("localidades") .select('localidades')

TypeORM cascade option: cascade, onDelete, onUpdate

删除回忆录丶 提交于 2021-02-06 10:12:40
问题 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 following options { cascade: "update" } = { onUpdate: 'CASCADE' } { cascade: "remove" } = { onDelete: 'CASCADE' } have the same effect? Or the cascade option is only for the TypeORM use while onUpdate and onDelete are only for the DB schema (created by migration)? 回答1: This is my conclusion of looking

TypeORM cascade option: cascade, onDelete, onUpdate

我只是一个虾纸丫 提交于 2021-02-06 10:09:46
问题 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 following options { cascade: "update" } = { onUpdate: 'CASCADE' } { cascade: "remove" } = { onDelete: 'CASCADE' } have the same effect? Or the cascade option is only for the TypeORM use while onUpdate and onDelete are only for the DB schema (created by migration)? 回答1: This is my conclusion of looking

How to pessimistic locking

☆樱花仙子☆ 提交于 2021-01-29 18:00:43
问题 I want to lock my table, but it didn't work. How can I handle it? Appreciate any advice! Typescript Typeorm Postgres //src public async checkDBTable(builderAddress: string): Promise<boolean> { // 1. find DB table by key(builderAddress) // 2. return true({key: value} exist) or false const info: InfoEntity|undefined = await this.findOne(builderAddress, { lock: {mode: 'pessimistic_write'} }); return nonceInfo !== undefined; } //result error: PessimisticLockTransactionRequiredError: An open

Cannot determine GraphQL input type for argument named

怎甘沉沦 提交于 2021-01-29 07:06:59
问题 I have two relationed models: 1.- RoleEntity import { Column, Entity, BaseEntity, OneToMany, PrimaryColumn } from "typeorm"; import { Field, ObjectType } from "type-graphql"; import { UserEntity } from "./user.entity"; @ObjectType() @Entity({ name: "tb_roles" }) export class RoleEntity extends BaseEntity { @Field() @PrimaryColumn({ name: "id", type: "character varying", length: 5 }) id!: string; @Field() @Column({ name: "description", type: "character varying", nullable: true }) description!:

Typeorm .loadRelationCountAndMap returns zeros

孤人 提交于 2021-01-29 04:15:42
问题 please help. I am trying to execute the following typeorm query: return await getRepository(Company) .createQueryBuilder("Company") .leftJoinAndSelect("Company.plants", "Plant") .leftJoinAndSelect("Plant.documents", "Document") .leftJoinAndSelect("Plant.notes", "Note") .loadRelationCountAndMap("Plant.documentsCount", "Plant.documents") .loadRelationCountAndMap("Plant.notesCount", "Plant.notes") .getMany(); The idea was to select counts of documents and notes per each plant along with all