Код: Выделить всё
async create(createProductDto:CreateProductDto):Promise
{
const product=this.productRepository.create(createProductDto)
return this.productRepository.save(product)
}
< /code>
это я моя сущность: < /p>
import { Category } from "src/category/entities/category.entity";
import { CheckProduct } from "src/check/entities/check-product.entity";
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Product{
@PrimaryGeneratedColumn()
id:number
@Column({length:100})
name:string
@Column({length:200, nullable:true})
description:string
@Column()
price:number
@Column({default:true})
status:boolean
@ManyToOne(()=>Category, category=>category.products, {onDelete:'CASCADE'})
@JoinColumn({name:'categoryId'})
category:Category
@Column()
categoryId:number
@OneToMany(()=>CheckProduct, checkProduct=>checkProduct.product)
checks:CheckProduct[]
}
< /code>
Все переменные автоинскручения. Состояние < /p>
Это мое приложение.module.ts: < /p>
TypeOrmModule.forRootAsync({
imports:[ConfigModule],
inject:[ConfigService],
useFactory:(configService:ConfigService)=>({
type:'mysql',
url:configService.get('DB_CONNECTION_STRING'),
ssl:{
ca:fs.readFileSync(configService.get('NODE_EXTRA_CA_CERTS')).toString(),
rejectUnauthorized:true
},
entities:[__dirname+'/**/*.entity{.ts,.js}'],
migrations:[__dirname+'/**/*.migrations{.ts,.js}'],
synchronize:configService.get('SYNCHRONIZE'),
migrationsRun:true,
extra:{
enableKeepAlive: true, // ⚠️ Mantenimiento de conexión a nivel TCP
keepAliveInitialDelay: 10000, // ms antes de mandar keepalive
connectTimeout: 10000,// Tiempo máximo de espera para adquirir una conexión
idleTimeout: 60000
}
})
}),
Подробнее здесь: https://stackoverflow.com/questions/796 ... t-sequence