Skip to content

Commit 2783110

Browse files
committed
πŸ› fix: ν”Όλ“œν¬λ‘€λŸ¬ 쿼리 μ—λŸ¬ μ „νŒŒμš© μ‹€ν–‰ λ©”μ„œλ“œ μΆ”κ°€
1 parent 1f1af3b commit 2783110

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

β€Žfeed-crawler/src/common/mysql-access.tsβ€Ž

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export class MySQLConnection implements DatabaseConnection {
2323
});
2424
}
2525

26-
async executeQuery<T>(query: string, params: any[] = []) {
26+
async executeQuery<T>(
27+
query: string,
28+
params: any[] = [],
29+
): Promise<T[] | null> {
2730
let connection: PoolConnection;
2831
try {
2932
connection = await this.pool.getConnection();
@@ -33,7 +36,7 @@ export class MySQLConnection implements DatabaseConnection {
3336
logger.error(
3437
`${this.nameTag} 쿼리 ${query} μ‹€ν–‰ 쀑 였λ₯˜ λ°œμƒ
3538
였λ₯˜ λ©”μ‹œμ§€: ${error.message}
36-
μŠ€νƒ 트레이슀: ${error.stack}`
39+
μŠ€νƒ 트레이슀: ${error.stack}`,
3740
);
3841
} finally {
3942
if (connection) {
@@ -43,13 +46,42 @@ export class MySQLConnection implements DatabaseConnection {
4346
logger.error(
4447
`${this.nameTag} connection release 쀑 였λ₯˜ λ°œμƒ
4548
였λ₯˜ λ©”μ‹œμ§€: ${error.message}
46-
μŠ€νƒ 트레이슀: ${error.stack}`
49+
μŠ€νƒ 트레이슀: ${error.stack}`,
4750
);
4851
}
4952
}
5053
}
5154
}
5255

56+
async executeQueryStrict<T>(query: string, params: any[] = []): Promise<T[]> {
57+
let connection: PoolConnection;
58+
try {
59+
connection = await this.pool.getConnection();
60+
const [rows] = await connection.query(query, params);
61+
return rows as T[];
62+
} catch (error) {
63+
logger.error(
64+
`${this.nameTag} 쿼리 ${query} μ‹€ν–‰ 쀑 였λ₯˜ λ°œμƒ
65+
였λ₯˜ λ©”μ‹œμ§€: ${error.message}
66+
μŠ€νƒ 트레이슀: ${error.stack}`,
67+
);
68+
throw error;
69+
} finally {
70+
if (connection) {
71+
try {
72+
if (connection) connection.release();
73+
} catch (error) {
74+
logger.error(
75+
`${this.nameTag} connection release 쀑 였λ₯˜ λ°œμƒ
76+
였λ₯˜ λ©”μ‹œμ§€: ${error.message}
77+
μŠ€νƒ 트레이슀: ${error.stack}`,
78+
);
79+
throw error;
80+
}
81+
}
82+
}
83+
}
84+
5385
public async end() {
5486
await this.pool.end();
5587
}

β€Žfeed-crawler/src/repository/feed.repository.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class FeedRepository {
2323

2424
const insertPromises = resultData.map(async (feed, index) => {
2525
try {
26-
const result = await this.dbConnection.executeQuery(query, [
26+
const result = await this.dbConnection.executeQueryStrict(query, [
2727
feed.blogId,
2828
feed.pubDate,
2929
feed.title,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface DatabaseConnection {
2-
executeQuery<T>(query: string, params: any[]): Promise<T[]>;
2+
executeQuery<T>(query: string, params: any[]): Promise<T[] | null>;
3+
executeQueryStrict<T>(query: string, params: any[]): Promise<T[]>;
34
end(): Promise<void>;
45
}

0 commit comments

Comments
Β (0)