Skip to content

Commit b4ebb4b

Browse files
committed
feat: add column selection support to Repository find and paginate methods
- Add columns parameter support to Repository.find() method - Update SelectQueryBuilder integration to handle column selection - Add test case demonstrating operationName and columns usage
1 parent 8a7e4de commit b4ebb4b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

__tests__/repository/find.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ describe("Repository findRows", () => {
2727

2828
beforeAll(async () => {
2929
await setupTestTables();
30-
repository = new Repository("users", executor);
30+
repository = new Repository("users", executor, {
31+
logging: true
32+
});
3133
});
3234

3335
afterAll(async () => {

src/repository/repository.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class Repository<T> {
6666
if (options.orderBy) builder.orderBy(options.orderBy);
6767
if (options.limit) builder.limit(options.limit);
6868
if (options.offset) builder.offset(options.offset);
69+
if (options.columns) builder.select(options.columns);
6970
return builder.paginate(options);
7071
}
7172

@@ -86,10 +87,16 @@ export class Repository<T> {
8687

8788
async insert(
8889
data: Partial<T>[],
89-
returning: Array<keyof T> = ["*"] as any
90+
returning?: Array<keyof T>
9091
): Promise<QueryResult<T>> {
9192
const builder = new InsertQueryBuilder<T>(this.tableName, this.executor);
92-
const result = await builder.values(data).returning(returning).commit();
93+
const cursor = builder.values(data);
94+
95+
if (returning) {
96+
cursor.returning(returning);
97+
}
98+
const result = await cursor.commit();
99+
93100
if (this.options?.logging) {
94101
console.log({
95102
sql: builder.build().sql,

0 commit comments

Comments
 (0)