Skip to content

Commit cbb3c3a

Browse files
committed
refactor: enhance logging in repository methods to include rowCount
- Updated logging in `find`, `insert`, and `delete` methods to return an object containing both `rows` and `rowCount` for improved clarity. - Removed unnecessary blank lines to streamline code readability.
1 parent f947264 commit cbb3c3a

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/repository/repository.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export class Repository<T> {
2525
protected options?: RepositoryOptions
2626
) {}
2727

28-
29-
3028
async find(payload?: QueryRowsPayload<T>): Promise<T[]> {
3129
const builder = new SelectQueryBuilder<T>(this.tableName, this.executor);
3230
if (payload?.where) builder.where(payload.where);
@@ -43,10 +41,13 @@ export class Repository<T> {
4341
console.log({
4442
sql: builder.build().sql,
4543
values: builder.build().values,
46-
result: result
44+
result: {
45+
rows: result.rows,
46+
rowCount: result.rowCount
47+
}
4748
});
4849
}
49-
50+
5051
return result.rows;
5152
}
5253

@@ -77,10 +78,10 @@ export class Repository<T> {
7778
`;
7879

7980
const result = await this.executor.executeSQL(query, values);
81+
8082
return parseInt(result.rows[0].count, 10);
8183
}
8284

83-
8485
async insert(
8586
data: Partial<T>[],
8687
returning: Array<keyof T> = ["*"] as any
@@ -91,7 +92,10 @@ export class Repository<T> {
9192
console.log({
9293
sql: builder.build().sql,
9394
values: builder.build().values,
94-
result: result.rows
95+
result: {
96+
rows: result.rows,
97+
rowCount: result.rowCount
98+
}
9599
});
96100
}
97101
return result;
@@ -111,16 +115,18 @@ export class Repository<T> {
111115
.returning(returning)
112116
.commit();
113117

114-
115118
if (this.options?.logging) {
116119
console.log({
117120
sql: builder.build().sql,
118121
values: builder.build().values,
119-
result: result
122+
result: {
123+
rows: result.rows,
124+
rowCount: result.rowCount
125+
}
120126
});
121127
}
122128

123-
return result
129+
return result;
124130
}
125131

126132
async delete(arg: {
@@ -136,9 +142,12 @@ export class Repository<T> {
136142
console.log({
137143
sql: builder.build().sql,
138144
values: builder.build().values,
139-
result: result.rows
145+
result: {
146+
rows: result.rows,
147+
rowCount: result.rowCount
148+
}
140149
});
141150
}
142-
return result
151+
return result;
143152
}
144153
}

0 commit comments

Comments
 (0)