From 229283bf6d0c15abb4e0dd8cf6bb2e528b8f9c9a Mon Sep 17 00:00:00 2001 From: muqiuhan Date: Sun, 30 Mar 2025 12:23:13 +0000 Subject: deploy: e3709d1d023c22e08ed7a8387acb75dda7fcfdf3 --- .../19/Repository-pattern-in-Typescript/index.html | 4 +++- search.xml | 26 ++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/2025/02/19/Repository-pattern-in-Typescript/index.html b/2025/02/19/Repository-pattern-in-Typescript/index.html index d5a0b590..9ba5366a 100644 --- a/2025/02/19/Repository-pattern-in-Typescript/index.html +++ b/2025/02/19/Repository-pattern-in-Typescript/index.html @@ -197,7 +197,9 @@

然后实现一个 MongoDataServices:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { IDataServices } from '../../../core';
import { MongoGenericRepository } from './mongo-generic-repository';
import {
Author,
AuthorDocument,
Book,
BookDocument,
Genre,
GenreDocument,
} from './model';

@Injectable()
export class MongoDataServices
implements IDataServices, OnApplicationBootstrap
{
authors: MongoGenericRepository<Author>;
books: MongoGenericRepository<Book>;
genres: MongoGenericRepository<Genre>;

constructor(
@InjectModel(Author.name)
private AuthorRepository: Model<AuthorDocument>,
@InjectModel(Book.name)
private BookRepository: Model<BookDocument>,
@InjectModel(Genre.name)
private GenreRepository: Model<GenreDocument>,
) {}

onApplicationBootstrap() {
this.authors = new MongoGenericRepository<Author>(this.AuthorRepository);
this.books = new MongoGenericRepository<Book>(this.BookRepository, [
'author',
'genre',
]);
this.genres = new MongoGenericRepository<Genre>(this.GenreRepository);
}
}
-

以上。

+
+

Sunday, March 30, 2025 7:58 PM:

+

感觉以上全错,不应该过度抽象 Repository 的,就让它分散在各个模块中,还可以参考 https://github.com/Papooch/nestjs-cls 实现不会抽象泄漏的事务性 Repository 方法。

diff --git a/search.xml b/search.xml index 023d96c0..b530c5e0 100644 --- a/search.xml +++ b/search.xml @@ -1679,7 +1679,9 @@

然后实现一个 MongoDataServices:

import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { IDataServices } from '../../../core';
import { MongoGenericRepository } from './mongo-generic-repository';
import {
Author,
AuthorDocument,
Book,
BookDocument,
Genre,
GenreDocument,
} from './model';

@Injectable()
export class MongoDataServices
implements IDataServices, OnApplicationBootstrap
{
authors: MongoGenericRepository<Author>;
books: MongoGenericRepository<Book>;
genres: MongoGenericRepository<Genre>;

constructor(
@InjectModel(Author.name)
private AuthorRepository: Model<AuthorDocument>,
@InjectModel(Book.name)
private BookRepository: Model<BookDocument>,
@InjectModel(Genre.name)
private GenreRepository: Model<GenreDocument>,
) {}

onApplicationBootstrap() {
this.authors = new MongoGenericRepository<Author>(this.AuthorRepository);
this.books = new MongoGenericRepository<Book>(this.BookRepository, [
'author',
'genre',
]);
this.genres = new MongoGenericRepository<Genre>(this.GenreRepository);
}
}
-

以上。

+
+

Sunday, March 30, 2025 7:58 PM:

+

感觉以上全错,不应该过度抽象 Repository 的,就让它分散在各个模块中,还可以参考 https://github.com/Papooch/nestjs-cls 实现不会抽象泄漏的事务性 Repository 方法。

]]> Technique @@ -2943,6 +2945,17 @@

“欢迎醒来,乐乐”

我抖了抖身上的花瓣,还未说话,就听见了爸爸兴奋的欢呼声。爷爷奶奶眼睛一亮,立刻跑了过来,春天的风似乎都柔软了,我摊了摊手,将他们卷到自己怀里。

春暖花开,一切都在,真好。

+]]> + + gallery + + + + 二零二三年八月二十七日 + /2023/08/27/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AB%E6%9C%88%E4%BA%8C%E5%8D%81%E4%B8%83%E6%97%A5/ + 我从失去家人的那一刻就坠入了一个朦胧而美丽的梦,梦境没有主人,我是被梦境所留下的,永远不愿醒来的旅人。
我足不出户,一直缩在一方小世界里面,我用了无数的理由和所有人说我的生活态度,其实勇敢的人根本不需要理由就能走出去,只有懦弱的人会用各种理由说服自己退缩

+

请以我为戒,大胆往前走,走到灯火通明。

+

何须纵酒方能舞翩迁,
赤诚相见时便是少年。

]]>
gallery @@ -2956,17 +2969,6 @@

接收到的评论不必急于改变,先存起来,让它们陪着自己,跟着时间走,路上会慢慢的和其他的事情连结起来,这样就能择其善者而从之,其不善者而改之了。

应当早日从这喧扰的世界冷静下来,让脑子里满是憧憬和情爱的灵魂得到一丝陈酿,理性点抬头看看世界上方的二氧化碳,自己晃晃头打破能回到最初的样子再重来的梦。

爱你们。

-]]> - - gallery - -
- - 二零二三年八月二十七日 - /2023/08/27/%E4%BA%8C%E9%9B%B6%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%85%AB%E6%9C%88%E4%BA%8C%E5%8D%81%E4%B8%83%E6%97%A5/ - 我从失去家人的那一刻就坠入了一个朦胧而美丽的梦,梦境没有主人,我是被梦境所留下的,永远不愿醒来的旅人。
我足不出户,一直缩在一方小世界里面,我用了无数的理由和所有人说我的生活态度,其实勇敢的人根本不需要理由就能走出去,只有懦弱的人会用各种理由说服自己退缩

-

请以我为戒,大胆往前走,走到灯火通明。

-

何须纵酒方能舞翩迁,
赤诚相见时便是少年。

]]>
gallery -- cgit v1.2.3