小编APu*_*APu的帖子

如何使用 TypeORM 0.3.x 在 NestJS 9 中创建自定义(单独文件)存储库

这不是重复的问题。请不要将其标记为那样。

以下不是我想要的

import { EntityRepository, Repository } from "typeorm";
import { Test } from "./test.model";
import { Injectable } from "@nestjs/common";

@EntityRepository(Test)
export class TestRepository extends Repository<Test> {}
Run Code Online (Sandbox Code Playgroud)

装饰@EntityRepository器现在已被弃用。

我也不想像这里一样创建一个假存储库: /sf/answers/5134658581/

我也不想要这个,因为我必须从中提取managerdataSource我不想要这个,因为我认为这不是最好的方法。

    export const UserRepository = dataSource.getRepository(User).extend({
        //                        ^^^^^^^^^^ from where this came from
        findByName(firstName: string, lastName: string) {
            return this.createQueryBuilder("user")
                .where("user.firstName = :firstName", { firstName })
                .andWhere("user.lastName = :lastName", { lastName })
                .getMany()
        },
    })
Run Code Online (Sandbox Code Playgroud)

上面找到: https: //orkhan.gitbook.io/typeorm/docs/custom-repository#how-to-create-custom-repository

我不认为这是在 NestJS 上下文中。

我想要什么想知道在最新版本的 NestJS …

repository-pattern typeorm nestjs

8
推荐指数
1
解决办法
4360
查看次数

如何从打字稿中的数组值创建对象键

如何在打字稿中输入以下函数,以便获得自动完成和错误预防功能。

使用打字稿 4.7.4

// reference fn
function doSomething(list) {

    const data = {};

    list.map(item => {
        data[item] = 'value type string|number|bool|null'   
    });

    return data;
}

// calling it like
const data = doSomething([
    'phone_number',
    'customer_email'
]);

// get IDE autocomplete here (for only properties inside data)
console.log(data.phone_number);
console.log(data.customer_email);

// typescript yell when try to access invalid properties
console.log(data.phone_numbersss);
Run Code Online (Sandbox Code Playgroud)

javascript types typescript

2
推荐指数
1
解决办法
4978
查看次数